Skip to content

Commit 139c558

Browse files
authored
bug fix: return bootstrap when validating config (envoyproxy#17643)
(cherry picked from commit 0bd670a, PR envoyproxy#17499) Co-authored-by: qinggniq <livewithblank@gmail.com> Signed-off-by: Greg Greenway <ggreenway@apple.com>
1 parent f5ccbc8 commit 139c558

File tree

5 files changed

+102
-9
lines changed

5 files changed

+102
-9
lines changed

source/server/config_validation/server.cc

+7-8
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,20 @@ void ValidationInstance::initialize(const Options& options,
7777
// If we get all the way through that stripped-down initialization flow, to the point where we'd
7878
// be ready to serve, then the config has passed validation.
7979
// Handle configuration that needs to take place prior to the main configuration load.
80-
envoy::config::bootstrap::v3::Bootstrap bootstrap;
81-
InstanceUtil::loadBootstrapConfig(bootstrap, options,
80+
InstanceUtil::loadBootstrapConfig(bootstrap_, options,
8281
messageValidationContext().staticValidationVisitor(), *api_);
8382

84-
Config::Utility::createTagProducer(bootstrap);
85-
bootstrap.mutable_node()->set_hidden_envoy_deprecated_build_version(VersionInfo::version());
83+
Config::Utility::createTagProducer(bootstrap_);
84+
bootstrap_.mutable_node()->set_hidden_envoy_deprecated_build_version(VersionInfo::version());
8685

8786
local_info_ = std::make_unique<LocalInfo::LocalInfoImpl>(
88-
stats().symbolTable(), bootstrap.node(), bootstrap.node_context_params(), local_address,
87+
stats().symbolTable(), bootstrap_.node(), bootstrap_.node_context_params(), local_address,
8988
options.serviceZone(), options.serviceClusterName(), options.serviceNodeName());
9089

9190
overload_manager_ = std::make_unique<OverloadManagerImpl>(
92-
dispatcher(), stats(), threadLocal(), bootstrap.overload_manager(),
91+
dispatcher(), stats(), threadLocal(), bootstrap_.overload_manager(),
9392
messageValidationContext().staticValidationVisitor(), *api_, options_);
94-
Configuration::InitialImpl initial_config(bootstrap, options, *this);
93+
Configuration::InitialImpl initial_config(bootstrap_, options, *this);
9594
admin_ = std::make_unique<Server::ValidationAdmin>(initial_config.admin().address());
9695
listener_manager_ = std::make_unique<ListenerManagerImpl>(*this, *this, *this, false);
9796
thread_local_.registerThread(*dispatcher_, true);
@@ -103,7 +102,7 @@ void ValidationInstance::initialize(const Options& options,
103102
admin(), runtime(), stats(), threadLocal(), dnsResolver(), sslContextManager(), dispatcher(),
104103
localInfo(), *secret_manager_, messageValidationContext(), *api_, http_context_,
105104
grpc_context_, router_context_, accessLogManager(), singletonManager(), options);
106-
config_.initialize(bootstrap, *this, *cluster_manager_factory_);
105+
config_.initialize(bootstrap_, *this, *cluster_manager_factory_);
107106
runtime().initialize(clusterManager());
108107
clusterManager().setInitializedCb([this]() -> void { init_manager_.initialize(init_watcher_); });
109108
}

source/server/config_validation/server.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ValidationInstance final : Logger::Loggable<Logger::Id::main>,
110110
}
111111

112112
Configuration::StatsConfig& statsConfig() override { return config_.statsConfig(); }
113-
envoy::config::bootstrap::v3::Bootstrap& bootstrap() override { NOT_IMPLEMENTED_GCOVR_EXCL_LINE; }
113+
envoy::config::bootstrap::v3::Bootstrap& bootstrap() override { return bootstrap_; }
114114
Configuration::ServerFactoryContext& serverFactoryContext() override { return server_contexts_; }
115115
Configuration::TransportSocketFactoryContext& transportSocketFactoryContext() override {
116116
return server_contexts_;
@@ -194,6 +194,7 @@ class ValidationInstance final : Logger::Loggable<Logger::Id::main>,
194194
Event::DispatcherPtr dispatcher_;
195195
std::unique_ptr<Server::ValidationAdmin> admin_;
196196
Singleton::ManagerPtr singleton_manager_;
197+
envoy::config::bootstrap::v3::Bootstrap bootstrap_;
197198
std::unique_ptr<Runtime::ScopedLoaderSingleton> runtime_singleton_;
198199
Random::RandomGeneratorImpl random_generator_;
199200
std::unique_ptr<Ssl::ContextManager> ssl_context_manager_;

test/extensions/filters/http/ext_authz/BUILD

+5
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,15 @@ envoy_extension_cc_test(
5656
envoy_extension_cc_test(
5757
name = "ext_authz_integration_test",
5858
srcs = ["ext_authz_integration_test.cc"],
59+
data = [
60+
"ext_authz.yaml",
61+
],
5962
extension_names = ["envoy.filters.http.ext_authz"],
6063
deps = [
6164
"//source/extensions/filters/http/ext_authz:config",
65+
"//source/server/config_validation:server_lib",
6266
"//test/integration:http_integration_lib",
67+
"//test/mocks/server:options_mocks",
6368
"//test/test_common:utility_lib",
6469
"@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto",
6570
"@envoy_api//envoy/config/listener/v3:pkg_cc_proto",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Regression test for https://github.com/envoyproxy/envoy/issues/17344
2+
static_resources:
3+
listeners:
4+
- address:
5+
socket_address:
6+
address: 0.0.0.0
7+
port_value: 8080
8+
filter_chains:
9+
- filters:
10+
- name: envoy.filters.network.http_connection_manager
11+
typed_config:
12+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
13+
stat_prefix: ingress_http
14+
route_config:
15+
name: local_route
16+
virtual_hosts:
17+
- name: local_service
18+
domains: ["*"]
19+
routes:
20+
- match:
21+
prefix: "/"
22+
route:
23+
cluster: local_service
24+
http_filters:
25+
- name: envoy.ext_authz
26+
typed_config:
27+
"@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz
28+
failure_mode_allow: false
29+
transport_api_version: V3
30+
status_on_error:
31+
code: 503
32+
grpc_service:
33+
envoy_grpc:
34+
cluster_name: ext_authz-service
35+
timeout: 0.5s
36+
with_request_body:
37+
max_request_bytes: 10240
38+
allow_partial_message: true
39+
pack_as_bytes: false
40+
- name: envoy.filters.http.router
41+
typed_config: {}
42+
clusters:
43+
- name: local_service
44+
connect_timeout: 30s
45+
type: STRICT_DNS
46+
lb_policy: ROUND_ROBIN
47+
load_assignment:
48+
cluster_name: local_service
49+
endpoints:
50+
- lb_endpoints:
51+
- endpoint:
52+
address:
53+
socket_address:
54+
address: main
55+
port_value: 8080
56+
- name: ext_authz-service
57+
type: STRICT_DNS
58+
lb_policy: ROUND_ROBIN
59+
typed_extension_protocol_options:
60+
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
61+
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
62+
explicit_http_config:
63+
http2_protocol_options: {}
64+
load_assignment:
65+
cluster_name: ext_authz-service
66+
endpoints:
67+
- lb_endpoints:
68+
- endpoint:
69+
address:
70+
socket_address:
71+
address: opa
72+
port_value: 80
73+
admin:
74+
address:
75+
socket_address:
76+
address: 0.0.0.0
77+
port_value: 8081

test/extensions/filters/http/ext_authz/ext_authz_integration_test.cc

+11
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#include "envoy/service/auth/v3/external_auth.pb.h"
55

66
#include "source/common/common/macros.h"
7+
#include "source/server/config_validation/server.h"
78

89
#include "test/common/grpc/grpc_client_integration.h"
910
#include "test/integration/http_integration.h"
11+
#include "test/mocks/server/options.h"
1012
#include "test/test_common/utility.h"
1113

1214
#include "absl/strings/str_format.h"
@@ -885,4 +887,13 @@ TEST_P(ExtAuthzGrpcIntegrationTest, GoogleAsyncClientCreation) {
885887
cleanup();
886888
}
887889

890+
// Regression test for https://github.com/envoyproxy/envoy/issues/17344
891+
TEST(ExtConfigValidateTest, Validate) {
892+
Server::TestComponentFactory component_factory;
893+
EXPECT_TRUE(validateConfig(testing::NiceMock<Server::MockOptions>(TestEnvironment::runfilesPath(
894+
"test/extensions/filters/http/ext_authz/ext_authz.yaml")),
895+
Network::Address::InstanceConstSharedPtr(), component_factory,
896+
Thread::threadFactoryForTest(), Filesystem::fileSystemForTest()));
897+
}
898+
888899
} // namespace Envoy

0 commit comments

Comments
 (0)