Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1alpha1/clienttrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ type HeaderSettings struct {
//
// +optional
LateResponseHeaders *HTTPHeaderFilter `json:"lateResponseHeaders,omitempty"`

// Host enables managing how the Host/Authority header set by clients can be normalized.
//
// +optional
Host *HostSettings `json:"host,omitempty"`
Comment on lines +186 to +190
}

// WithUnderscoresAction configures the action to take when an HTTP header with underscores
Expand Down
21 changes: 21 additions & 0 deletions api/v1alpha1/hostsettings_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

// HostSettings provides settings that manage how the incoming Host/Authority header
// set by clients is normalized.
type HostSettings struct {
// StripTrailingHostDot determines if the trailing dot of the host should be removed
// from the Host/Authority header before any processing of the request.
// This affects the upstream host header as well. Without this option, incoming requests
// with host "example.com." will not match routes with domains set to "example.com".
// When the host includes a port (for example "example.com.:443"), only the trailing dot
// from the host section is stripped, leaving the port as-is ("example.com:443").
// Defaults to false.
//
// +optional
StripTrailingHostDot *bool `json:"stripTrailingHostDot,omitempty"`
}
25 changes: 25 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 @@ -499,6 +499,21 @@ spec:
EnableEnvoyHeaders configures Envoy Proxy to add the "X-Envoy-" headers to requests
and responses.
type: boolean
host:
description: Host enables managing how the Host/Authority header
set by clients can be normalized.
properties:
stripTrailingHostDot:
description: |-
StripTrailingHostDot determines if the trailing dot of the host should be removed
from the Host/Authority header before any processing of the request.
This affects the upstream host header as well. Without this option, incoming requests
with host "example.com." will not match routes with domains set to "example.com".
When the host includes a port (for example "example.com.:443"), only the trailing dot
from the host section is stripped, leaving the port as-is ("example.com:443").
Defaults to false.
type: boolean
type: object
lateResponseHeaders:
description: LateResponseHeaders defines settings for global response
header modification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,21 @@ spec:
EnableEnvoyHeaders configures Envoy Proxy to add the "X-Envoy-" headers to requests
and responses.
type: boolean
host:
description: Host enables managing how the Host/Authority header
set by clients can be normalized.
properties:
stripTrailingHostDot:
description: |-
StripTrailingHostDot determines if the trailing dot of the host should be removed
from the Host/Authority header before any processing of the request.
This affects the upstream host header as well. Without this option, incoming requests
with host "example.com." will not match routes with domains set to "example.com".
When the host includes a port (for example "example.com.:443"), only the trailing dot
from the host section is stripped, leaving the port as-is ("example.com:443").
Defaults to false.
type: boolean
type: object
lateResponseHeaders:
description: LateResponseHeaders defines settings for global response
header modification.
Expand Down
6 changes: 6 additions & 0 deletions internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,12 @@ func translateListenerHeaderSettings(headerSettings *egv1a1.HeaderSettings, http
}
}

if headerSettings.Host != nil && headerSettings.Host.StripTrailingHostDot != nil {
httpIR.Host = &ir.HostSettings{
StripTrailingHostDot: *headerSettings.Host.StripTrailingHostDot,
}
}

var errs error

if headerSettings.EarlyRequestHeaders != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
clientTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-gateway-1
spec:
headers:
host: {}
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-1
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http-1
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Same
139 changes: 139 additions & 0 deletions internal/gatewayapi/testdata/clienttrafficpolicy-host-empty.out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
clientTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
name: target-gateway-1
namespace: envoy-gateway
spec:
headers:
host: {}
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-1
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-1
namespace: envoy-gateway
conditions:
- lastTransitionTime: null
message: Policy has been accepted.
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: spec.targetRef is deprecated, use spec.targetRefs instead
reason: DeprecatedField
status: "True"
type: Warning
controllerName: gateway.envoyproxy.io/gatewayclass-controller
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-1
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
listeners:
- allowedRoutes:
namespaces:
from: Same
name: http-1
port: 80
protocol: HTTP
status:
listeners:
- attachedRoutes: 0
conditions:
- lastTransitionTime: null
message: Sending translated listener configuration to the data plane
reason: Programmed
status: "True"
type: Programmed
- lastTransitionTime: null
message: Listener has been successfully translated
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: Listener references have been resolved
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
name: http-1
supportedKinds:
- group: gateway.networking.k8s.io
kind: HTTPRoute
- group: gateway.networking.k8s.io
kind: GRPCRoute
infraIR:
envoy-gateway/gateway-1:
proxy:
listeners:
- name: envoy-gateway/gateway-1/http-1
ports:
- containerPort: 10080
name: http-80
protocol: HTTP
servicePort: 80
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
ownerReference:
kind: GatewayClass
name: envoy-gateway-class
name: envoy-gateway/gateway-1
namespace: envoy-gateway-system
xdsIR:
envoy-gateway/gateway-1:
accessLog:
json:
- path: /dev/stdout
globalResources:
proxyServiceCluster:
metadata:
kind: Service
name: envoy-envoy-gateway-gateway-1-196ae069
namespace: envoy-gateway-system
sectionName: "8080"
name: envoy-gateway/gateway-1
settings:
- addressType: IP
endpoints:
- host: 7.6.5.4
port: 8080
zone: zone1
metadata:
kind: Service
name: envoy-envoy-gateway-gateway-1-196ae069
namespace: envoy-gateway-system
sectionName: "8080"
name: envoy-gateway/gateway-1
protocol: TCP
http:
- address: 0.0.0.0
externalPort: 80
headers:
withUnderscoresAction: RejectRequest
hostnames:
- '*'
metadata:
kind: Gateway
name: gateway-1
namespace: envoy-gateway
sectionName: http-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: UnescapeAndRedirect
mergeSlashes: true
port: 10080
readyListener:
address: 0.0.0.0
ipFamily: IPv4
path: /ready
port: 19003
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
clientTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-gateway-1
spec:
headers:
host:
stripTrailingHostDot: true
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-1
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http-1
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Same
Loading
Loading