-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Support Envoy to fetch secrets using SDS service. #4256
Changes from 16 commits
2ada52e
98d9f26
98b7ffc
f33fe64
448dff3
41432b3
006c41c
95acda8
045dcdf
00d4d23
6f75d4b
74f0d1e
166a30f
98b29db
b182b23
508f4ab
1b8e91e
336a950
f36a870
f02ae4b
2844cb9
54a8dd1
599a459
11a358d
92a4fca
93778bf
cf3400a
a7b9d9f
0dcd867
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include "envoy/common/exception.h" | ||
|
||
#include "common/common/assert.h" | ||
#include "common/secret/sds_api.h" | ||
#include "common/secret/secret_provider_impl.h" | ||
#include "common/ssl/tls_certificate_config_impl.h" | ||
|
||
|
@@ -37,5 +38,37 @@ TlsCertificateConfigProviderSharedPtr SecretManagerImpl::createInlineTlsCertific | |
return std::make_shared<TlsCertificateConfigProviderImpl>(tls_certificate); | ||
} | ||
|
||
void SecretManagerImpl::removeDynamicSecretProvider(const std::string& map_key) { | ||
ENVOY_LOG(debug, "Unregister secret provider. hash key: {}", map_key); | ||
|
||
RELEASE_ASSERT(dynamic_secret_providers_.erase(map_key) == 1, ""); | ||
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. style: I prefer not putting actions inside ASSERT, even if it's RELEASE_ASSERT.
Also, does this need to be RELEASE_ASSERT? ASSERT is preferable in most cases. 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. Thanks for pointing this out. Moved erase() call outside of RELEASE_ASSERT. RELEASE_ASSERT was recommended here comment 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.
With it split into two lines, the rational for making it RELEASE_ASSERT instead of ASSERT is no longer true, so this should now be ASSERT |
||
} | ||
|
||
TlsCertificateConfigProviderSharedPtr SecretManagerImpl::findOrCreateDynamicSecretProvider( | ||
const envoy::api::v2::core::ConfigSource& sds_config_source, const std::string& config_name, | ||
Server::Configuration::TransportSocketFactoryContext& secret_provider_context) { | ||
const std::string map_key = std::to_string(MessageUtil::hash(sds_config_source)) + config_name; | ||
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. Why use a hash as part of the key? Doesn't this leave the (rare) possibility of a hash collision? Can we flatten sds_config_source to string representation instead of taking a hash? 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. Make sense. Thanks! rds_impl.cc also use string representation as key. Changed map_key to make it consistent with rds. |
||
|
||
auto secret_provider = dynamic_secret_providers_[map_key].lock(); | ||
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 would be easier to read with a typename instead of auto 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. Replaced with typename. Thanks. |
||
if (!secret_provider) { | ||
ASSERT(secret_provider_context.initManager() != nullptr); | ||
|
||
// SdsApi is owned by ListenerImpl and ClusterInfo which are destroyed before | ||
// SecretManagerImpl. It is safe to invoke this callback at the destructor of SdsApi. | ||
std::function<void()> unregister_secret_provider = [map_key, this]() { | ||
removeDynamicSecretProvider(map_key); | ||
}; | ||
|
||
secret_provider = std::make_shared<SdsApi>( | ||
secret_provider_context.localInfo(), secret_provider_context.dispatcher(), | ||
secret_provider_context.random(), secret_provider_context.stats(), | ||
secret_provider_context.clusterManager(), *secret_provider_context.initManager(), | ||
sds_config_source, config_name, unregister_secret_provider); | ||
dynamic_secret_providers_[map_key] = secret_provider; | ||
} | ||
|
||
return secret_provider; | ||
} | ||
|
||
} // namespace Secret | ||
} // namespace Envoy |
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.
will this work for other Secret types? name it findOrCreateTlsCertificateProvider
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.
This method name is updated to findOrCreateTlsCertificateProvider(). Will add findOrCreateCertificateValidationContextProvider() once #4264 is in. Thanks.