Integrating fail2ban with Cloudflare API v4 instead of default v1

So I found a very useful blog post that explains how to switch your fail2ban from using the Cloudflare v1 API to using the Cloudflare v4 API. The Cloudflare v4 API is so much faster than the v1 API. Getting the config posted in here without it becoming a formatting diaster is too hard so I’m just going to let you read the blog post I linked earlier. Tell me what you think about it. It’s pretty awesome how Cloudflare has improved their API in v4 and now all of you can experience the benefits with ease :smiley:

3 Likes

Thanks for that i used the fail2ban default Cloudflare action which is a bit dated so this makes it easier

edit:

tried modifying the action ban to add the filter name <name> to notes section but doesn’t seem to work. If anyone has any ideas here’s what I tried fail2ban cloudflare v4 API actionban trying to pass the filter name to notes · GitHub

for now seems to be work okay without passing filter name to Cloudflare firewall’s notes GitHub - centminmod/centminmod-fail2ban: fail2ban setup for centminmod.com LEMP stack with CSF Firewall in that it shows up in Cloudflare firewall access rules for blocking server IP = 149.xxx.xxx.xxx

curl -I http://domain.com/wp-login.php 
HTTP/1.1 403 Forbidden
Date: Sat, 13 May 2017 05:22:01 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Set-Cookie: __cfduid=d34a309e3527a91971491fc853424dbca1494652921; expires=Sun, 13-May-18 05:22:01 GMT; path=/; domain=.domain.com; HttpOnly
Cache-Control: max-age=15
Expires: Sat, 13 May 2017 05:22:16 GMT
X-Frame-Options: SAMEORIGIN
Server: Cloudflare-nginx
CF-RAY: 35e32d7813e63f95-YUL

149.xxx.xxx.xxx is blocked ip listing

Glad to see you’re enjoying it. The v4 API is so much faster :smiley:

1 Like

thanks working very well with my fail2ban implementation