From 6dc5096143bd7dcc0c978dd30a410e9766157968 Mon Sep 17 00:00:00 2001 From: Blake Covarrubias Date: Mon, 9 Aug 2021 17:10:32 -0700 Subject: [PATCH] cli: Use admin bind address in self_admin cluster (#10757) Configure the self_admin cluster to use the admin bind address provided when starting Envoy. Fixes #10747 --- .changelog/10757.txt | 4 +++ command/connect/envoy/bootstrap_config.go | 2 +- .../connect/envoy/bootstrap_config_test.go | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .changelog/10757.txt diff --git a/.changelog/10757.txt b/.changelog/10757.txt new file mode 100644 index 000000000000..35a90591fad6 --- /dev/null +++ b/.changelog/10757.txt @@ -0,0 +1,4 @@ +```release-note:bug +cli: Ensure the metrics endpoint is accessible when Envoy is configured to use +a non-default admin bind address. +``` diff --git a/command/connect/envoy/bootstrap_config.go b/command/connect/envoy/bootstrap_config.go index f2d696e21609..242449ec2737 100644 --- a/command/connect/envoy/bootstrap_config.go +++ b/command/connect/envoy/bootstrap_config.go @@ -416,7 +416,7 @@ func (c *BootstrapConfig) generateListenerConfig(args *BootstrapTplArgs, bindAdd "hosts": [ { "socket_address": { - "address": "127.0.0.1", + "address": "` + args.AdminBindAddress + `", "port_value": ` + args.AdminBindPort + ` } } diff --git a/command/connect/envoy/bootstrap_config_test.go b/command/connect/envoy/bootstrap_config_test.go index d6d33d13f384..533cdb7f82bb 100644 --- a/command/connect/envoy/bootstrap_config_test.go +++ b/command/connect/envoy/bootstrap_config_test.go @@ -23,6 +23,20 @@ const ( } ] }` + expectedSelfAdminClusterNonLoopbackIP = `{ + "name": "self_admin", + "connect_timeout": "5s", + "type": "STATIC", + "http_protocol_options": {}, + "hosts": [ + { + "socket_address": { + "address": "192.0.2.10", + "port_value": 19002 + } + } + ] + }` expectedPromListener = `{ "name": "envoy_prometheus_metrics_listener", "address": { @@ -442,6 +456,26 @@ func TestBootstrapConfig_ConfigureArgs(t *testing.T) { }, wantErr: false, }, + { + name: "prometheus-bind-addr-non-loopback-ip", + input: BootstrapConfig{ + PrometheusBindAddr: "0.0.0.0:9000", + }, + baseArgs: BootstrapTplArgs{ + AdminBindAddress: "192.0.2.10", + AdminBindPort: "19002", + }, + wantArgs: BootstrapTplArgs{ + AdminBindAddress: "192.0.2.10", + AdminBindPort: "19002", + // Should add a static cluster for the self-proxy to admin + StaticClustersJSON: expectedSelfAdminClusterNonLoopbackIP, + // Should add a static http listener too + StaticListenersJSON: expectedPromListener, + StatsConfigJSON: defaultStatsConfigJSON, + }, + wantErr: false, + }, { name: "prometheus-bind-addr-with-overrides", input: BootstrapConfig{