Skip to content

Commit

Permalink
feat: PreserveExternalRequestID on ClientTrafficPolicy
Browse files Browse the repository at this point in the history
Signed-off-by: Ardika Bagus <me@ardikabs.com>
  • Loading branch information
ardikabs committed Apr 20, 2024
1 parent fcfeefd commit 5506342
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 3 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/clienttrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ type HeaderSettings struct {
// is encountered. The default action is to reject the request.
// +optional
WithUnderscoresAction *WithUnderscoresAction `json:"withUnderscoresAction,omitempty"`

// PreserveExternalRequestID configures Envoy to keep the X-Request-ID header if passed for a request that is edge
// (Edge request is the request from external clients to front Envoy) and not reset it, which is the current Envoy behaviour.
// It defaults to false.
//
// +optional
PreserveExternalRequestID *bool `json:"preserveExternalRequestID,omitempty"`
}

// WithUnderscoresAction configures the action to take when an HTTP header with underscores
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ spec:
EnableEnvoyHeaders configures Envoy Proxy to add the "X-Envoy-" headers to requests
and responses.
type: boolean
preserveExternalRequestID:
description: |-
PreserveExternalRequestID configures Envoy to keep the X-Request-ID header if passed for a request that is edge
(Edge request is the request from external clients to front Envoy) and not reset it, which is the current Envoy behaviour.
It defaults to false.
type: boolean
withUnderscoresAction:
description: |-
WithUnderscoresAction configures the action to take when an HTTP header with underscores
Expand Down
5 changes: 3 additions & 2 deletions internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,9 @@ func translateListenerHeaderSettings(headerSettings *egv1a1.HeaderSettings, http
return
}
httpIR.Headers = &ir.HeaderSettings{
EnableEnvoyHeaders: ptr.Deref(headerSettings.EnableEnvoyHeaders, false),
WithUnderscoresAction: ir.WithUnderscoresAction(ptr.Deref(headerSettings.WithUnderscoresAction, egv1a1.WithUnderscoresActionRejectRequest)),
EnableEnvoyHeaders: ptr.Deref(headerSettings.EnableEnvoyHeaders, false),
WithUnderscoresAction: ir.WithUnderscoresAction(ptr.Deref(headerSettings.WithUnderscoresAction, egv1a1.WithUnderscoresActionRejectRequest)),
PreserveExternalRequestID: ptr.Deref(headerSettings.PreserveExternalRequestID, false),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ clientTrafficPolicies:
headers:
enableEnvoyHeaders: true
withUnderscoresAction: Allow
preserveExternalRequestID: true
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ clientTrafficPolicies:
spec:
headers:
enableEnvoyHeaders: true
preserveXRequestID: true
withUnderscoresAction: Allow
targetRef:
group: gateway.networking.k8s.io
Expand Down Expand Up @@ -130,6 +131,7 @@ xdsIR:
- address: 0.0.0.0
headers:
enableEnvoyHeaders: true
preserveExternalRequestID: true
withUnderscoresAction: Allow
hostnames:
- '*'
Expand All @@ -142,6 +144,7 @@ xdsIR:
- address: 0.0.0.0
headers:
enableEnvoyHeaders: true
preserveExternalRequestID: true
withUnderscoresAction: Allow
hostnames:
- '*'
Expand Down
5 changes: 5 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ type HeaderSettings struct {
// is encountered. The default action is to reject the request.
// Refer to https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/protocol.proto#envoy-v3-api-enum-config-core-v3-httpprotocoloptions-headerswithunderscoresaction
WithUnderscoresAction WithUnderscoresAction `json:"withUnderscoresAction,omitempty" yaml:"withUnderscoresAction,omitempty"`

// PreserveExternalRequestID configures whether Envoy will keep the x-request-id header if passed for a request that is edge
// (Edge request is the request from external clients to front Envoy) and not reset it, which is the current Envoy behaviour.
// It defaults to false.
PreserveExternalRequestID bool `json:"preserveExternalRequestID,omitempty" yaml:"preserveExternalRequestID,omitempty"`
}

// ClientTimeout sets the timeout configuration for downstream connections
Expand Down
3 changes: 2 additions & 1 deletion internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ func (t *Translator) addHCMToXDSListener(xdsListener *listenerv3.Listener, irLis
CommonHttpProtocolOptions: &corev3.HttpProtocolOptions{
HeadersWithUnderscoresAction: buildHeadersWithUnderscoresAction(irListener.Headers),
},
Tracing: hcmTracing,
Tracing: hcmTracing,
PreserveExternalRequestId: ptr.Deref(irListener.Headers, ir.HeaderSettings{}).PreserveExternalRequestID,
}

if irListener.Timeout != nil && irListener.Timeout.HTTP != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
http:
- name: "first-listener"
address: "0.0.0.0"
port: 8081
hostnames:
- "*"
routes:
- name: "first-route"
hostname: "*"
destination:
name: "first-route-dest"
settings:
- endpoints:
- host: "1.1.1.1"
port: 8081
headers:
preserveExternalRequestID: true
- name: "second-listener"
address: "0.0.0.0"
port: 8082
hostnames:
- "*"
routes:
- name: "second-route"
hostname: "*"
destination:
name: "second-route-dest"
settings:
- endpoints:
- host: "2.2.2.2"
port: 8082

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: first-route-dest
lbPolicy: LEAST_REQUEST
name: first-route-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: second-route-dest
lbPolicy: LEAST_REQUEST
name: second-route-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- clusterName: first-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.1.1.1
portValue: 8081
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: first-route-dest/backend/0
- clusterName: second-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 2.2.2.2
portValue: 8082
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: second-route-dest/backend/0
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- address:
socketAddress:
address: 0.0.0.0
portValue: 8081
defaultFilterChain:
filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
commonHttpProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
maxConcurrentStreams: 100
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
suppressEnvoyHeaders: true
normalizePath: true
preserveExternalRequestId: true
rds:
configSource:
ads: {}
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
useRemoteAddress: true
drainType: MODIFY_ONLY
name: first-listener
perConnectionBufferLimitBytes: 32768
- address:
socketAddress:
address: 0.0.0.0
portValue: 8082
defaultFilterChain:
filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
commonHttpProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
maxConcurrentStreams: 100
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
suppressEnvoyHeaders: true
normalizePath: true
rds:
configSource:
ads: {}
resourceApiVersion: V3
routeConfigName: second-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
useRemoteAddress: true
drainType: MODIFY_ONLY
name: second-listener
perConnectionBufferLimitBytes: 32768
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- ignorePortInHostMatching: true
name: first-listener
virtualHosts:
- domains:
- '*'
name: first-listener/*
routes:
- match:
prefix: /
name: first-route
route:
cluster: first-route-dest
upgradeConfigs:
- upgradeType: websocket
- ignorePortInHostMatching: true
name: second-listener
virtualHosts:
- domains:
- '*'
name: second-listener/*
routes:
- match:
prefix: /
name: second-route
route:
cluster: second-route-dest
upgradeConfigs:
- upgradeType: websocket
1 change: 1 addition & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `enableEnvoyHeaders` | _boolean_ | false | EnableEnvoyHeaders configures Envoy Proxy to add the "X-Envoy-" headers to requests<br />and responses. |
| `withUnderscoresAction` | _[WithUnderscoresAction](#withunderscoresaction)_ | false | WithUnderscoresAction configures the action to take when an HTTP header with underscores<br />is encountered. The default action is to reject the request. |
| `preserveExternalRequestID` | _boolean_ | false | PreserveExternalRequestID configures Envoy to keep the X-Request-ID header if passed for a request that is edge<br />(Edge request is the request from external clients to front Envoy) and not reset it, which is the current Envoy behaviour.<br />It defaults to false. |


#### HealthCheck
Expand Down

0 comments on commit 5506342

Please sign in to comment.