Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/envoy/secret/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_package",
)

envoy_package()

envoy_cc_library(
name = "secret_manager_interface",
hdrs = ["secret_manager.h"],
deps = [
"//include/envoy/ssl:tls_certificate_config_interface",
"@envoy_api//envoy/api/v2/auth:cert_cc",
],
)
34 changes: 34 additions & 0 deletions include/envoy/secret/secret_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <string>

#include "envoy/api/v2/auth/cert.pb.h"
#include "envoy/ssl/tls_certificate_config.h"

namespace Envoy {
namespace Secret {

/**
* A manager for static secrets.
*
* TODO(jaebong) Support dynamic secrets.
*/
class SecretManager {
public:
virtual ~SecretManager() {}

/**
* @param secret a protobuf message of envoy::api::v2::auth::Secret.
* @throw an EnvoyException if the secret is invalid or not supported.
*/
virtual void addOrUpdateSecret(const envoy::api::v2::auth::Secret& secret) PURE;

/**
* @param name a name of the Ssl::TlsCertificateConfig.
* @return the TlsCertificate secret. Returns nullptr if the secret is not found.
*/
virtual const Ssl::TlsCertificateConfig* findTlsCertificate(const std::string& name) const PURE;
};

} // namespace Secret
} // namespace Envoy
2 changes: 2 additions & 0 deletions include/envoy/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ envoy_cc_library(
"//include/envoy/local_info:local_info_interface",
"//include/envoy/ratelimit:ratelimit_interface",
"//include/envoy/runtime:runtime_interface",
"//include/envoy/secret:secret_manager_interface",
"//include/envoy/ssl:context_manager_interface",
"//include/envoy/thread_local:thread_local_interface",
"//include/envoy/tracing:http_tracer_interface",
Expand Down Expand Up @@ -172,6 +173,7 @@ envoy_cc_library(
hdrs = ["transport_socket_config.h"],
deps = [
"//include/envoy/network:transport_socket_interface",
"//include/envoy/secret:secret_manager_interface",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This isn't needed anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secret_manager_interface is required here again.

"//include/envoy/ssl:context_manager_interface",
"//source/common/protobuf",
],
Expand Down
6 changes: 6 additions & 0 deletions include/envoy/server/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "envoy/network/listen_socket.h"
#include "envoy/ratelimit/ratelimit.h"
#include "envoy/runtime/runtime.h"
#include "envoy/secret/secret_manager.h"
#include "envoy/server/admin.h"
#include "envoy/server/drain_manager.h"
#include "envoy/server/hot_restart.h"
Expand Down Expand Up @@ -113,6 +114,11 @@ class Instance {
*/
virtual ListenerManager& listenerManager() PURE;

/**
* @return the server's secret manager
*/
virtual Secret::SecretManager& secretManager() PURE;

/**
* @return the server's CLI options.
*/
Expand Down
8 changes: 7 additions & 1 deletion include/envoy/server/transport_socket_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>

#include "envoy/network/transport_socket.h"
#include "envoy/secret/secret_manager.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

#include "envoy/ssl/context_manager.h"

#include "common/protobuf/protobuf.h"
Expand All @@ -19,14 +20,19 @@ class TransportSocketFactoryContext {
virtual ~TransportSocketFactoryContext() {}

/**
* @return Ssl::ContextManager& the SSL context manager
* @return Ssl::ContextManager& the SSL context manager.
*/
virtual Ssl::ContextManager& sslContextManager() PURE;

/**
* @return Stats::Scope& the transport socket's stats scope.
*/
virtual Stats::Scope& statsScope() const PURE;

/**
* Return the instance of secret manager.
*/
virtual Secret::SecretManager& secretManager() PURE;
};

class TransportSocketConfigFactory {
Expand Down
5 changes: 5 additions & 0 deletions include/envoy/ssl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ envoy_cc_library(
"//include/envoy/stats:stats_interface",
],
)

envoy_cc_library(
name = "tls_certificate_config_interface",
hdrs = ["tls_certificate_config.h"],
)
29 changes: 29 additions & 0 deletions include/envoy/ssl/tls_certificate_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <memory>
#include <string>

#include "envoy/common/pure.h"

namespace Envoy {
namespace Ssl {

class TlsCertificateConfig {
public:
virtual ~TlsCertificateConfig() {}

/**
* @return a string of certificate chain
*/
virtual const std::string& certificateChain() const PURE;

/**
* @return a string of private key
*/
virtual const std::string& privateKey() const PURE;
};

typedef std::unique_ptr<TlsCertificateConfig> TlsCertificateConfigPtr;

} // namespace Ssl
} // namespace Envoy
1 change: 1 addition & 0 deletions include/envoy/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ envoy_cc_library(
"//include/envoy/http:conn_pool_interface",
"//include/envoy/local_info:local_info_interface",
"//include/envoy/runtime:runtime_interface",
"//include/envoy/secret:secret_manager_interface",
"//include/envoy/server:admin_interface",
"@envoy_api//envoy/api/v2:cds_cc",
"@envoy_api//envoy/config/bootstrap/v2:bootstrap_cc",
Expand Down
10 changes: 10 additions & 0 deletions include/envoy/upstream/cluster_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "envoy/http/conn_pool.h"
#include "envoy/local_info/local_info.h"
#include "envoy/runtime/runtime.h"
#include "envoy/secret/secret_manager.h"
#include "envoy/server/admin.h"
#include "envoy/upstream/load_balancer.h"
#include "envoy/upstream/thread_local_cluster.h"
Expand Down Expand Up @@ -57,6 +58,8 @@ class ClusterUpdateCallbacksHandle {

typedef std::unique_ptr<ClusterUpdateCallbacksHandle> ClusterUpdateCallbacksHandlePtr;

class ClusterManagerFactory;

/**
* Manages connection pools and load balancing for upstream clusters. The cluster manager is
* persistent and shared among multiple ongoing requests/connections.
Expand Down Expand Up @@ -188,6 +191,8 @@ class ClusterManager {
*/
virtual ClusterUpdateCallbacksHandlePtr
addThreadLocalClusterUpdateCallbacks(ClusterUpdateCallbacks& callbacks) PURE;

virtual ClusterManagerFactory& clusterManagerFactory() PURE;
};

typedef std::unique_ptr<ClusterManager> ClusterManagerPtr;
Expand Down Expand Up @@ -257,6 +262,11 @@ class ClusterManagerFactory {
virtual CdsApiPtr createCds(const envoy::api::v2::core::ConfigSource& cds_config,
const absl::optional<envoy::api::v2::core::ConfigSource>& eds_config,
ClusterManager& cm) PURE;

/**
* Returns the secret manager.
*/
virtual Secret::SecretManager& secretManager() PURE;
};

} // namespace Upstream
Expand Down
21 changes: 21 additions & 0 deletions source/common/secret/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_package",
)

envoy_package()

envoy_cc_library(
name = "secret_manager_impl_lib",
srcs = ["secret_manager_impl.cc"],
hdrs = ["secret_manager_impl.h"],
deps = [
"//include/envoy/secret:secret_manager_interface",
"//source/common/common:minimal_logger_lib",
"//source/common/ssl:tls_certificate_config_impl_lib",
"@envoy_api//envoy/api/v2/auth:cert_cc",
],
)
28 changes: 28 additions & 0 deletions source/common/secret/secret_manager_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "common/secret/secret_manager_impl.h"

#include "envoy/common/exception.h"

#include "common/ssl/tls_certificate_config_impl.h"

namespace Envoy {
namespace Secret {

void SecretManagerImpl::addOrUpdateSecret(const envoy::api::v2::auth::Secret& secret) {
switch (secret.type_case()) {
case envoy::api::v2::auth::Secret::TypeCase::kTlsCertificate:
tls_certificate_secrets_[secret.name()] =
std::make_unique<Ssl::TlsCertificateConfigImpl>(secret.tls_certificate());
break;
default:
throw EnvoyException("Secret type not implemented");
}
}

const Ssl::TlsCertificateConfig*
SecretManagerImpl::findTlsCertificate(const std::string& name) const {
auto secret = tls_certificate_secrets_.find(name);
return (secret != tls_certificate_secrets_.end()) ? secret->second.get() : nullptr;
}

} // namespace Secret
} // namespace Envoy
23 changes: 23 additions & 0 deletions source/common/secret/secret_manager_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <unordered_map>

#include "envoy/secret/secret_manager.h"
#include "envoy/ssl/tls_certificate_config.h"

#include "common/common/logger.h"

namespace Envoy {
namespace Secret {

class SecretManagerImpl : public SecretManager, Logger::Loggable<Logger::Id::upstream> {
public:
void addOrUpdateSecret(const envoy::api::v2::auth::Secret& secret) override;
const Ssl::TlsCertificateConfig* findTlsCertificate(const std::string& name) const override;

private:
std::unordered_map<std::string, Ssl::TlsCertificateConfigPtr> tls_certificate_secrets_;
};

} // namespace Secret
} // namespace Envoy
13 changes: 13 additions & 0 deletions source/common/ssl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ envoy_cc_library(
"ssl",
],
deps = [
"//include/envoy/secret:secret_manager_interface",
"//include/envoy/ssl:context_config_interface",
"//source/common/common:assert_lib",
"//source/common/common:empty_string",
"//source/common/config:datasource_lib",
"//source/common/config:tls_context_json_lib",
"//source/common/json:json_loader_lib",
Expand Down Expand Up @@ -66,3 +68,14 @@ envoy_cc_library(
"//source/common/common:hex_lib",
],
)

envoy_cc_library(
name = "tls_certificate_config_impl_lib",
srcs = ["tls_certificate_config_impl.cc"],
hdrs = ["tls_certificate_config_impl.h"],
deps = [
"//include/envoy/ssl:tls_certificate_config_interface",
"//source/common/config:datasource_lib",
"@envoy_api//envoy/api/v2/auth:cert_cc",
],
)
Loading