I'm interested in setting up fail2ban with my Traefik deployment. I found a gist that has some snippets in it, but I'm not clear on how to use them. Can anyone fill in the blanks please? Or, is there a better way to implement fail2ban style security with Traefik?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
I was able to accomplish this starting with the gist you posted. This is under the assumptions you have Traefik already working, want to block IPs that have HTTP Basic Auth failures, and ban them with iptables. There's a couple of pieces so let me start with the container configurations:
Traefik docker-compose.yaml
You can see here I am writing the log file to
/var/log/access.log
and only getting access codes to400-499
. I am then mounting that file to my host/var/log/traefik:/var/log
Now for the fail2ban part, I am using a fail2ban docker container rather than installing on my host, but you could technically do it there too.
Fail2ban docker-compose.yaml
You can see I mount the
/var/log
directory into the fail2ban container as read only.Fail2ban configuration
The
/apps/docker/fail2ban/data/jail.d/traefik.conf
file contains:The
/apps/docker/fail2ban/data/filter.d/traefik-auth.conf
file contains:Extra
The default ban action is to ban via iptables. If you want to change that you can change the default
banaction
in thetraefik.conf
, for example:Actions are here: https://github.com/fail2ban/fail2ban/tree/0.11/config/action.d
If you need to modify one, copy the file to the
/apps/docker/fail2ban/data/action.d
directory and restart the container.