-
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 9 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; | ||
|
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. make these getters as const method? Also I would prefer not having
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. Renamed
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. still not const method. (i.e.
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 |
||
|
|
||
| /** | ||
| * @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> SecretPtr; | ||
|
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. nit:
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. Replaced |
||
|
|
||
| typedef std::unordered_map<std::string, SecretPtr> SecretPtrMap; | ||
|
|
||
| typedef std::vector<SecretPtr> SecretPtrVector; | ||
|
|
||
| /** | ||
| * 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 SecretPtr secret) PURE; | ||
|
|
||
| /** | ||
| * @return the static secret for the given name | ||
| */ | ||
| virtual SecretPtr getStaticSecret(const std::string& name) PURE; | ||
| }; | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1678,4 +1678,19 @@ const std::string Json::Schema::SDS_SCHEMA(R"EOF( | |
| "required" : ["hosts"] | ||
| } | ||
| )EOF"); | ||
|
|
||
|
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 is not going to v1 so I don't think you need this.
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 |
||
| const std::string Json::Schema::SECRET_SCHEMA(R"EOF( | ||
| { | ||
| "$schema": "http://json-schema.org/schema#", | ||
| "type": "object", | ||
| "properties": { | ||
| "name": {"type": "string"} | ||
| }, | ||
| "required": [ | ||
| "name" | ||
| ], | ||
| "additionalProperties": true | ||
| } | ||
| )EOF"); | ||
|
|
||
| } // 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/filesystem:filesystem_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,35 @@ | ||
| #include "common/secret/secret_impl.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "common/common/assert.h" | ||
| #include "common/filesystem/filesystem_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Secret { | ||
|
|
||
| SecretImpl::SecretImpl(const envoy::api::v2::auth::Secret& config) | ||
| : name_(config.name()), | ||
| certificate_chain_(readDataSource(config.tls_certificate().certificate_chain(), true)), | ||
| private_key_(readDataSource(config.tls_certificate().private_key(), true)) {} | ||
|
|
||
| const std::string SecretImpl::readDataSource(const envoy::api::v2::core::DataSource& source, | ||
|
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. Just use
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 |
||
| bool allow_empty) { | ||
| switch (source.specifier_case()) { | ||
| case envoy::api::v2::core::DataSource::kFilename: | ||
| return Filesystem::fileReadToEnd(source.filename()); | ||
| case envoy::api::v2::core::DataSource::kInlineBytes: | ||
| return source.inline_bytes(); | ||
| case envoy::api::v2::core::DataSource::kInlineString: | ||
| return source.inline_string(); | ||
| default: | ||
| if (!allow_empty) { | ||
| throw EnvoyException( | ||
| fmt::format("Unexpected DataSource::specifier_case(): {}", source.specifier_case())); | ||
| } | ||
| return ""; | ||
| } | ||
| } | ||
|
|
||
| } // namespace Secret | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #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); | ||
|
|
||
| virtual ~SecretImpl() {} | ||
|
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. no need of this line
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 |
||
|
|
||
| const std::string& getName() override { return name_; } | ||
|
|
||
| const std::string& getCertificateChain() override { return certificate_chain_; } | ||
|
|
||
| const std::string& getPrivateKey() override { return private_key_; } | ||
|
|
||
| private: | ||
| const std::string readDataSource(const envoy::api::v2::core::DataSource& source, | ||
| bool allow_empty); | ||
| const std::string getDataSourcePath(const envoy::api::v2::core::DataSource& source); | ||
|
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 |
||
|
|
||
| private: | ||
| std::string name_; | ||
| std::string certificate_chain_; | ||
| std::string private_key_; | ||
| }; | ||
|
|
||
| } // 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.
?