-
Notifications
You must be signed in to change notification settings - Fork 5.5k
sds: clusters and listeners read static secrets from Bootstrap.static_resources #3378
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 12 commits
9c00999
46b0f38
475f8dc
4fd2c47
7e4b1d2
a7a1203
f2449be
bef00a6
fc79004
cc6733b
d572843
0728fc2
b4daba6
92188fd
b66bc01
9c644ed
8629d28
349a5c2
c25e5fe
ce70ec3
e7539e1
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "secret_interface", | ||
| hdrs = ["secret.h"], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "secret_manager_interface", | ||
| hdrs = ["secret_manager.h"], | ||
| deps = [ | ||
| ":secret_interface", | ||
| "//source/common/json:json_loader_lib", | ||
| "@envoy_api//envoy/api/v2/auth:cert_cc", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #pragma once | ||
|
|
||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include "envoy/common/exception.h" | ||
| #include "envoy/ssl/context.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| /** | ||
| * Secret contains certificate chain and private key | ||
| */ | ||
| class Secret { | ||
| public: | ||
| virtual ~Secret() {} | ||
|
|
||
| /** | ||
| * @return a name of the SDS secret | ||
| */ | ||
| virtual const std::string& getName() PURE; | ||
|
|
||
| /** | ||
| * @return a string of certificate chain | ||
| */ | ||
| virtual const std::string& getCertificateChain() PURE; | ||
| /** | ||
| * @return a string of private key | ||
| */ | ||
| virtual const std::string& getPrivateKey() PURE; | ||
| }; | ||
|
|
||
| typedef std::shared_ptr<Secret> SecretSharedPtr; | ||
|
|
||
| typedef std::unordered_map<std::string, SecretSharedPtr> SecretSharedPtrMap; | ||
|
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. The map and vector are not used in interfaces, so move them to impl.h?
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. Moved, |
||
|
|
||
| typedef std::vector<SecretSharedPtr> SecretSharedPtrVector; | ||
|
|
||
| /** | ||
| * Throws when the requested static secret is not available | ||
| */ | ||
| class EnvoyStaticSecretException : public EnvoyException { | ||
| public: | ||
| EnvoyStaticSecretException(const std::string& message) : EnvoyException(message) {} | ||
| }; | ||
|
|
||
| /** | ||
| * Throws when the requested dynamic secret is not available | ||
| */ | ||
| class EnvoyDynamicSecretNotReadyException : public EnvoyException { | ||
| public: | ||
| EnvoyDynamicSecretNotReadyException(const std::string& message) : EnvoyException(message) {} | ||
| }; | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #pragma once | ||
|
|
||
| #include <google/protobuf/util/json_util.h> | ||
|
|
||
| #include <iomanip> | ||
| #include <sstream> | ||
| #include <string> | ||
|
|
||
| #include "envoy/secret/secret.h" | ||
|
|
||
| #include "common/json/json_loader.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| /** | ||
| * A manager for all static secrets | ||
| */ | ||
| class SecretManager { | ||
| public: | ||
| virtual ~SecretManager() {} | ||
|
|
||
| /** | ||
| * Add or update static secret | ||
| * | ||
| * @param secret Updated Secret | ||
| * @return true when successful, otherwise returns false | ||
| */ | ||
| virtual bool addOrUpdateStaticSecret(const SecretSharedPtr secret) PURE; | ||
|
|
||
| /** | ||
| * @return the static secret for the given name | ||
| */ | ||
| virtual SecretSharedPtr getStaticSecret(const std::string& name) PURE; | ||
| }; | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "secret_impl_lib", | ||
| srcs = ["secret_impl.cc"], | ||
| hdrs = ["secret_impl.h"], | ||
| deps = [ | ||
| "//include/envoy/secret:secret_interface", | ||
| "//source/common/config:datasource_lib", | ||
| "@envoy_api//envoy/api/v2/auth:cert_cc", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "secret_manager_impl_lib", | ||
| srcs = ["secret_manager_impl.cc"], | ||
| hdrs = ["secret_manager_impl.h"], | ||
| deps = [ | ||
| ":secret_impl_lib", | ||
| "//include/envoy/secret:secret_manager_interface", | ||
| "//include/envoy/server:instance_interface", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "common/secret/secret_impl.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "common/common/assert.h" | ||
| #include "common/config/datasource.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| SecretImpl::SecretImpl(const envoy::api::v2::auth::Secret& config) | ||
| : name_(config.name()), certificate_chain_(Config::DataSource::read( | ||
| config.tls_certificate().certificate_chain(), true)), | ||
| private_key_(Config::DataSource::read(config.tls_certificate().private_key(), true)) {} | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/api/v2/auth/cert.pb.h" | ||
| #include "envoy/secret/secret.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| class SecretImpl : public Secret { | ||
| public: | ||
| SecretImpl(const envoy::api::v2::auth::Secret& config); | ||
|
|
||
| const std::string& getName() override { return name_; } | ||
|
|
||
| const std::string& getCertificateChain() override { return certificate_chain_; } | ||
|
|
||
| const std::string& getPrivateKey() override { return private_key_; } | ||
|
|
||
| private: | ||
| std::string name_; | ||
| std::string certificate_chain_; | ||
| std::string private_key_; | ||
| }; | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #include "common/secret/secret_manager_impl.h" | ||
|
|
||
| #include "common/common/logger.h" | ||
| #include "common/secret/secret_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| bool SecretManagerImpl::addOrUpdateStaticSecret(const SecretSharedPtr secret) { | ||
| static_secrets_[secret->getName()] = secret; | ||
| return true; | ||
| } | ||
|
|
||
| SecretSharedPtr SecretManagerImpl::getStaticSecret(const std::string& name) { | ||
| return (static_secrets_.find(name) != static_secrets_.end()) ? static_secrets_[name] : nullptr; | ||
|
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. You're looking up twice, prefer:
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. Done |
||
| } | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <shared_mutex> | ||
|
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. unused
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. Removed. It will be added later for dynamic secret support. |
||
| #include <unordered_map> | ||
|
|
||
| #include "envoy/secret/secret.h" | ||
| #include "envoy/secret/secret_manager.h" | ||
| #include "envoy/server/instance.h" | ||
|
|
||
| #include "common/common/logger.h" | ||
| #include "common/secret/secret_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| class SecretManagerImpl : public SecretManager, Logger::Loggable<Logger::Id::upstream> { | ||
| public: | ||
| SecretManagerImpl(){}; | ||
|
|
||
| virtual ~SecretManagerImpl() {} | ||
|
|
||
| bool addOrUpdateStaticSecret(const SecretSharedPtr secret) override; | ||
| SecretSharedPtr getStaticSecret(const std::string& name) override; | ||
|
|
||
| private: | ||
| SecretSharedPtrMap static_secrets_; | ||
| }; | ||
|
|
||
| } // 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.
make these getters as const method?
Also I would prefer not having
getprefix for those properties, so justname,certificateChain...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.
Renamed
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.
still not const method. (i.e.
virtual const std::string& name() const PURE;)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.
Done