Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

certloader: Correctly support RequestClientCert in WatchedClientConfig #26812

Merged
merged 1 commit into from Jul 18, 2023

Conversation

chancez
Copy link
Contributor

@chancez chancez commented Jul 13, 2023

Only configure GetClientCertificate if client keypair is configured, allowing servers to Request ClientCertificates without requiring them.

In docs for GetClientCertificate it specifies:

GetClientCertificate must return a non-nil Certificate. If
Certificate.Certificate is empty then no certificate will be sent to the
server.

If a nil certificate is sent when the server requests a client certificate, the client will return an error. Instead, only configure GetClientCertificate if certificates are provided and the server may choose to how to handle the lack of a client certificate.

This is needed primarily for when the server is using RequestClientCert, which requests a certificate, but does not require the client to send one.

Previously, you would see this log message produced by the clients using WatchedClientConfig.GetClientCertificate:

transport: authentication handshake failed: mTLS client certificate requested, but not configured

Now, if a server requires a client certificate it should reject the TLS connection and the client will receive the error from the server.

I also discovered the same issue in Hubble CLI here: cilium/hubble#1123, though it doesn't use this package.

certloader: Correctly support RequestClientCert in WatchedClientConfig

@chancez chancez requested review from a team as code owners July 13, 2023 21:07
@chancez chancez self-assigned this Jul 13, 2023
@chancez chancez requested review from kaworu and aditighag July 13, 2023 21:07
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jul 13, 2023
@chancez chancez added the release-note/misc This PR makes changes that have no direct user impact. label Jul 13, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jul 13, 2023
@chancez
Copy link
Contributor Author

chancez commented Jul 13, 2023

Went with release-note/misc since it seems the only user of the modified method (within cilium/cilium) is in our tests.

@rolinh rolinh added the needs-backport/1.14 This PR / issue needs backporting to the v1.14 branch label Jul 14, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.14.0 Jul 14, 2023
@rolinh
Copy link
Member

rolinh commented Jul 14, 2023

This is technically a bug, marking for backport to v1.14 and v1.13 as per our backport policy.

@rolinh rolinh added the needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch label Jul 14, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.13.5 Jul 14, 2023
Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch, LGTM but I'd like to see a simple unit test added for this change please.

Only configure GetClientCertificate if client keypair is configured,
allowing servers to Request ClientCertificates without requiring them.

In docs for `GetClientCertificate` it specifies:

>  GetClientCertificate must return a non-nil Certificate. If
>  Certificate.Certificate is empty then no certificate will be sent to the
>  server.

If a nil certificate is sent when the server requests a client
certificate, the client will return an error. Instead, only configure
GetClientCertificate if certificates are provided and the server may
choose to how to handle the lack of a client certificate.

This is needed primarily for when the server is using RequestClientCert,
which requests a certificate, but does not require the client to send
one.

Previously, you would see this log message:

```
transport: authentication handshake failed: mTLS client certificate requested, but not provided
```

Now, if a server requires a client certificate it should reject the TLS
connection and the client will receive the error from the server.

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
@chancez chancez force-pushed the pr/chancez/tls_fix_clientconfig branch from 2d16f87 to 2d4e4d9 Compare July 14, 2023 15:28
@chancez
Copy link
Contributor Author

chancez commented Jul 14, 2023

@kaworu good point. I wrote a simple unit test verifying GetClientCertificate is nil when no keypair is provided. I considered doing an httpserver test, but wasn't sure that much was needed since this behavior is well documented and should be tested in the stdlib.

Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@chancez
Copy link
Contributor Author

chancez commented Jul 17, 2023

/test

Copy link
Member

@aditighag aditighag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any context for the package, so please go ahead with getting this merged based on reviews from the Hubble folks.

@kaworu kaworu merged commit 0bf7cc5 into main Jul 18, 2023
179 checks passed
@kaworu kaworu deleted the pr/chancez/tls_fix_clientconfig branch July 18, 2023 06:46
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jul 18, 2023
@gandro gandro mentioned this pull request Jul 18, 2023
9 tasks
@gandro gandro added backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. and removed needs-backport/1.14 This PR / issue needs backporting to the v1.14 branch labels Jul 18, 2023
@gandro gandro mentioned this pull request Jul 18, 2023
9 tasks
@gandro gandro removed the backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. label Jul 19, 2023
@gandro gandro added the backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. label Jul 19, 2023
@gandro gandro mentioned this pull request Jul 19, 2023
5 tasks
@gandro gandro added backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. and removed needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch labels Jul 19, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport done to v1.14 in 1.14.0 Jul 19, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.13 in 1.13.5 Jul 19, 2023
@gandro gandro added backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. and removed backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. labels Jul 19, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.13 to Backport done to v1.13 in 1.13.5 Jul 19, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.13 to Backport done to v1.13 in 1.13.5 Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
No open projects
1.13.5
Backport done to v1.13
1.14.0
Backport done to v1.14
Development

Successfully merging this pull request may close these issues.

None yet

5 participants