From e27717498dbcfb0d4ce04c6b4e616fffdb2b4b6a Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Tue, 25 Jan 2022 14:55:48 -0800 Subject: [PATCH] xds/bootstrap: escape authority when populating resource name template (#5160) --- xds/internal/xdsclient/bootstrap/bootstrap.go | 3 ++- xds/internal/xdsclient/bootstrap/bootstrap_test.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xds/internal/xdsclient/bootstrap/bootstrap.go b/xds/internal/xdsclient/bootstrap/bootstrap.go index ecec170774c..eef0e4fe6ff 100644 --- a/xds/internal/xdsclient/bootstrap/bootstrap.go +++ b/xds/internal/xdsclient/bootstrap/bootstrap.go @@ -25,6 +25,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "net/url" "strings" "github.com/golang/protobuf/jsonpb" @@ -401,7 +402,7 @@ func NewConfigFromContents(data []byte) (*Config, error) { // - if set, it must start with "xdstp:///" // - if not set, it defaults to "xdstp:///envoy.config.listener.v3.Listener/%s" for name, authority := range config.Authorities { - prefix := fmt.Sprintf("xdstp://%s", name) + prefix := fmt.Sprintf("xdstp://%s", url.PathEscape(name)) if authority.ClientListenerResourceNameTemplate == "" { authority.ClientListenerResourceNameTemplate = prefix + "/envoy.config.listener.v3.Listener/%s" continue diff --git a/xds/internal/xdsclient/bootstrap/bootstrap_test.go b/xds/internal/xdsclient/bootstrap/bootstrap_test.go index 6b6933e97bf..d681666077c 100644 --- a/xds/internal/xdsclient/bootstrap/bootstrap_test.go +++ b/xds/internal/xdsclient/bootstrap/bootstrap_test.go @@ -862,7 +862,8 @@ func TestNewConfigWithFederation(t *testing.T) { }], "client_default_listener_resource_name_template": "xdstp://xds.example.com/envoy.config.listener.v3.Listener/%s", "authorities": { - "xds.td.com": { } + "xds.td.com": { }, + "#.com": { } } }`, // It's OK for an authority to not have servers. The top-level server @@ -956,6 +957,9 @@ func TestNewConfigWithFederation(t *testing.T) { "xds.td.com": { ClientListenerResourceNameTemplate: "xdstp://xds.td.com/envoy.config.listener.v3.Listener/%s", }, + "#.com": { + ClientListenerResourceNameTemplate: "xdstp://%23.com/envoy.config.listener.v3.Listener/%s", + }, }, }, },