forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 63
Sds secret update #2
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
Closed
Closed
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a9ec642
clusters and listeners read static secrets from Bootstrap.static_reso…
mangchiandjjoe 6a270c4
Added secretManager() to ClusterManagerFactory interface
mangchiandjjoe 3d330c5
Removed unnecessary changes
mangchiandjjoe 79defaf
Changed the location of secret_manager argument
mangchiandjjoe df3e59c
Add SDS api.
JimmyCYJ b32cb31
fix format.
JimmyCYJ 8d0a41f
fix test files.
JimmyCYJ 0dd3cc8
fix format.
JimmyCYJ 7927531
fix format and mock interfaces.
JimmyCYJ 2f56357
fix tests.
JimmyCYJ 051d7b3
Minor changes SecretManager.
JimmyCYJ 0554e71
Use SdsApiPtr
JimmyCYJ fa631a1
minor fix
JimmyCYJ d6f4d28
updated readConfig()
JimmyCYJ 50010a1
Update dynamic secret.
JimmyCYJ 3c2ff23
add secret_callback.h
JimmyCYJ 3ec032a
fix format.
JimmyCYJ 0548c1e
update tests.
JimmyCYJ eace316
Context config change.
JimmyCYJ 9f8966d
support unregistering callback from secret manager.
JimmyCYJ abe5938
Fix mock class and broken tests.
JimmyCYJ fd56370
Fix broken tests.
JimmyCYJ f441820
Fixed broken tests and asan errors.
JimmyCYJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "envoy/common/pure.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| /** | ||
| * Callbacks invoked by a secret manager. | ||
| */ | ||
| class SecretCallbacks { | ||
| public: | ||
| virtual ~SecretCallbacks() {} | ||
|
|
||
| virtual void onAddOrUpdateSecret() PURE; | ||
| }; | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/service/discovery/v2/ads.pb.h" | ||
| #include "envoy/service/discovery/v2/sds.pb.h" | ||
| #include "envoy/service/ratelimit/v2/rls.pb.h" | ||
|
|
||
| namespace Envoy { | ||
|
|
||
| // Hack to force linking of the service: https://github.com/google/protobuf/issues/4221. | ||
| // This file should be included ONLY if this hack is required. | ||
| const envoy::service::discovery::v2::AdsDummy _ads_dummy; | ||
| const envoy::service::discovery::v2::SdsDummy _sds_dummy; | ||
| const envoy::service::ratelimit::v2::RateLimitRequest _rls_dummy; | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #include "common/secret/sds_api.h" | ||
|
|
||
| #include <unordered_map> | ||
|
|
||
| #include "common/config/resources.h" | ||
| #include "common/config/subscription_factory.h" | ||
| #include "common/secret/secret_manager_util.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| SdsApi::SdsApi(Server::Instance& server, const envoy::api::v2::core::ConfigSource& sds_config, | ||
| std::string sds_config_hash, std::string sds_config_name) | ||
| : server_(server), sds_config_(sds_config), sds_config_source_hash_(sds_config_hash), | ||
| sds_config_name_(sds_config_name) { | ||
| server_.initManager().registerTarget(*this); | ||
| } | ||
|
|
||
| void SdsApi::initialize(std::function<void()> callback) { | ||
| initialize_callback_ = callback; | ||
| subscription_ = Envoy::Config::SubscriptionFactory::subscriptionFromConfigSource< | ||
| envoy::api::v2::auth::Secret>( | ||
| sds_config_, server_.localInfo().node(), server_.dispatcher(), server_.clusterManager(), | ||
| server_.random(), server_.stats(), /* rest_legacy_constructor */ nullptr, | ||
| "envoy.service.discovery.v2.SecretDiscoveryService.FetchSecrets", | ||
| // TODO(jaebong): replace next line with | ||
| // "envoy.service.discovery.v2.SecretDiscoveryService.StreamSecrets" to support streaming | ||
| // service | ||
| "envoy.service.discovery.v2.SecretDiscoveryService.FetchSecrets"); | ||
|
|
||
| Config::Utility::checkLocalInfo("sds", server_.localInfo()); | ||
|
|
||
| subscription_->start({sds_config_name_}, *this); | ||
| } | ||
|
|
||
| void SdsApi::onConfigUpdate(const ResourceVector& resources, const std::string&) { | ||
| for (const auto& resource : resources) { | ||
| switch (resource.type_case()) { | ||
| case envoy::api::v2::auth::Secret::kTlsCertificate: | ||
| server_.secretManager().addOrUpdateSecret(sds_config_source_hash_, resource); | ||
| break; | ||
| case envoy::api::v2::auth::Secret::kSessionTicketKeys: | ||
| NOT_IMPLEMENTED; | ||
| default: | ||
| throw EnvoyException("sds: invalid configuration"); | ||
| } | ||
| } | ||
|
|
||
| runInitializeCallbackIfAny(); | ||
| } | ||
|
|
||
| void SdsApi::onConfigUpdateFailed(const EnvoyException*) { | ||
| // We need to allow server startup to continue, even if we have a bad config. | ||
| runInitializeCallbackIfAny(); | ||
| } | ||
|
|
||
| void SdsApi::runInitializeCallbackIfAny() { | ||
| if (initialize_callback_) { | ||
| initialize_callback_(); | ||
| initialize_callback_ = nullptr; | ||
| } | ||
| } | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #pragma once | ||
|
|
||
| #include <functional> | ||
|
|
||
| #include "envoy/api/v2/auth/cert.pb.h" | ||
| #include "envoy/api/v2/core/config_source.pb.h" | ||
| #include "envoy/config/subscription.h" | ||
| #include "envoy/server/instance.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| /** | ||
| * SDS API implementation that fetches secrets from SDS server via Subscription. | ||
| */ | ||
| class SdsApi : public Init::Target, Config::SubscriptionCallbacks<envoy::api::v2::auth::Secret> { | ||
| public: | ||
| SdsApi(Server::Instance& server, const envoy::api::v2::core::ConfigSource& sds_config, | ||
| std::string sds_config_hash, std::string sds_config_name); | ||
|
|
||
| // Init::Target | ||
| void initialize(std::function<void()> callback) override; | ||
|
|
||
| // Config::SubscriptionCallbacks | ||
| void onConfigUpdate(const ResourceVector& resources, const std::string& version_info) override; | ||
| void onConfigUpdateFailed(const EnvoyException* e) override; | ||
| std::string resourceName(const ProtobufWkt::Any& resource) override { | ||
| return MessageUtil::anyConvert<envoy::api::v2::auth::Secret>(resource).name(); | ||
| } | ||
|
|
||
| private: | ||
| void runInitializeCallbackIfAny(); | ||
|
|
||
| Server::Instance& server_; | ||
| const envoy::api::v2::core::ConfigSource sds_config_; | ||
| const std::string sds_config_source_hash_; | ||
| std::unique_ptr<Config::Subscription<envoy::api::v2::auth::Secret>> subscription_; | ||
| std::function<void()> initialize_callback_; | ||
| std::string sds_config_name_; | ||
| }; | ||
|
|
||
| typedef std::unique_ptr<SdsApi> SdsApiPtr; | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just return raw pointer