@@ -53,6 +53,12 @@ type NginxProxySpec struct {
53
53
//
54
54
// +optional
55
55
Telemetry * Telemetry `json:"telemetry,omitempty"`
56
+ // RewriteClientIP defines configuration for rewriting the client IP to the original client's IP.
57
+ // +kubebuilder:validation:XValidation:message="if mode is set, trustedAddresses is a required field",rule="!(has(self.mode) && !has(self.trustedAddresses))"
58
+ //
59
+ // +optional
60
+ //nolint:lll
61
+ RewriteClientIP * RewriteClientIP `json:"rewriteClientIP,omitempty"`
56
62
// DisableHTTP2 defines if http2 should be disabled for all servers.
57
63
// Default is false, meaning http2 will be enabled for all servers.
58
64
//
@@ -114,3 +120,56 @@ type TelemetryExporter struct {
114
120
// +kubebuilder:validation:Pattern=`^(?:http?:\/\/)?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*(?::\d{1,5})?$`
115
121
Endpoint string `json:"endpoint"`
116
122
}
123
+
124
+ // RewriteClientIP specifies the configuration for rewriting the client's IP address.
125
+ type RewriteClientIP struct {
126
+ // Mode defines how NGINX will rewrite the client's IP address.
127
+ // Possible modes: ProxyProtocol, XForwardedFor.
128
+ //
129
+ // +optional
130
+ Mode * RewriteClientIPModeType `json:"mode,omitempty"`
131
+
132
+ // SetIPRecursively configures whether recursive search is used for selecting client's
133
+ // address from the X-Forwarded-For header and used in conjunction with TrustedAddresses.
134
+ // If enabled, NGINX will recurse on the values in X-Forwarded-Header from the end of
135
+ // array to start of array and select the first untrusted IP.
136
+ //
137
+ // +optional
138
+ SetIPRecursively * bool `json:"setIPRecursively,omitempty"`
139
+
140
+ // TrustedAddresses specifies the addresses that are trusted to send correct client IP information.
141
+ // If a request comes from a trusted address, NGINX will rewrite the client IP information,
142
+ // and forward it to the backend in the X-Forwarded-For* and X-Real-IP headers.
143
+ // This field is required if mode is set.
144
+ // +kubebuilder:validation:MaxItems=16
145
+ // +listType=atomic
146
+ //
147
+ //
148
+ // +optional
149
+ TrustedAddresses []TrustedAddress `json:"trustedAddresses,omitempty"`
150
+ }
151
+
152
+ // RewriteClientIPModeType defines how NGINX Gateway Fabric will determine the client's original IP address.
153
+ // +kubebuilder:validation:Enum=ProxyProtocol;XForwardedFor
154
+ type RewriteClientIPModeType string
155
+
156
+ const (
157
+ // RewriteClientIPModeProxyProtocol configures NGINX to accept PROXY protocol and,
158
+ // set the client's IP address to the IP address in the PROXY protocol header.
159
+ // Sets the proxy_protocol parameter to the listen directive on all servers, and sets real_ip_header
160
+ // to proxy_protocol: https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header.
161
+ RewriteClientIPModeProxyProtocol RewriteClientIPModeType = "ProxyProtocol"
162
+
163
+ // RewriteClientIPModeXForwardedFor configures NGINX to set the client's IP address to the
164
+ // IP address in the X-Forwarded-For HTTP header.
165
+ // https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header.
166
+ RewriteClientIPModeXForwardedFor RewriteClientIPModeType = "XForwardedFor"
167
+ )
168
+
169
+ // TrustedAddress is a string value representing a CIDR block.
170
+ // Examples: 0.0.0.0/0
171
+ //
172
+ // +kubebuilder:validation:Pattern=`^(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3}(?:\/(?:[0-9]|[12][0-9]|3[0-2]))?|(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}(?:\/(?:[0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?)$`
173
+ //
174
+ //nolint:lll
175
+ type TrustedAddress string
0 commit comments