Skip to content
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

Sds api: implement SDS api #3700

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ REPOSITORY_LOCATIONS = dict(
remote = "https://github.com/google/libprotobuf-mutator",
),
com_github_grpc_grpc = dict(
commit = "bec3b5ada2c5e5d782dff0b7b5018df646b65cb0", # v1.12.0
remote = "https://github.com/grpc/grpc.git",
commit = "8e40a5b79a1e2f0535e71aab2bdc4844e5e5afd1",
# A forked grpc with local_credential supports.
remote = "https://github.com/qiwzhang/grpc.git",
),
io_opentracing_cpp = dict(
commit = "3b36b084a4d7fffc196eac83203cf24dfb8696b3", # v1.4.2
Expand Down
31 changes: 30 additions & 1 deletion include/envoy/secret/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,40 @@ load(

envoy_package()

envoy_cc_library(
name = "secret_callbacks_interface",
hdrs = ["secret_callbacks.h"],
)

envoy_cc_library(
name = "dynamic_secret_provider_interface",
hdrs = ["dynamic_secret_provider.h"],
deps = [
"secret_callbacks_interface",
"//include/envoy/ssl:tls_certificate_config_interface",
],
)

envoy_cc_library(
name = "dynamic_secret_provider_factory_interface",
hdrs = ["dynamic_secret_provider_factory.h"],
deps = [
":dynamic_secret_provider_interface",
"//include/envoy/event:dispatcher_interface",
"//include/envoy/local_info:local_info_interface",
"//include/envoy/runtime:runtime_interface",
"//include/envoy/stats:stats_interface",
"//include/envoy/upstream:cluster_manager_interface",
"@envoy_api//envoy/api/v2/core:config_source_cc",
],
)

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

#include <string>
Copy link
Member

Choose a reason for hiding this comment

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

nit: I don't think this is used.


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

namespace Envoy {
namespace Secret {

/**
* An interface to fetch dynamic secret.
*
* TODO(JimmyCYJ): Support other types of secrets.
*/
class DynamicTlsCertificateSecretProvider {
public:
virtual ~DynamicTlsCertificateSecretProvider() {}

/**
* @return the TlsCertificate secret. Returns nullptr if the secret is not found.
*/
virtual const Ssl::TlsCertificateConfig* secret() const PURE;
virtual void addUpdateCallback(SecretCallbacks& callback) PURE;
virtual void removeUpdateCallback(SecretCallbacks& callback) PURE;
};

typedef std::shared_ptr<DynamicTlsCertificateSecretProvider>
DynamicTlsCertificateSecretProviderSharedPtr;

} // namespace Secret
} // namespace Envoy
70 changes: 70 additions & 0 deletions include/envoy/secret/dynamic_secret_provider_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include "envoy/api/v2/core/config_source.pb.h"
#include "envoy/event/dispatcher.h"
#include "envoy/local_info/local_info.h"
#include "envoy/runtime/runtime.h"
#include "envoy/secret/dynamic_secret_provider.h"
#include "envoy/stats/stats.h"
#include "envoy/upstream/cluster_manager.h"

namespace Envoy {
namespace Secret {

/**
* DynamicTlsCertificateSecretProviderFactoryContext passed to
* DynamicTlsCertificateSecretProviderFactory to access resources which are needed for creating
* dynamic tls certificate secret provider.
*/
class DynamicTlsCertificateSecretProviderFactoryContext {
public:
virtual ~DynamicTlsCertificateSecretProviderFactoryContext() {}

/**
* @return information about the local environment the server is running in.
*/
virtual const LocalInfo::LocalInfo& local_info() PURE;

/**
* @return Event::Dispatcher& the main thread's dispatcher.
*/
virtual Event::Dispatcher& dispatcher() PURE;

/**
* @return RandomGenerator& the random generator for the server.
*/
virtual Runtime::RandomGenerator& random() PURE;

/**
* @return the server-wide stats store.
*/
virtual Stats::Store& stats() PURE;

/**
* @return Upstream::ClusterManager.
*/
virtual Upstream::ClusterManager& cluster_manager() PURE;
};

/**
* Factory for creating dynamic TlsCertificate secret provider.
*/
class DynamicTlsCertificateSecretProviderFactory {
public:
virtual ~DynamicTlsCertificateSecretProviderFactory() {}

/**
* Finds and returns a secret provider associated to SDS config. Create a new one
* if such provider does not exist.
*
* @param config_source a protobuf message object contains SDS config source.
* @param config_name a name that uniquely refers to the SDS config source.
* @return the dynamic tls certificate secret provider.
*/
virtual DynamicTlsCertificateSecretProviderSharedPtr
findOrCreate(const envoy::api::v2::core::ConfigSource& sds_config,
std::string sds_config_name) PURE;
};

} // namespace Secret
} // namespace Envoy
22 changes: 22 additions & 0 deletions include/envoy/secret/secret_callbacks.h
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
33 changes: 28 additions & 5 deletions include/envoy/secret/secret_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
#include <string>

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

namespace Envoy {
namespace Secret {

/**
* A manager for static secrets.
*
* TODO(jaebong) Support dynamic secrets.
* A manager for static and dynamic secrets.
*/
class SecretManager {
public:
Expand All @@ -21,13 +20,37 @@ class 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;
virtual void addStaticSecret(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;
virtual const Ssl::TlsCertificateConfig*
findStaticTlsCertificate(const std::string& name) const PURE;

/**
* Finds and returns a secret provider associated to SDS config. Return nullptr
* if such provider does not exist.
*
* @param config_source a protobuf message object contains SDS config source.
* @param config_name a name that uniquely refers to the SDS config source.
* @return the dynamic tls certificate secret provider.
*/
virtual DynamicTlsCertificateSecretProviderSharedPtr
findDynamicTlsCertificateSecretProvider(const envoy::api::v2::core::ConfigSource& config_source,
const std::string& config_name) PURE;

/**
* Add new dynamic tls certificate secret provider into secret manager.
*
* @param config_source a protobuf message object contains SDS config source.
* @param config_name a name that uniquely refers to the SDS config source.
* @param provider the dynamic tls certificate secret provider to be added into secret manager.
*/
virtual void setDynamicTlsCertificateSecretProvider(
const envoy::api::v2::core::ConfigSource& config_source, const std::string& config_name,
DynamicTlsCertificateSecretProviderSharedPtr provider) PURE;
};

} // namespace Secret
Expand Down
3 changes: 3 additions & 0 deletions include/envoy/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ envoy_cc_library(
name = "transport_socket_config_interface",
hdrs = ["transport_socket_config.h"],
deps = [
"//include/envoy/init:init_interface",
"//include/envoy/network:transport_socket_interface",
"//include/envoy/secret:dynamic_secret_provider_factory_interface",
"//include/envoy/secret:secret_manager_interface",
"//include/envoy/ssl:context_manager_interface",
"//include/envoy/upstream:cluster_manager_interface",
"//source/common/protobuf",
],
)
Expand Down
19 changes: 19 additions & 0 deletions include/envoy/server/transport_socket_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

#include <string>

#include "envoy/init/init.h"
#include "envoy/network/transport_socket.h"
#include "envoy/secret/dynamic_secret_provider_factory.h"
#include "envoy/secret/secret_manager.h"
#include "envoy/ssl/context_manager.h"
#include "envoy/upstream/cluster_manager.h"

#include "common/protobuf/protobuf.h"

Expand All @@ -29,10 +32,26 @@ class TransportSocketFactoryContext {
*/
virtual Stats::Scope& statsScope() const PURE;

/**
* @return the instance of init manager.
*/
virtual Init::Manager& initManager() PURE;

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

/**
* @return the instance of ClusterManager.
*/
virtual Upstream::ClusterManager& clusterManager() PURE;

/**
* @return the factory of dynamic tls certificate secret provider.
*/
virtual Secret::DynamicTlsCertificateSecretProviderFactory&
dynamicTlsCertificateSecretProviderFactory() PURE;
};

class TransportSocketConfigFactory {
Expand Down
16 changes: 16 additions & 0 deletions include/envoy/ssl/context_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>

#include "envoy/common/pure.h"
#include "envoy/secret/dynamic_secret_provider.h"
Copy link
Member

Choose a reason for hiding this comment

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

is this needed?


namespace Envoy {
namespace Ssl {
Expand Down Expand Up @@ -111,6 +112,17 @@ class ContextConfig {
* @return The maximum TLS protocol version to negotiate.
*/
virtual unsigned maxProtocolVersion() const PURE;

/**
* @return true if the config is valid. Only when SDS dynamic secret is needed, but has not been
* downloaded yet, the config is invalid.
*/
virtual bool isValid() const PURE;
Copy link
Member

Choose a reason for hiding this comment

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

Would isReady be better name for this?

Copy link
Member

Choose a reason for hiding this comment

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

+1


/**
* @return the DynamicSecretProvider object.
*/
virtual Secret::DynamicTlsCertificateSecretProvider* getDynamicSecretProvider() const PURE;
};

class ClientContextConfig : public virtual ContextConfig {
Expand All @@ -127,6 +139,8 @@ class ClientContextConfig : public virtual ContextConfig {
virtual bool allowRenegotiation() const PURE;
};

typedef std::unique_ptr<ClientContextConfig> ClientContextConfigPtr;

class ServerContextConfig : public virtual ContextConfig {
public:
struct SessionTicketKey {
Expand All @@ -148,5 +162,7 @@ class ServerContextConfig : public virtual ContextConfig {
virtual const std::vector<SessionTicketKey>& sessionTicketKeys() const PURE;
};

typedef std::unique_ptr<ServerContextConfig> ServerContextConfigPtr;

} // namespace Ssl
} // namespace Envoy
1 change: 1 addition & 0 deletions include/envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class PrioritySet {
COUNTER (upstream_cx_http1_total) \
COUNTER (upstream_cx_http2_total) \
COUNTER (upstream_cx_connect_fail) \
COUNTER (upstream_cx_connect_fail_by_sds) \
COUNTER (upstream_cx_connect_timeout) \
COUNTER (upstream_cx_idle_timeout) \
COUNTER (upstream_cx_connect_attempts_exceeded) \
Expand Down
1 change: 1 addition & 0 deletions source/common/common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace Logger {
FUNCTION(router) \
FUNCTION(runtime) \
FUNCTION(stats) \
FUNCTION(secret) \
FUNCTION(testing) \
FUNCTION(thrift) \
FUNCTION(tracing) \
Expand Down
1 change: 1 addition & 0 deletions source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ envoy_cc_library(
hdrs = ["protobuf_link_hacks.h"],
deps = [
"@envoy_api//envoy/service/discovery/v2:ads_cc",
"@envoy_api//envoy/service/discovery/v2:sds_cc",
"@envoy_api//envoy/service/ratelimit/v2:rls_cc",
],
)
Expand Down
2 changes: 2 additions & 0 deletions source/common/config/protobuf_link_hacks.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#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 {
Expand All @@ -9,4 +10,5 @@ namespace Envoy {
// This file should be included ONLY if this hack is required.
const envoy::service::discovery::v2::AdsDummy _ads_dummy;
const envoy::service::ratelimit::v2::RateLimitRequest _rls_dummy;
const envoy::service::discovery::v2::SdsDummy _sds_dummy;
} // namespace Envoy
1 change: 1 addition & 0 deletions source/common/config/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TypeUrlValues {
const std::string Listener{"type.googleapis.com/envoy.api.v2.Listener"};
const std::string Cluster{"type.googleapis.com/envoy.api.v2.Cluster"};
const std::string ClusterLoadAssignment{"type.googleapis.com/envoy.api.v2.ClusterLoadAssignment"};
const std::string Secret{"type.googleapis.com/envoy.api.v2.auth.Secret"};
const std::string RouteConfiguration{"type.googleapis.com/envoy.api.v2.RouteConfiguration"};
};

Expand Down
1 change: 1 addition & 0 deletions source/common/grpc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ envoy_cc_library(
deps = [
"//include/envoy/grpc:google_grpc_creds_interface",
"//include/envoy/registry",
"//source/common/common:utility_lib",
"//source/common/config:datasource_lib",
],
)
Loading