Skip to content

Optional tls_params in certificate to override TLS params in context#45680

Open
rudrakhp wants to merge 10 commits into
envoyproxy:mainfrom
rudrakhp:tls_config_per_cert
Open

Optional tls_params in certificate to override TLS params in context#45680
rudrakhp wants to merge 10 commits into
envoyproxy:mainfrom
rudrakhp:tls_config_per_cert

Conversation

@rudrakhp

Copy link
Copy Markdown
Member

Commit Message: optional tls params in certificate
Additional Description: Add optional tls_params in TLS certificate SDS that overrides context level TLS params for the certificate if provided.
Risk Level: Low (new API)
Testing: Unit tests
Docs Changes: N/A
Release Notes: Yes
Platform Specific Features: N/A
Related #44021

@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #45680 was opened by rudrakhp.

see: more, trace.

@rudrakhp
rudrakhp force-pushed the tls_config_per_cert branch 2 times, most recently from 61f0b97 to 8d7cf14 Compare June 18, 2026 04:10
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
@wbpcode

wbpcode commented Jun 24, 2026

Copy link
Copy Markdown
Member

I will leave this to the expert of TLS.

@ggreenway ggreenway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this works.

// SSL_set_SSL_CTX changes |ssl|'s |SSL_CTX|. |ssl| will use the
// certificate-related settings from |ctx|, and |SSL_get_SSL_CTX| will report
// |ctx|. This function may be used during the callbacks registered by
// |SSL_CTX_set_select_certificate_cb|,
// |SSL_CTX_set_tlsext_servername_callback|, and |SSL_CTX_set_cert_cb| or when
// the handshake is paused from them. It is typically used to switch
// certificates based on SNI.
//
// Note the session cache and related settings will continue to use the initial
// |SSL_CTX|. Callers should use |SSL_CTX_set_session_id_context| to partition
// the session cache between different domains.
//
// TODO(davidben): Should other settings change after this call?
OPENSSL_EXPORT SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx);

This only affects the certificate-related settings, and most of the newly-added settings wouldn't be applied.

/wait

@rudrakhp
rudrakhp force-pushed the tls_config_per_cert branch 15 times, most recently from cad1603 to 5c44f82 Compare July 6, 2026 16:34
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
@rudrakhp
rudrakhp force-pushed the tls_config_per_cert branch from 5c44f82 to 0be0fc5 Compare July 6, 2026 16:39
@rudrakhp

rudrakhp commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@ggreenway Thanks for the review! I updated the implementation to apply the selected certificate’s TLS params directly on SSL* after SSL_set_SSL_CTX() in onCertificateSelectionCompleted(), since SSL_set_SSL_CTX() only carries cert details. Please do give it a look, thanks again :)

@ggreenway

Copy link
Copy Markdown
Member

Don't force-push to the PR branch; it makes it difficult to review.

// for that certificate during the TLS handshake; unset fields continue to use the context-level
// values. This allows different cipher suites, ECDH curves, protocol versions, signature
// algorithms, or compliance policies per certificate.
// Setting this on a client certificate has no effect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there somewhere else this can be configured, so we don't have a setting that only works some of the time?

@wbpcode can you comment as the api-reviewer?

@rudrakhp rudrakhp Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Some params like the ocsp_staple are configured under TlsCertificate but is supported in downstream context (server cert) only. Per cert TLS params made sense to exist under each corresponding cert.

We could rename it to downstream_tls_params or server_tls_params to be more explicit about its usage?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know a better position for that. And if we can support this at upstream in theory, then it's fine to place it here and document it clear that this only make sense for now for downstream TLS.

And in the future, if we see similar requirement at upstream, we can implement it at upstream TLS also.

@rudrakhp

rudrakhp commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Don't force-push to the PR branch; it makes it difficult to review.

Ack. I added a new commit after your last review to make it easier to see the changes since then. I only force pushed on the new commit while iterating on a few test failures. Will avoid doing that as well if you would prefer no force pushes at all :)

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm api

My two cents to the API. :)

@rudrakhp
rudrakhp requested a review from ggreenway July 14, 2026 12:21
@paul-r-gall

Copy link
Copy Markdown
Contributor

coverage finding looks relevant.

@ggreenway ggreenway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's copy/pasted code all over this PR. Please refactor to avoid that.

The tests are currently not covering ecdh_curves or max_protocol_version, and they don't cover TLSv1.3 handshakes. Please add coverage for all the settings, using both TLSv1.2 and TLSv1.3.

/wait

Comment on lines +137 to +141
if (p.compliance_policies_size() > 1) {
creation_status = absl::InvalidArgumentError(
"Only one compliance policy may be specified per certificate tls_params");
return;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use compliancePolicyFromProto() here and line 149

@rudrakhp rudrakhp Jul 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moving compliancePolicyFromProto() to utils to avoid cyclic dependencies

Comment on lines +156 to +157
std::vector<absl::string_view> ciphers =
StringUtil::splitToken(tls_params_->cipher_suites, ":+![|]", false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You've copied a lot of code from elsewhere. Refactor so there's not duplicated config handling code, so that it can't drift over time.

Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
rudrakhp added 3 commits July 25, 2026 01:39
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Comment on lines +152 to +153
// QUIC selects certs via ProofSource::GetProof(), not cert_cb, so tls_params_ never applies
// there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have not implemented this for QUIC/HTTP3 in this PR (also documented it in API docs and changelogs). We can implement this in a follow up if required?

rudrakhp added 3 commits July 26, 2026 01:28
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants