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

ssl: Add an SslCtxCb hook to Ssl::HandshakerFactory. #15179

Merged
merged 13 commits into from
Mar 3, 2021

Conversation

ambuc
Copy link
Contributor

@ambuc ambuc commented Feb 24, 2021

Commit Message: Add an SslCtxCb hook to Ssl::HandshakerFactory.
Additional Description: This lets a custom handshaker configure the SSL_CTX object after creation, but before it is used to create any SSL objects.

Per the BoringSSL docs, "|SSL_CTX| are reference-counted and may be shared by connections across multiple threads. Once shared, functions which change the |SSL_CTX|'s configuration may not be used." Additionally, the SSL_CTX object is complex enough and has enough methods that, rather than expose each of them via another method on some wrapper class, it is convenient to just allow mutating access via a callback during socket creation (as in tls/context_impl.cc` in this PR).

This PR also provides a reference to the HandshakerFactoryContext to this sslctx_cb callback at runtime so that a custom handshaker can further inject SSL_CTX configuration behavior.

Risk Level: Low
Testing: n/a
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

What is this PR trying to fix, exactly? This is the issue with exposing interfaces, but not having consumers for them in public. It's impossiible to review this PR without context.

Also, why are you quoting OpenSSL documentation? We don't use OpenSSL, and I cannot find such statements in BoringSSL documenation.

@ambuc
Copy link
Contributor Author

ambuc commented Feb 24, 2021

Re the second point: sorry for the link to the wrong docs. I updated the description with the BoringSSL docs' mention of the same notion, that it is invalid to modify SSL_CTX's configuration after it is shared.

Re the first point: I have a private implementation of the custom handshaker interface which needs to call SSL_CTX_* methods on the SSL_CTX object. I'm going to write a test which exercises this callsite to regression-proof it and re-request review on this PR.

@ambuc ambuc requested a review from PiotrSikora February 25, 2021 15:56
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

include/envoy/ssl/context_config.h Outdated Show resolved Hide resolved
@@ -72,6 +72,7 @@ class SslSocket : public Network::TransportSocket,
Network::TransportSocketCallbacks* transportSocketCallbacks() override { return callbacks_; }

protected:
friend class SslSocketFriend;
Copy link
Contributor

Choose a reason for hiding this comment

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

This class doesn't exist, I don't think? Delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used in handshaker_factory_test.cc as a way to peek at an SslSocket's underlying SSL*. I thought briefly about just making the rawSsl() accessor public instead of protected but decided that it would expose the internal SSL* too much.

Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern used elsewhere for this is to create a method rawSslForTest().

@ggreenway ggreenway self-assigned this Feb 26, 2021
@ambuc ambuc requested a review from PiotrSikora March 1, 2021 20:15
PiotrSikora
PiotrSikora previously approved these changes Mar 1, 2021
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

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.

Looks good overall; just a few minor things

/wait

@@ -72,6 +72,7 @@ class SslSocket : public Network::TransportSocket,
Network::TransportSocketCallbacks* transportSocketCallbacks() override { return callbacks_; }

protected:
friend class SslSocketFriend;
Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern used elsewhere for this is to create a method rawSslForTest().

@ambuc
Copy link
Contributor Author

ambuc commented Mar 2, 2021

Re #15179 (comment): I changed this PR to introduce rawSslForTest() instead of SslSocketFriend to be more aligned with the pattern used elsewhere.

@ambuc ambuc requested review from ggreenway and PiotrSikora March 2, 2021 19:26
@ambuc
Copy link
Contributor Author

ambuc commented Mar 3, 2021

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #15179 (comment) was created by @ambuc.

see: more, trace.

@htuch htuch merged commit 565e97d into envoyproxy:main Mar 3, 2021
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.

4 participants