Preserving the Client IP
An Ingress or Gateway edge proxy forwards requests to the app from its own address. Where is the client address lost, how can it still arrive, and how far can the app trust a header like X-Forwarded-For?
Play the animation 5 steps, animated, plays on a computer or a tablet
Preserving the Client IP, step by step
-
The client opens the connection to the edge, an Ingress or Gateway proxy Pod. Its packets carry the real source address, 198.51.100.9, and they arrive unchanged only because nothing on the way rewrote them.
Play from step 1 -
The edge does not forward those packets. It ends that connection and opens a new one of its own to the backend, so what the app receives is sourced from the proxy Pod, 10.244.0.9. The two src rows show it: read from the socket, the client address is gone.
Play from step 2 -
So the edge writes the address into the request instead. Before proxying it adds X-Forwarded-For carrying the client address. The standardized form, the RFC 7239 Forwarded header, writes it as for=198.51.100.9. The socket still reads 10.244.0.9, and the app reads the header.
Play from step 3 -
A header is only data, and the client can send an X-Forwarded-For of its own claiming any address. An edge that keeps what arrived appends what it saw, so the row becomes a list with the forged value first and the address your own edge saw last. Trust that list from its last entry inwards.
Play from step 4 -
Raw TCP and passed-through TLS have no header to write into. The PROXY protocol prepends a short preamble to the first bytes of the stream, carrying the original source address, and the backend must be configured to expect it or it reads the preamble as request bytes.
Play from step 5