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

tls: add enable_client_cipher_preference option #35106

Merged
merged 12 commits into from
Jul 23, 2024

Conversation

arulthileeban
Copy link
Contributor

Commit Message: Add option to allow enabling client cipher preference for TLS handshakes instead of the server's (default).
Risk Level: Low
Testing: Unit/Integration/Manual
Docs Changes: Added
Release Notes: Added
Fixes #34604

Signed-off-by: Arul Thileeban Sagayam <[email protected]>
Signed-off-by: Arul Thileeban Sagayam <[email protected]>
Signed-off-by: Arul Thileeban Sagayam <[email protected]>
Copy link

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

🐱

Caused by: #35106 was opened by arulthileeban.

see: more, trace.

@@ -309,7 +309,9 @@ ContextImpl::ContextImpl(Stats::Scope& scope, const Envoy::Ssl::ContextConfig& c

// use the server's cipher list preferences
for (auto& ctx : tls_contexts_) {
SSL_CTX_set_options(ctx.ssl_ctx_.get(), SSL_OP_CIPHER_SERVER_PREFERENCE);
if (!config.enableClientCipherPreference()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this require a runtime guard?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, configuration guard is fine because it is off-by-default.

Copy link
Contributor

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

/wait

// By default, Envoy as a server uses its preferred cipher during the handshake.
// Setting this to true would allow the downstream client's preferred cipher to be used instead.
// Has no effect when using TLSv1_3.
bool enable_client_cipher_preference = 6;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe prefer_client_ciphers?

envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context;
TestUtility::loadFromYaml(TestEnvironment::substitute(yaml), tls_context);
auto cfg = *ServerContextConfigImpl::create(tls_context, factory_context_);
EXPECT_EQ(cfg.get()->enableClientCipherPreference(), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should test that the SSL_CTX has the correct flags set on it instead of just looking at the cfg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wanted to test it, but the SSL_CTX object didn't seem directly accessible or downgradable from these objects. Let me check further

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to move a helper function to util file, but this was doable. Addressed other comments as well.

@@ -275,6 +275,40 @@ TEST_P(SslIntegrationTest, RouterDownstreamDisconnectBeforeResponseComplete) {
checkStats();
}

// Test server preference of cipher suites. Default server order is ECDHE-RSA-AES128-GCM-SHA256
Copy link
Contributor

Choose a reason for hiding this comment

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

In these two tests, it will be clearer what is happening, and less likely to break in the future, if you explicitly set the server ciphers as well, instead of relying on the default.

Signed-off-by: Arul Thileeban Sagayam <[email protected]>
Signed-off-by: Arul Thileeban Sagayam <[email protected]>
@KBaichoo
Copy link
Contributor

/wait

I think this needs to be updated to resolve the merge conflict @arulthileeban

Signed-off-by: Arul Thileeban Sagayam <[email protected]>
@arulthileeban
Copy link
Contributor Author

/wait

I think this needs to be updated to resolve the merge conflict @arulthileeban

Updated it. Check seems to fail due to lack of agents?

// By default, Envoy as a server uses its preferred cipher during the handshake.
// Setting this to true would allow the downstream client's preferred cipher to be used instead.
// Has no effect when using TLSv1_3.
bool prefer_client_ciphers = 6;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this field be in DownstreamTlsContext instead of here? If I'm understanding the intent here correctly, this seems to apply to the downstream connection only, not to upstream connections. But the TlsParameters message is used in CommonTlsContext, which is used in both UpstreamTlsContext and DownstreamTlsContext.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good catch! Yes, agree this should be in the downstream context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, Thanks for pointing that out. I've moved it to downstream context now.

@ggreenway
Copy link
Contributor

Unassigning @markdroth because he's out this week.

/assign-from @envoyproxy/api-shepherds

Copy link

@envoyproxy/api-shepherds assignee is @adisuissa

🐱

Caused by: a #35106 (comment) was created by @ggreenway.

see: more, trace.

ggreenway
ggreenway previously approved these changes Jul 23, 2024
Copy link
Contributor

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

LGTM. Waiting on api-shepherds review.

Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

/lgtm api

@ggreenway
Copy link
Contributor

@arulthileeban sorry there's a merge conflict again. Should be able to merge after that's resolved.

/wait

Signed-off-by: Arul Thileeban Sagayam <[email protected]>
@arulthileeban
Copy link
Contributor Author

@arulthileeban sorry there's a merge conflict again. Should be able to merge after that's resolved.

/wait

Fixed. Thanks!

@ggreenway ggreenway enabled auto-merge (squash) July 23, 2024 19:06
@ggreenway ggreenway merged commit 226942b into envoyproxy:main Jul 23, 2024
52 checks passed
martinduke pushed a commit to martinduke/envoy that referenced this pull request Aug 8, 2024
asingh-g pushed a commit to asingh-g/envoy that referenced this pull request Aug 20, 2024
@arulthileeban arulthileeban deleted the cipher_pref branch September 14, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support BoringSSL's SSL_OP_CIPHER_SERVER_PREFERENCE option in Envoy Common TLS configuration
5 participants