Logging CF-Connecting-IP in HAProxy from Cloudflare

I’ve read a lot of posts and docs about this… I’m still unable to get the CF-Connecting-IP in my haproxy access logs.

#       Cloudflare origin IP
        acl from_cf src -f /etc/haproxy/cf-ips/CF_ips.lst
        acl cf_ip_hdr  req.hdr(CF-Connecting-IP) -m found
        http-request set-header X-Forwarded-For %[req.hdr(CF-Connecting-IP)] if from_cf cf_ip_hdr

I am using the above on the frontend to get the CF-Connecting-IP - but my haproxy access logs still show all CF IPs instead of origin IPs. Is that expected?

haproxy.cfg

haproxy -vv

Thanks in advance!

Setting the IP address in the X-Forwarded-For does just that. Use http-request set-src to set the src-ip at lower levels.

In versions older than 2.5, workarounds will are required:

1 Like

Thank you for the pointer. I have added this to get Cloudflare IPs working correctly in haproxy 2.4 on Ubuntu 22:

#       Cloudflare origin IP
        acl from_cf src -f /etc/haproxy/cf-ips/CF_ips.lst
        acl cf_ip_hdr  req.hdr(CF-Connecting-IP) -m found
        http-request set-header X-Forwarded-For %[req.hdr(CF-Connecting-IP)] if from_cf cf_ip_hdr
        http-request set-src hdr(x-forwarded-for) if from_cf
        http-request set-var(sess.cloudflare) always_true if { http_first_req } from_cf

Looks like haproxy 2.5 isn’t available as LTS until Q1 2023.

No, 2.5 is EOL in Q1 2023 it will never be an LTS.

Just use 2.6 which is LTS and supported until Q2 2027.

This is an incomplete configuration and will trigger the bug I linked above.

Use the complete workaround so that you don’t hit any bugs: