infra is the following
visitor --> Cloudflare proxy --> Front --> Back
^^^^^^
-->iptables(fail2ban)-->nginx-->
What I want to do is track a bruteforcing IP via 401 rejects and ban this IP to make any subsequent request.
FE BE
| |
.. | |
| POST /oauth/token |
|-------------------->|
| 401 (access denied) |
|<--------------------|
.. | |
| |
However, the only incoming address on FE is the cloudflare's IP and not the visitor's IP. Thus I can't ban the incoming IP via iptable.
I only see two ways:
- Configure nginx to use the X-Forwarded-For (or CF-Connecting-IP addionnally given by cloudflare), coupled with the evaluation of 401 response plus a limit_req (is this feasible? How?)
- Instead of jailing the detected bruteforcingIP via fail2ban, map it to a banned ip (e.g 140.1.1.1 or whatever IP in africa) and reject the http traffic via a Deny directive on nginx.
Are one of the latters feasible? If no, any alternative?