-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Make health check loop wait for any required SDS secrets to be loaded… #17756
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 2 commits
ffa08e1
24e4b74
d18d23e
d7ac8f1
0cc47e5
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -379,13 +379,45 @@ 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) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. This block looks redundant. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| absl::WriterMutexLock m(&secrets_ready_callbacks_mu_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const auto& cb : secrets_ready_callbacks_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cb(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| absl::WriterMutexLock m(&secrets_ready_callbacks_mu_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secrets_ready_callbacks_.push_back(callback); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. This block could be less nested if executed as an |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (immediately_run_callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| callback(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+401
to
+415
Member
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. Consider this change here and in
Suggested change
Contributor
Author
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. don't I need to hold both locks when adding to the callbacks list? otherwise another thread could set
Member
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 are the implications if the missed callback runs next time
Contributor
Author
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 think the next
Member
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. Alright, SGTM. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ServerSslSocketFactory::ServerSslSocketFactory(Envoy::Ssl::ServerContextConfigPtr config, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Envoy::Ssl::ContextManager& manager, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Stats::Scope& stats_scope, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -425,13 +457,46 @@ 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) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. redundant nested block |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| absl::WriterMutexLock l(&secrets_ready_callbacks_mu_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| absl::WriterMutexLock m(&secrets_ready_callbacks_mu_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secrets_ready_callbacks_.push_back(callback); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (immediately_run_callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| callback(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace Tls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace TransportSockets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace Extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.