How to set X-forwarded-For as a real IP while Proxy Protocol is enabled? (Ingress-Nginx)

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information: OVHCloud Managed Kubernetes (v1.26)

Kubernetes version:
Cloud being used: OVHCloud
Installation method: Managed Kubernetes
Host OS: Managed Kubernetes
CNI and version: Managed Kubernetes
CRI and version: Managed Kubernetes

Hi guys. I’m running a Kubernetes cluster on OVHCloud with a Load balancer connected, and proxy protocol enabled. Under normal circumstances, it got no issue reading the client’s IP.

However, some of my services got Cloudflare CDN integration. So the client’s IP will be only passed with the X-Forwarded-For header, not through the typical remote_addr.

Is there a way that I can set the Ingress-Nginx to read the X-Forwarded-For data as a real_ip, and set proxy_protocol address as a real_ip if the XFF value doesn’t exist?

I tried to set enable-real-ip to true on the Ingress configmap, but this was not effective while the use-proxy-protocol is enabled.

Setting real_ip_header X-Forwarded-For; through the server-snippet was not helpful either. It made the server read the XFF value as a real_ip, but if the XFF header is missing, it got the LB’s local IP as a real_ip (not getting the data from the proxy protocol).

I’m kinda stuck right now. Can someone help me to figure out the way here?

Thanks a ton.