Skip to content

Commit cb547d6

Browse files
authored
Add docs for rewrite client IP settings (#2701)
Add docs for rewrite client IP settings Problem: User needs documentation explaining how to configure rewrite client IP settings. Solution: Adds documentation on how to configure rewrite client IP settings
1 parent 88661c1 commit cb547d6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

site/content/how-to/data-plane-configuration.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,45 @@ as arguments and add `/bin/sh` as the command. The deployment manifest should lo
157157
- /bin/sh
158158
...
159159
```
160+
161+
## Configure PROXY protocol and RewriteClientIP settings
162+
163+
When the request is passed through multiple proxies or load balancers, the client IP is set to the IP address of the server that last handled the request. To preserve the original client IP address, you can configure `RewriteClientIP` settings in the `NginxProxy` resource. `RewriteClientIP` has the fields: _mode_, _trustedAddresses_ and _setIPRecursively_.
164+
165+
**Mode** determines how the original client IP is passed through multiple proxies and the way the load balancer is set to receive it. It can have two values:
166+
167+
1. `ProxyProtocol` is a protocol that carries connection information from the source requesting the connection to the destination for which the connection was requested.
168+
2. `XForwardedFor` is a multi-value HTTP header that is used by proxies to append IP addresses of the hosts that passed the request.
169+
170+
The choice of mode depends on how the load balancer fronting NGINX Gateway Fabric receives information.
171+
172+
**TrustedAddresses** are used to specify the IP addresses of the trusted proxies that pass the request. These can be in the form of CIDRs, IPs, or hostnames. For example, if a load balancer is forwarding the request to NGINX Gateway Fabric, the IP address of the load balancer should be specified in the `trustedAddresses` list to inform NGINX that the forwarded request is from a known source.
173+
174+
**SetIPRecursively** is a boolean field used to enable recursive search when selecting the client's address from a multi-value header. It is applicable in cases where we have a multi-value header containing client IPs to select from, i.e., when using `XForwardedFor` mode.
175+
176+
The following command creates an `NginxProxy` resource with `RewriteClientIP` settings that set the mode to XForwardedFor, enables recursive search for finding the client IP and sets a CIDR, IPAddress and Hostname in the list of trusted addresses to find the original client IP address.
177+
178+
```yaml
179+
kubectl apply -f - <<EOF
180+
apiVersion: gateway.nginx.org/v1alpha1
181+
kind: NginxProxy
182+
metadata:
183+
name: ngf-proxy-config
184+
spec:
185+
config:
186+
rewriteClientIP:
187+
mode: XForwardedFor
188+
setIPRecursively: true
189+
trustedAddresses:
190+
- type: CIDR
191+
value: ":1/28"
192+
- type: IPAddress
193+
value: "192.68.74.28"
194+
- type: Hostname
195+
value: "cafe.com"
196+
EOF
197+
```
198+
199+
For more information, see the `NginxProxy spec` in the [API reference]({{< relref "reference/api.md" >}}).
200+
201+
{{< note >}} When sending curl requests to a server expecting proxy information, use the flag `--harproxy-protocol` to avoid broken header errors. {{< /note >}}

0 commit comments

Comments
 (0)