Feature request: Prefer an end-user configured IP header when available (crowdsec_manager #137)

:octopus: GitHub issue crowdsec_manager #137, opened by iconoclasthero on GitHub

For a given Traefik log entry, e.g.:

{
  "ClientAddr": "104.22.105.6:10884",
  "ClientHost": "104.22.105.6",
  "DownstreamContentSize": 0,
  "DownstreamStatus": 0,
  "Duration": 173108453463,
  "OriginContentSize": 0,
  "OriginDuration": 171130088445,
  "OriginStatus": 0,
  "Overhead": 1978365018,
  "RequestMethod": "GET",
  ⋮
  "level": "info",
  "msg": "",
  "origin_Content-Type": "",
  "request_Cf-Connecting-Ip": "2607:fb90:6272:c2f0:d4c6:76ff:fed1:bb7b",
  "request_Cf-Ipcountry": "US",
  "request_Cookie": "REDACTED",
  "request_User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Mobile Safari/537.36",
  "request_X-Forwarded-For": "2607:fb90:6272:c2f0:d4c6:76ff:fed1:bb7b",
  "request_X-Forwarded-Host": [REDACTED],
  "request_X-Forwarded-Proto": "https",
  "request_X-Real-Ip": "2607:fb90:6272:c2f0:d4c6:76ff:fed1:bb7b",
  "time": "2026-09-18T09:57:46-04:00"
}

When request_Cf-Connecting-Ip is available, it would be useful to optionally use that as the IP for hit/source tallying instead of ClientAddr / ClientHost.

In this example, ClientHost is the Cloudflare proxy (104.22.105.6), while request_Cf-Connecting-Ip contains the actual client IP. For purposes such as counting hits by source IP, using ClientHost would therefore aggregate all Cloudflare traffic together rather than representing the actual visitors.

More generally, though, it would probably be ideal if the **“end-user IP header field” …


:speech_balloon: Discuss it here. Status, fixes and code review stay on GitHub.

iconoclasthero commented on GitHub:

This is relevant more for Traefik logs than for the Crowdsec ones as parsing/enrichment rules can basically obviate the need to use e.g., request_Cf-Connecting-IP downstream.

iconoclasthero commented on GitHub:

I went ahead and implemented this locally.

The basic change is an environmental variable IP_SOURCE_HEADER. It lets me tell CrowdSec Manager which Traefik JSON field should be treated as the client IP, rather than always using ClientHost.

For example, with Cloudflare proxies in front of Traefik I can set:

IP_SOURCE_HEADER=request_Cf-Connecting-Ip

and the Manager now uses that value for the client-IP handling, including the dashboard aggregation and the CLIENT IP column in Live Traffic Logs. It still falls back through the existing ClientHost → ClientAddr → ClientIP → IP → RemoteAddr chain when the option isn’t configured or when the connection is unproxied.

I deliberately made it generic rather than Cloudflare-specific, since the same situation can come up with Fastly, Akamai, nginx, HAProxy, Envoy, etc., where the original client address may be carried in a proxy-specific or X-Forwarded-* header.

I also left the default as unset, so existing installations retain the current behavior.

I’ve tested the change against my actual Traefik/Cloudflare setup, including the slightly fun part where the actual client address is IPv6 even though the remote host itself is IPv4-only, and both go test ./... and docker build are clean.

So, as far as I’m concerned, the FR is implemented and working.

I’m not going to spend the time forking the repo and submitting a PR until I know there’s actually interest in merging it. If/when you get back to this and want the change upstreamed, I have the working implementation here and can turn it into a proper PR.