-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
SNI-based cert selection in TLS transport socket #21739
Comments
Continuing discussion from #1984 and #18928: message CommonTlsContext {
......
// Only one of *tls_certificates*, *tls_certificate_sds_secret_configs*,
// and *tls_certificate_provider_instance* may be used.
repeated TlsCertificate tls_certificates = 2;
repeated SdsSecretConfig tls_certificate_sds_secret_configs = 6
[(validate.rules).repeated = {max_items: 2}];
// [#not-implemented-hide:]
CertificateProviderPluginInstance tls_certificate_provider_instance = 14;
......
} If we get certificates via one of these three provider, we need to modify existing cert selection logic to support different SNI. So I propose to modify current cert selection logic directly, not sure if we need to introduce some flag to indicate we need do cert selection based on SNI in transport socket. What do you think about it? |
I would definitely want to hear from @ggreenway here, but I think this comes up often enough that having an in-tree handshake provider that can do cert selection would I think be useful. I'm not sure if this would be implemented as a cert provider or something else. |
It doesn't seems like the cert selection logic is part of handshaker envoy/source/extensions/transport_sockets/tls/context_impl.cc Lines 710 to 718 in 2aa40dc
Even if we have a custom handshaker for selection, but I guess that custom handshaker most of parts same with the default handshaker except the selection logic. |
Yeah I don't know the right answer here without digging in myself. There will need to be either a new extension point or significant code sharing. I'm not sure the right solution, it will need to be investigated. |
If the only usecase of multiple certs is about support both RSA and ECDSA, then I think it is fine without a flag for me And the selection of RSA and ECDSA should be keep with SNI selection behavior
But I don't know how custom validator use the multiple certs, at least there is link for it https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/security/ssl#arch-overview-ssl-cert-select |
In general, I'd be fine with adding support for multiple certs and selecting the correct one based on SNI. There are a few questions we'd need to sort out:
|
sure
custom validator does not have multiple certs issue, multiple certs in this feature is indentity certs used for TLS handshake, validator is to use a trusted ca to validate peer certificate. |
If there is no SNI, we can fallback to only RSA/ECDSA selection, this will not break existing logic.
I think it should be a config-load error. It sounds weird that multiple certs have the same SNI.
envoy/source/extensions/transport_sockets/tls/context_impl.cc Lines 1072 to 1093 in 8259b33
Only a single TLS certificate is supported in client contexts. In server contexts, the first RSA certificate is used for clients that only support RSA and the first ECDSA certificate is used for clients that support ECDSA. According to the code and comment, it assumes that there is always a RSA cert existing, and fallback to RSA cert when client supports EC but no EC cert is found. We can keep this logic when matching the SNI. What's your suggestion? @ggreenway |
But if there are many certs, and no SNI (or no matching SNI), which of the many certs should be used? We'd probably need to specify which one, maybe the first in the list of configured certs.
Sounds good to me. You'll also need to account for wildcards, and make sure to use a more-specific cert before considering a wildcard.
No, it is not safe to assume there is always an RSA cert. But currently, there will be at most one RSA cert and one EC cert. You'll need to decide on and clearly document the matching criteria/algorithm, including both SNI and type. |
I'm ok with that selecting first cert as default.
After thinking about this for a while, It should be possible that multiple certs has the same SNI, e.g. EC and RSA certs, they both serves for the same SNI.
I mean current code assume there is always a RSA cert. Because the comment says "the first RSA certificate is used...", but code always fallback to the first certificate without looking up RSA keyword. // Fallback on first certificate.
const TlsContext* selected_ctx = &tls_contexts_[0]; So I just propose to keep this logic when do type matching. Based on your suggestion, criteria v1 should be: |
This isn't correct. The current code tries to find a match, and if one isn't found, it uses certificate 0. There's no guarantee that this is an RSA cert. But I agree that we can keep this same logic.
That is incorrect. The SANs should be checked first, and if there are none, then the CN should be used, according to RFC 6125. https://www.rfc-editor.org/rfc/rfc6125#section-6.4.4 |
So for SNI matching:
After the SNI matching, A few questions:
|
@ggreenway kindly ping :) |
After thinking about this for a while, we don't need to create a map, we can just add a member
@ggreenway What do you think about matching criteria? And for above questions do you have any experience about that? |
@ggreenway could you have a look at the code? Let us nail down the matching criteria I don't introduce any cert loading error, because I think the users or control plane should consider what certificates they provide. And it's hard to define which condition should raise loading error, two certs have overlapped SANs or overlapped subject common name? It's should be enough that we select a correct cert that the client wants. What's your suggestions? For cert selection criteria, please look the code, I left many comments there and updated the doc to explain the matching process. |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions. |
Not stale; PR in progress: #22036 |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions. |
Not stale, pr will be updated soon. |
Title: SNI-based cert selection in TLS transport socket
Description:
cc @ggreenway @mattklein123
The text was updated successfully, but these errors were encountered: