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
2 changes: 1 addition & 1 deletion api/v1alpha1/authorization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type Principal struct {
//
// The client IP is inferred from the X-Forwarded-For header, a custom header,
// or the proxy protocol.
// You can use the `ClientIPDetection` or the `EnableProxyProtocol` field in
// You can use the `ClientIPDetection` or the `ProxyProtocol` field in
// the `ClientTrafficPolicy` to configure how the client IP is detected.
//
// +optional
Expand Down
28 changes: 28 additions & 0 deletions api/v1alpha1/clienttrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ type ClientTrafficPolicySpec struct {
// Note Proxy Protocol must be present when this field is set, else the connection
// is closed.
//
// Deprecated: Use ProxyProtocol instead.
//
// +optional
EnableProxyProtocol *bool `json:"enableProxyProtocol,omitempty"`
// ProxyProtocol configures the Proxy Protocol settings. When configured,
// the Proxy Protocol header will be interpreted and the Client Address
// will be added into the X-Forwarded-For header.
// If both EnableProxyProtocol and ProxyProtocol are set, ProxyProtocol takes precedence.
//
// +optional
ProxyProtocol *ProxyProtocolSettings `json:"proxyProtocol,omitempty"`
// ClientIPDetectionSettings provides configuration for determining the original client IP address for requests.
//
// +optional
Expand Down Expand Up @@ -344,6 +353,25 @@ type HealthCheckSettings struct {
Path string `json:"path"`
}

// ProxyProtocolSettings configures the Proxy Protocol settings. When configured,
// the Proxy Protocol header will be interpreted and the Client Address
// will be added into the X-Forwarded-For header.
// If both EnableProxyProtocol and ProxyProtocol are set, ProxyProtocol takes precedence.
//
// +kubebuilder:validation:MinProperties=0
type ProxyProtocolSettings struct {
// Optional allows requests without a Proxy Protocol header to be proxied.
// If set to true, the listener will accept requests without a Proxy Protocol header.
// If set to false, the listener will reject requests without a Proxy Protocol header.
// If not set, the default behavior is to reject requests without a Proxy Protocol header.
// Warning: Optional breaks conformance with the specification. Only enable if ALL traffic to the listener comes from a trusted source.
// For more information on security implications, see haproxy.org/download/2.1/doc/proxy-protocol.txt
//
//
// +optional
Optional *bool `json:"optional,omitempty"`
}

//+kubebuilder:object:root=true

// ClientTrafficPolicyList contains a list of ClientTrafficPolicy resources.
Expand Down
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 @@ -182,6 +182,8 @@ spec:
Client Address into the X-Forwarded-For header.
Note Proxy Protocol must be present when this field is set, else the connection
is closed.

Deprecated: Use ProxyProtocol instead.
type: boolean
headers:
description: HeaderSettings provides configuration for header management.
Expand Down Expand Up @@ -514,6 +516,24 @@ spec:
- UnescapeAndRedirect
type: string
type: object
proxyProtocol:
description: |-
ProxyProtocol configures the Proxy Protocol settings. When configured,
the Proxy Protocol header will be interpreted and the Client Address
will be added into the X-Forwarded-For header.
If both EnableProxyProtocol and ProxyProtocol are set, ProxyProtocol takes precedence.
minProperties: 0
properties:
optional:
description: |-
Optional allows requests without a Proxy Protocol header to be proxied.
If set to true, the listener will accept requests without a Proxy Protocol header.
If set to false, the listener will reject requests without a Proxy Protocol header.
If not set, the default behavior is to reject requests without a Proxy Protocol header.
Warning: Optional breaks conformance with the specification. Only enable if ALL traffic to the listener comes from a trusted source.
For more information on security implications, see haproxy.org/download/2.1/doc/proxy-protocol.txt
type: boolean
type: object
targetRef:
description: |-
TargetRef is the name of the resource this policy is being attached to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ spec:

The client IP is inferred from the X-Forwarded-For header, a custom header,
or the proxy protocol.
You can use the `ClientIPDetection` or the `EnableProxyProtocol` field in
You can use the `ClientIPDetection` or the `ProxyProtocol` field in
the `ClientTrafficPolicy` to configure how the client IP is detected.
items:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ spec:
Client Address into the X-Forwarded-For header.
Note Proxy Protocol must be present when this field is set, else the connection
is closed.

Deprecated: Use ProxyProtocol instead.
type: boolean
headers:
description: HeaderSettings provides configuration for header management.
Expand Down Expand Up @@ -513,6 +515,24 @@ spec:
- UnescapeAndRedirect
type: string
type: object
proxyProtocol:
description: |-
ProxyProtocol configures the Proxy Protocol settings. When configured,
the Proxy Protocol header will be interpreted and the Client Address
will be added into the X-Forwarded-For header.
If both EnableProxyProtocol and ProxyProtocol are set, ProxyProtocol takes precedence.
minProperties: 0
properties:
optional:
description: |-
Optional allows requests without a Proxy Protocol header to be proxied.
If set to true, the listener will accept requests without a Proxy Protocol header.
If set to false, the listener will reject requests without a Proxy Protocol header.
If not set, the default behavior is to reject requests without a Proxy Protocol header.
Warning: Optional breaks conformance with the specification. Only enable if ALL traffic to the listener comes from a trusted source.
For more information on security implications, see haproxy.org/download/2.1/doc/proxy-protocol.txt
type: boolean
type: object
targetRef:
description: |-
TargetRef is the name of the resource this policy is being attached to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ spec:

The client IP is inferred from the X-Forwarded-For header, a custom header,
or the proxy protocol.
You can use the `ClientIPDetection` or the `EnableProxyProtocol` field in
You can use the `ClientIPDetection` or the `ProxyProtocol` field in
the `ClientTrafficPolicy` to configure how the client IP is detected.
items:
description: |-
Expand Down
29 changes: 20 additions & 9 deletions internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,12 @@ func (t *Translator) translateClientTrafficPolicyForListener(policy *egv1a1.Clie

// HTTP and TCP listeners can both be configured by common fields below.
var (
keepalive *ir.TCPKeepalive
connection *ir.ClientConnection
tlsConfig *ir.TLSConfig
enableProxyProtocol bool
timeout *ir.ClientTimeout
err, errs error
keepalive *ir.TCPKeepalive
connection *ir.ClientConnection
tlsConfig *ir.TLSConfig
proxyProtocol *ir.ProxyProtocolSettings
timeout *ir.ClientTimeout
err, errs error
)

// Build common IR shared by HTTP and TCP listeners, return early if some field is invalid.
Expand All @@ -416,7 +416,18 @@ func (t *Translator) translateClientTrafficPolicyForListener(policy *egv1a1.Clie
}

// Translate Proxy Protocol
enableProxyProtocol = ptr.Deref(policy.Spec.EnableProxyProtocol, false)
if policy.Spec.ProxyProtocol != nil {
// ProxyProtocol field takes precedence when configured
// Even if it's an empty object {}, we should enable proxy protocol with default settings
proxyProtocol = &ir.ProxyProtocolSettings{
Optional: ptr.Deref(policy.Spec.ProxyProtocol.Optional, false),
}
} else if ptr.Deref(policy.Spec.EnableProxyProtocol, false) {
// Fallback to legacy EnableProxyProtocol field
proxyProtocol = &ir.ProxyProtocolSettings{
Optional: false, // Default behavior for legacy field
}
}

// Translate Client Timeout Settings
timeout, err = buildClientTimeout(policy.Spec.Timeout)
Expand Down Expand Up @@ -492,7 +503,7 @@ func (t *Translator) translateClientTrafficPolicyForListener(policy *egv1a1.Clie

httpIR.TCPKeepalive = keepalive
httpIR.Connection = connection
httpIR.EnableProxyProtocol = enableProxyProtocol
httpIR.ProxyProtocol = proxyProtocol
httpIR.Timeout = timeout
httpIR.TLS = tlsConfig
}
Expand All @@ -515,7 +526,7 @@ func (t *Translator) translateClientTrafficPolicyForListener(policy *egv1a1.Clie

tcpIR.TCPKeepalive = keepalive
tcpIR.Connection = connection
tcpIR.EnableProxyProtocol = enableProxyProtocol
tcpIR.ProxyProtocol = proxyProtocol
tcpIR.TLS = tlsConfig
tcpIR.Timeout = timeout
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ clientTrafficPolicies:
connectionLimit:
value: 3
closeDelay: 10s
enableProxyProtocol: true
timeout:
tcp:
idleTimeout: 1200s
Expand All @@ -31,6 +30,8 @@ clientTrafficPolicies:
signatureAlgorithms:
- sig1
- sig2
proxyProtocol:
optional: false
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ clientTrafficPolicies:
connectionLimit:
closeDelay: 10s
value: 3
enableProxyProtocol: true
proxyProtocol:
optional: false
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
Expand Down Expand Up @@ -199,9 +200,9 @@ xdsIR:
limit:
closeDelay: 10s
value: 3
enableProxyProtocol: true
name: envoy-gateway/gateway-1/tls-1
port: 10443
proxyProtocol: {}
routes:
- destination:
metadata:
Expand Down Expand Up @@ -270,9 +271,9 @@ xdsIR:
limit:
closeDelay: 10s
value: 3
enableProxyProtocol: true
name: envoy-gateway/gateway-1/tcp-1
port: 8080
proxyProtocol: {}
routes:
- destination:
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
clientTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-gateway-precedence-test
spec:
# Legacy API - should be overridden by new API
enableProxyProtocol: false
# New API - should take precedence
proxyProtocol:
optional: true
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-precedence-test
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-gateway-legacy-only
spec:
# Legacy API only - should work as before
enableProxyProtocol: true
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-legacy-only
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-gateway-new-api-only
spec:
# New API only - no legacy field
proxyProtocol:
optional: false
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-new-api-only
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-precedence-test
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http-1
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Same
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-legacy-only
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: tcp-1
protocol: TCP
port: 9090
allowedRoutes:
namespaces:
from: Same
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-new-api-only
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http-2
protocol: HTTP
port: 8080
allowedRoutes:
namespaces:
from: Same
tcpRoutes:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
namespace: envoy-gateway
name: tcproute-1
spec:
parentRefs:
- name: gateway-legacy-only
rules:
- backendRefs:
- name: tcp-backend
port: 3000
Loading