Skip to content

Commit 432bda3

Browse files
xdsclient/xdsresource: add AutoHostRewrite and Endpoint Hostname support (grpc#8728)
This PR implements the validation logic and extracting per endpoint Hostname attributes from xDS resources for [gRFC A81](https://github.com/grpc/proposal/blob/master/A81-xds-authority-rewriting.md) ### Key Changes: 1. **RDS Resource Validation :** * The boolean value of `RouteAction.auto_host_rewrite` is extracted from the RDS resource and stored in route struct * This field is only set to `true` in the parsed route struct if the `trusted_xds_server` option is present in the `ServerConfig` and the global environment variable for authority overriding is enabled. 2. **EDS Resource Validation:** * The `Endpoint.hostname` field is extracted from the EDS resource and will be stored as a `hostname` string in parsed endpoint struct. It will be changed to be an per-endpoint resolver attribute in a follow-up PR. RELEASE NOTES: None
1 parent 749af0c commit 432bda3

File tree

12 files changed

+244
-78
lines changed

12 files changed

+244
-78
lines changed

internal/envconfig/envconfig.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ var (
7777
// - Target resolution is disabled.
7878
// - The DNS resolver is being used.
7979
EnableDefaultPortForProxyTarget = boolFromEnv("GRPC_EXPERIMENTAL_ENABLE_DEFAULT_PORT_FOR_PROXY_TARGET", true)
80+
81+
// XDSAuthorityRewrite indicates whether xDS authority rewriting is enabled.
82+
// This feature is defined in gRFC A81 and is enabled by setting the
83+
// environment variable GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE to "true".
84+
XDSAuthorityRewrite = boolFromEnv("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE", false)
8085
)
8186

8287
func boolFromEnv(envVar string, def bool) bool {

internal/xds/xdsclient/xdsresource/filter_chain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ func processNetworkFilters(filters []*v3listenerpb.Filter) (*FilterChain, error)
680680
// server-side." - A36
681681
// Can specify v3 here, as will never get to this function
682682
// if v2.
683-
routeU, err := generateRDSUpdateFromRouteConfiguration(hcm.GetRouteConfig())
683+
routeU, err := generateRDSUpdateFromRouteConfiguration(hcm.GetRouteConfig(), nil)
684684
if err != nil {
685685
return nil, fmt.Errorf("failed to parse inline RDS resp: %v", err)
686686
}

internal/xds/xdsclient/xdsresource/listener_resource_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ type listenerResourceDecoder struct {
3535
bootstrapConfig *bootstrap.Config
3636
}
3737

38-
func (d *listenerResourceDecoder) Decode(resource *xdsclient.AnyProto, _ xdsclient.DecodeOptions) (*xdsclient.DecodeResult, error) {
39-
name, listener, err := unmarshalListenerResource(resource.ToAny())
38+
func (d *listenerResourceDecoder) Decode(resource *xdsclient.AnyProto, opts xdsclient.DecodeOptions) (*xdsclient.DecodeResult, error) {
39+
name, listener, err := unmarshalListenerResource(resource.ToAny(), &opts)
4040
if name == "" {
4141
// Name is unset only when protobuf deserialization fails.
4242
return nil, err

internal/xds/xdsclient/xdsresource/route_config_resource_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ type routeConfigResourceDecoder struct {
3737
bootstrapConfig *bootstrap.Config
3838
}
3939

40-
func (d *routeConfigResourceDecoder) Decode(resource *xdsclient.AnyProto, _ xdsclient.DecodeOptions) (*xdsclient.DecodeResult, error) {
41-
name, rc, err := unmarshalRouteConfigResource(resource.ToAny())
40+
func (d *routeConfigResourceDecoder) Decode(resource *xdsclient.AnyProto, opts xdsclient.DecodeOptions) (*xdsclient.DecodeResult, error) {
41+
name, rc, err := unmarshalRouteConfigResource(resource.ToAny(), &opts)
4242
if name == "" {
4343
// Name is unset only when protobuf deserialization fails.
4444
return nil, err

internal/xds/xdsclient/xdsresource/type_eds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Endpoint struct {
5454
Weight uint32
5555
HashKey string
5656
Metadata map[string]any
57+
Hostname string
5758
}
5859

5960
// Locality contains information of a locality.

internal/xds/xdsclient/xdsresource/type_rds.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ type Route struct {
150150
// ClusterSpecifierPlugin is the name of the Cluster Specifier Plugin that
151151
// this Route is linked to, if specified by xDS.
152152
ClusterSpecifierPlugin string
153+
// AutoHostRewrite indicates that the ":authority" header can be rewritten
154+
// to the hostname of the upstream endpoint.
155+
AutoHostRewrite bool
153156
}
154157

155158
// WeightedCluster contains settings for an xds ActionType.WeightedCluster.

internal/xds/xdsclient/xdsresource/unmarshal_eds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func parseEndpoints(lbEndpoints []*v3endpointpb.LbEndpoint, uniqueEndpointAddrs
132132
Weight: weight,
133133
HashKey: hashKey,
134134
Metadata: endpointMetadata,
135+
Hostname: lbEndpoint.GetEndpoint().GetHostname(),
135136
})
136137
}
137138
return endpoints, nil

0 commit comments

Comments
 (0)