@@ -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) || size(self.trustedAddresses) == 0))"
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,86 @@ 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
+ // There are two possible modes:
128
+ // - ProxyProtocol: NGINX will rewrite the client's IP using the PROXY protocol header.
129
+ // - XForwardedFor: NGINX will rewrite the client's IP using the X-Forwarded-For header.
130
+ // Sets NGINX directive real_ip_header: https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header
131
+ //
132
+ // +optional
133
+ Mode * RewriteClientIPModeType `json:"mode,omitempty"`
134
+
135
+ // SetIPRecursively configures whether recursive search is used when selecting the client's address from
136
+ // the X-Forwarded-For header. It is used in conjunction with TrustedAddresses.
137
+ // If enabled, NGINX will recurse on the values in X-Forwarded-Header from the end of array
138
+ // to start of array and select the first untrusted IP.
139
+ // For example, if X-Forwarded-For is [11.11.11.11, 22.22.22.22, 55.55.55.1],
140
+ // and TrustedAddresses is set to 55.55.55.1/32, NGINX will rewrite the client IP to 22.22.22.22.
141
+ // If disabled, NGINX will select the IP at the end of the array.
142
+ // In the previous example, 55.55.55.1 would be selected.
143
+ // Sets NGINX directive real_ip_recursive: https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_recursive
144
+ //
145
+ // +optional
146
+ SetIPRecursively * bool `json:"setIPRecursively,omitempty"`
147
+
148
+ // TrustedAddresses specifies the addresses that are trusted to send correct client IP information.
149
+ // If a request comes from a trusted address, NGINX will rewrite the client IP information,
150
+ // and forward it to the backend in the X-Forwarded-For* and X-Real-IP headers.
151
+ // If the request does not come from a trusted address, NGINX will not rewrite the client IP information.
152
+ // TrustedAddresses only supports CIDR blocks: 192.33.21.1/24, fe80::1/64.
153
+ // To trust all addresses (not recommended for production), set to 0.0.0.0/0.
154
+ // If no addresses are provided, NGINX will not rewrite the client IP information.
155
+ // Sets NGINX directive set_real_ip_from: https://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
156
+ // This field is required if mode is set.
157
+ // +kubebuilder:validation:MaxItems=16
158
+ // +listType=map
159
+ // +listMapKey=type
160
+ //
161
+ // +optional
162
+ TrustedAddresses []Address `json:"trustedAddresses,omitempty"`
163
+ }
164
+
165
+ // RewriteClientIPModeType defines how NGINX Gateway Fabric will determine the client's original IP address.
166
+ // +kubebuilder:validation:Enum=ProxyProtocol;XForwardedFor
167
+ type RewriteClientIPModeType string
168
+
169
+ const (
170
+ // RewriteClientIPModeProxyProtocol configures NGINX to accept PROXY protocol and
171
+ // set the client's IP address to the IP address in the PROXY protocol header.
172
+ // Sets the proxy_protocol parameter on the listen directive of all servers and sets real_ip_header
173
+ // to proxy_protocol: https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header.
174
+ RewriteClientIPModeProxyProtocol RewriteClientIPModeType = "ProxyProtocol"
175
+
176
+ // RewriteClientIPModeXForwardedFor configures NGINX to set the client's IP address to the
177
+ // IP address in the X-Forwarded-For HTTP header.
178
+ // https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header.
179
+ RewriteClientIPModeXForwardedFor RewriteClientIPModeType = "XForwardedFor"
180
+ )
181
+
182
+ // Address is a struct that specifies address type and value.
183
+ type Address struct {
184
+ // Type specifies the type of address.
185
+ // Default is "cidr" which specifies that the address is a CIDR block.
186
+ //
187
+ // +optional
188
+ // +kubebuilder:default:=cidr
189
+ Type AddressType `json:"type,omitempty"`
190
+
191
+ // Value specifies the address value.
192
+ //
193
+ // +optional
194
+ Value string `json:"value,omitempty"`
195
+ }
196
+
197
+ // AddressType specifies the type of address.
198
+ // +kubebuilder:validation:Enum=cidr
199
+ type AddressType string
200
+
201
+ const (
202
+ // AddressTypeCIDR specifies that the address is a CIDR block.
203
+ // kubebuilder:validation:Pattern=`^[\.a-zA-Z0-9:]*(\/([0-9]?[0-9]?[0-9]))$`
204
+ AddressTypeCIDR AddressType = "cidr"
205
+ )
0 commit comments