Is it possible to Log the real IP from Cloudflare as per the below docs?
@jnovack Thank you for your response. But is it possible in Traefik to rate limit based on CF-Connecting-IP?
This should give you a good idea what is and is not possible with regards to rate limiting in traefik. Traefik does not have special integration with CloudFlare for the purpose of rate limiting.
How can I now configure Traefik to pass the visitor's original IP so I can filter them based on their IP via iptables? Like month ago my iptables filtration worked, now it does not.. I suspect that Cloudflare is now no longer "handling" visitors original IP as before.. but it has to put his original IP somewhere and Traefik should have a config flag to restore it.
So my config scenario is as follows:
INTERNET -> Cloudflare (DNS-Proxy) -> MY_FIREWALL -> Traefik -> Server (filters e.g. whole Russia based on the source IP) -> Docker Container
^^^This worked before (month ago).. However now my server sees only Cloudflare IP and thus iptables overcoming iptables rule..
Appreciate any input here, Thanks.
In order to proceed with any filters based on Source IP address, the first step is to correctly configure forwarded headers EntryPoints - Traefik.
Depending on your setup additional changes might be required especially for the Kubernetes Load Balancer service type to preserve real Ip addresses (externalTrafficPolicy)
Once you have the real IP address you can consider configuring rate limiter or any other middlewares that relies on the source IP address.
We should provide a full-fledged tutorial to present how to achieve it because it is a recurring question.
Thank you, Jakub
Firstly thank you for taking time here. Now let me first be more specific with the actual scenario:
- WHITELIST ipset contains the Cloudflare's IPs.
- BLACKLIST ipset contains other IP sets such as different countries or spam groups (this is periodically updated in the background).
I have configured this where I am trusting Cloudflare's IPs:
forwardedHeaders: trustedIPs: - 22.214.171.124/20 - 126.96.36.199/22 - 188.8.131.52/22 - 184.108.40.206/22 - 220.127.116.11/18 - 18.104.22.168/18 - 22.214.171.124/20 - 126.96.36.199/20 - 188.8.131.52/22 - 184.108.40.206/17 - 220.127.116.11/15 - 18.104.22.168/13 - 22.214.171.124/14 - 126.96.36.199/13 - 188.8.131.52/22
The server still sees the Cloudlfare
Y.Y.Y.Y IP address and passes it to the Traefik. Now you say that it is possible to filter those request based on the
X-Forwarded-For: X.X.X.X - well sure for couple of IPs but not for the whole region.. Here it would be ideal and much desired if Traefik could make use of systems IP sets or be able to implement them itself (or import them from system at start?).
Some time ago I created a feature request for this very scenario and no one cared to even reply . With this capability we now have power to effectively filter this per service.
In regards to IPSETS I would use ForwardAuth middleware. I would forward the request to the authentication backend. The backend's responsibility would be to make a decision whether the source IP is whitelisted or blacklisted.
Traefik can use the response from the backend to technically accept the incoming connection or block it based on the HTTP responses coming from the backend.
However, you need to correctly get the source IP address of the client.
Regarding your feature request, I encourage you to open the issue on the Traefik Github repository and describe the request you wish to have in the next releases.