From 82b158f2490c6fec42144deee1d1c8d22878b614 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 24 Nov 2020 23:48:18 -0800 Subject: [PATCH] Update file watcher certificate provider factory with provider implementation --- ...le_watcher_certificate_provider_factory.cc | 25 +++++++++++++++++++ ...ile_watcher_certificate_provider_factory.h | 5 +--- .../plugin_registry/grpc_plugin_registry.cc | 6 +++++ test/cpp/end2end/xds_end2end_test.cc | 13 ++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/core/ext/xds/file_watcher_certificate_provider_factory.cc b/src/core/ext/xds/file_watcher_certificate_provider_factory.cc index fab8dac52ef..a5250eba7c4 100644 --- a/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +++ b/src/core/ext/xds/file_watcher_certificate_provider_factory.cc @@ -23,6 +23,7 @@ #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" +#include "src/core/ext/xds/certificate_provider_registry.h" #include "src/core/lib/json/json_util.h" namespace grpc_core { @@ -116,4 +117,28 @@ FileWatcherCertificateProviderFactory::CreateCertificateProviderConfig( error); } +RefCountedPtr +FileWatcherCertificateProviderFactory::CreateCertificateProvider( + RefCountedPtr config) { + if (config->name() != name()) { + gpr_log(GPR_ERROR, "Wrong config type Actual:%s vs Expected:%s", + config->name(), name()); + return nullptr; + } + auto* file_watcher_config = + static_cast(config.get()); + return MakeRefCounted( + file_watcher_config->private_key_file(), + file_watcher_config->identity_cert_file(), + file_watcher_config->root_cert_file(), + file_watcher_config->refresh_interval_ms() / GPR_MS_PER_SEC); +} + +void FileWatcherCertificateProviderInit() { + CertificateProviderRegistry::RegisterCertificateProviderFactory( + absl::make_unique()); +} + +void FileWatcherCertificateProviderShutdown() {} + } // namespace grpc_core diff --git a/src/core/ext/xds/file_watcher_certificate_provider_factory.h b/src/core/ext/xds/file_watcher_certificate_provider_factory.h index 96b61e1869b..c5700625e95 100644 --- a/src/core/ext/xds/file_watcher_certificate_provider_factory.h +++ b/src/core/ext/xds/file_watcher_certificate_provider_factory.h @@ -61,10 +61,7 @@ class FileWatcherCertificateProviderFactory grpc_error** error) override; RefCountedPtr CreateCertificateProvider( - RefCountedPtr config) override { - // TODO(yashykt) : To be implemented - return nullptr; - } + RefCountedPtr config) override; }; } // namespace grpc_core diff --git a/src/core/plugin_registry/grpc_plugin_registry.cc b/src/core/plugin_registry/grpc_plugin_registry.cc index 55815238fec..b532c0042cf 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_plugin_registry.cc @@ -68,6 +68,10 @@ void XdsClientGlobalShutdown(); } // namespace grpc_core void grpc_certificate_provider_registry_init(void); void grpc_certificate_provider_registry_shutdown(void); +namespace grpc_core { +void FileWatcherCertificateProviderInit(); +void FileWatcherCertificateProviderShutdown(); +} // namespace grpc_core void grpc_lb_policy_cds_init(void); void grpc_lb_policy_cds_shutdown(void); void grpc_lb_policy_eds_init(void); @@ -126,6 +130,8 @@ void grpc_register_built_in_plugins(void) { grpc_core::XdsClientGlobalShutdown); grpc_register_plugin(grpc_certificate_provider_registry_init, grpc_certificate_provider_registry_shutdown); + grpc_register_plugin(grpc_core::FileWatcherCertificateProviderInit, + grpc_core::FileWatcherCertificateProviderShutdown); grpc_register_plugin(grpc_lb_policy_cds_init, grpc_lb_policy_cds_shutdown); grpc_register_plugin(grpc_lb_policy_eds_init, diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index cdc5f6bc944..81fbef074c2 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -184,6 +184,14 @@ constexpr char kBootstrapFileV3[] = " },\n" " \"fake_plugin2\": {\n" " \"plugin_name\": \"fake2\"\n" + " },\n" + " \"file_plugin\": {\n" + " \"plugin_name\": \"file_watcher\",\n" + " \"config\": {\n" + " \"certificate_file\": \"src/core/tsi/test_creds/client.pem\",\n" + " \"private_key_file\": \"src/core/tsi/test_creds/client.key\",\n" + " \"ca_certificate_file\": \"src/core/tsi/test_creds/ca.pem\"\n" + " }" " }\n" " }\n" "}\n"; @@ -5630,6 +5638,11 @@ TEST_P(XdsSecurityTest, TestFallbackToTls) { g_fake1_cert_data_map = nullptr; } +TEST_P(XdsSecurityTest, TestFileWatcherCertificateProvider) { + UpdateAndVerifyXdsSecurityConfiguration("file_plugin", "", "file_plugin", "", + authenticated_identity_1_); +} + using EdsTest = BasicTest; // Tests that EDS client should send a NACK if the EDS update contains