-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fetch certificate validation context using SDS service. #4355
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
9cb2e20
cd35a2c
61bdf6c
cf3cbf3
a905c0a
d9414bd
a12b042
058d3d0
820f6a2
99b9957
91996d6
0925dd4
d7532e8
d89a836
259322a
a02fef6
4e2594c
1557732
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 |
|---|---|---|
|
|
@@ -71,31 +71,53 @@ void SecretManagerImpl::removeDynamicSecretProvider(const std::string& map_key) | |
| ASSERT(num_deleted == 1, ""); | ||
| } | ||
|
|
||
| TlsCertificateConfigProviderSharedPtr SecretManagerImpl::findOrCreateTlsCertificateProvider( | ||
| SdsApiSharedPtr SecretManagerImpl::findOrCreate( | ||
| const envoy::api::v2::core::ConfigSource& sds_config_source, const std::string& config_name, | ||
| Server::Configuration::TransportSocketFactoryContext& secret_provider_context) { | ||
| std::function<SdsApiSharedPtr(std::function<void()> unregister_secret_provider)> create_fn) { | ||
| const std::string map_key = sds_config_source.SerializeAsString() + config_name; | ||
|
|
||
| TlsCertificateConfigProviderSharedPtr secret_provider = dynamic_secret_providers_[map_key].lock(); | ||
| SdsApiSharedPtr secret_provider = dynamic_secret_providers_[map_key].lock(); | ||
| 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); | ||
| secret_provider = create_fn(unregister_secret_provider); | ||
| dynamic_secret_providers_[map_key] = secret_provider; | ||
| } | ||
|
|
||
| return secret_provider; | ||
| } | ||
|
|
||
| TlsCertificateConfigProviderSharedPtr SecretManagerImpl::findOrCreateTlsCertificateProvider( | ||
| const envoy::api::v2::core::ConfigSource& sds_config_source, const std::string& config_name, | ||
| Server::Configuration::TransportSocketFactoryContext& secret_provider_context) { | ||
| auto create_fn = [&secret_provider_context, &sds_config_source, &config_name]( | ||
| std::function<void()> unregister_secret_provider) -> SdsApiSharedPtr { | ||
| ASSERT(secret_provider_context.initManager() != nullptr); | ||
| return TlsCertificateSdsApi::create(secret_provider_context, sds_config_source, config_name, | ||
| unregister_secret_provider); | ||
| }; | ||
| SdsApiSharedPtr secret_provider = findOrCreate(sds_config_source, config_name, create_fn); | ||
|
|
||
| return std::dynamic_pointer_cast<TlsCertificateConfigProvider>(secret_provider); | ||
| } | ||
|
|
||
| CertificateValidationContextConfigProviderSharedPtr | ||
| SecretManagerImpl::findOrCreateCertificateValidationContextProvider( | ||
|
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. The code is similar for this function and the other. try to share them by create a SdsApiSharedPtr innerFindOrCreate(..., create_fn); Then, each function will provide its creation_function to create proper object,
Member
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. Done. |
||
| const envoy::api::v2::core::ConfigSource& sds_config_source, const std::string& config_name, | ||
| Server::Configuration::TransportSocketFactoryContext& secret_provider_context) { | ||
| auto create_fn = [&secret_provider_context, &sds_config_source, &config_name]( | ||
| std::function<void()> unregister_secret_provider) -> SdsApiSharedPtr { | ||
| ASSERT(secret_provider_context.initManager() != nullptr); | ||
| return CertificateValidationContextSdsApi::create(secret_provider_context, sds_config_source, | ||
| config_name, unregister_secret_provider); | ||
| }; | ||
| SdsApiSharedPtr secret_provider = findOrCreate(sds_config_source, config_name, create_fn); | ||
|
|
||
| return std::dynamic_pointer_cast<CertificateValidationContextConfigProvider>(secret_provider); | ||
|
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. Can we templatize
Member
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. We are building sidecar with SDS feature from istio:collab-gcp-identity branch, and @quanjielin is working on merging istio:collab-gcp-identity branch into istio:master. This PR blocks the merge. |
||
| } | ||
|
|
||
| } // 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.
At first I thought templates might be a nice thing here to avoid the boiler plate, but then we have another problem, namely how to marry templates and virtual inheritance. Worth thinking about if you have any way to reduce this repetition.
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.
We tried using templates at first (cd35a2c), and then we found that causes many duplicated methods. We have to add more methods into secret manager to create each type of provider, and the provider creation methods have duplicated code. We also need two maps for each type of providers in secret manager. Besides, each type of provider also overrides some methods of provider interface, and those methods have duplicated code, too. Then we decide to switch to this way and simplify the code a lot. We don't find a better way for now.