-
Notifications
You must be signed in to change notification settings - Fork 5.3k
health_checker: Make health check loop wait for any required SDS secrets to be loaded before starting. #16236
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
Changes from all commits
e98cbec
e43c9f8
6e61b4d
72989c3
cf18615
7da3fee
c3a2f41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ class UpstreamProxyProtocolSocketFactory : public Network::TransportSocketFactor | |
| createTransportSocket(Network::TransportSocketOptionsSharedPtr options) const override; | ||
| bool implementsSecureTransport() const override; | ||
| bool usesProxyProtocolOptions() const override { return true; } | ||
| void addReadyCb(std::function<void()> callback) override { callback(); }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| private: | ||
| Network::TransportSocketFactoryPtr transport_socket_factory_; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,7 @@ class ServerStartTlsSocketFactory : public Network::TransportSocketFactory, | |
| createTransportSocket(Network::TransportSocketOptionsSharedPtr options) const override; | ||
| bool implementsSecureTransport() const override { return false; } | ||
| bool usesProxyProtocolOptions() const override { return false; } | ||
| void addReadyCb(std::function<void()> callback) override { callback(); } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| private: | ||
| Network::TransportSocketFactoryPtr raw_socket_factory_; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -380,13 +380,38 @@ bool ClientSslSocketFactory::implementsSecureTransport() const { return true; } | |
|
|
||
| void ClientSslSocketFactory::onAddOrUpdateSecret() { | ||
| ENVOY_LOG(debug, "Secret is updated."); | ||
| bool should_run_callbacks = false; | ||
| { | ||
| absl::WriterMutexLock l(&ssl_ctx_mu_); | ||
| ssl_ctx_ = manager_.createSslClientContext(stats_scope_, *config_, ssl_ctx_); | ||
| if (ssl_ctx_) { | ||
| should_run_callbacks = true; | ||
| } | ||
| } | ||
| if (should_run_callbacks) { | ||
| for (const auto& cb : secrets_ready_callbacks_) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what threads are callbacks added to this list? Do adds happen from outside the thread where onAddOrUpdateSecret() is called? |
||
| cb(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On what thread to these callbacks run? I don't know what the threading model looks like for health checker vs SDS. I think there's potential for callbacks being invoked from the wrong thread. |
||
| } | ||
| secrets_ready_callbacks_.clear(); | ||
| } | ||
| stats_.ssl_context_update_by_sds_.inc(); | ||
| } | ||
|
|
||
| void ClientSslSocketFactory::addReadyCb(std::function<void()> callback) { | ||
| bool immediately_run_callback = false; | ||
| { | ||
| absl::ReaderMutexLock l(&ssl_ctx_mu_); | ||
| if (ssl_ctx_) { | ||
| immediately_run_callback = true; | ||
| } else { | ||
| secrets_ready_callbacks_.push_back(callback); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see no mechanism to cancel pending callbacks on ActiveHealthCheckSession deletion. Is it possible for it to take a long time for secrets to become available, and for the ActiveHealthCheckSession to be deleted before this callback is executed? |
||
| } | ||
| } | ||
| if (immediately_run_callback) { | ||
| callback(); | ||
| } | ||
| } | ||
|
|
||
| ServerSslSocketFactory::ServerSslSocketFactory(Envoy::Ssl::ServerContextConfigPtr config, | ||
| Envoy::Ssl::ContextManager& manager, | ||
| Stats::Scope& stats_scope, | ||
|
|
@@ -421,13 +446,39 @@ bool ServerSslSocketFactory::implementsSecureTransport() const { return true; } | |
|
|
||
| void ServerSslSocketFactory::onAddOrUpdateSecret() { | ||
| ENVOY_LOG(debug, "Secret is updated."); | ||
| bool should_run_callbacks = false; | ||
| { | ||
| absl::WriterMutexLock l(&ssl_ctx_mu_); | ||
| ssl_ctx_ = manager_.createSslServerContext(stats_scope_, *config_, server_names_, ssl_ctx_); | ||
|
|
||
| if (ssl_ctx_) { | ||
| should_run_callbacks = true; | ||
| } | ||
| } | ||
| if (should_run_callbacks) { | ||
| for (const auto& cb : secrets_ready_callbacks_) { | ||
| cb(); | ||
| } | ||
| secrets_ready_callbacks_.clear(); | ||
| } | ||
| stats_.ssl_context_update_by_sds_.inc(); | ||
| } | ||
|
|
||
| void ServerSslSocketFactory::addReadyCb(std::function<void()> callback) { | ||
| bool immediately_run_callback = false; | ||
| { | ||
| absl::ReaderMutexLock l(&ssl_ctx_mu_); | ||
| if (ssl_ctx_) { | ||
| immediately_run_callback = true; | ||
| } else { | ||
| secrets_ready_callbacks_.push_back(callback); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What mutex guards secrets_ready_callbacks_ ? You only have a reader lock on ssl_ctx_mu_ here, I think you need a write lock. |
||
| } | ||
| } | ||
| if (immediately_run_callback) { | ||
| callback(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace Tls | ||
| } // namespace TransportSockets | ||
| } // namespace Extensions | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,8 @@ class ClientSslSocketFactory : public Network::TransportSocketFactory, | |
| bool usesProxyProtocolOptions() const override { return false; } | ||
| bool supportsAlpn() const override { return true; } | ||
|
|
||
| void addReadyCb(std::function<void()> callback) override; | ||
|
|
||
| // Secret::SecretCallbacks | ||
| void onAddOrUpdateSecret() override; | ||
|
|
||
|
|
@@ -125,6 +127,7 @@ class ClientSslSocketFactory : public Network::TransportSocketFactory, | |
| Envoy::Ssl::ClientContextConfigPtr config_; | ||
| mutable absl::Mutex ssl_ctx_mu_; | ||
| Envoy::Ssl::ClientContextSharedPtr ssl_ctx_ ABSL_GUARDED_BY(ssl_ctx_mu_); | ||
| std::list<std::function<void()>> secrets_ready_callbacks_; | ||
| }; | ||
|
|
||
| class ServerSslSocketFactory : public Network::TransportSocketFactory, | ||
|
|
@@ -140,6 +143,8 @@ class ServerSslSocketFactory : public Network::TransportSocketFactory, | |
| bool implementsSecureTransport() const override; | ||
| bool usesProxyProtocolOptions() const override { return false; } | ||
|
|
||
| void addReadyCb(std::function<void()> callback) override; | ||
|
|
||
| // Secret::SecretCallbacks | ||
| void onAddOrUpdateSecret() override; | ||
|
|
||
|
|
@@ -151,6 +156,7 @@ class ServerSslSocketFactory : public Network::TransportSocketFactory, | |
| const std::vector<std::string> server_names_; | ||
| mutable absl::Mutex ssl_ctx_mu_; | ||
| Envoy::Ssl::ServerContextSharedPtr ssl_ctx_ ABSL_GUARDED_BY(ssl_ctx_mu_); | ||
| std::list<std::function<void()>> secrets_ready_callbacks_; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add ABSL_GUARDED_BY
|
||
| }; | ||
|
|
||
| } // namespace Tls | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC TSI socket does not use SDS to propagate credentials. I think that the current implementation is good enough.