Skip to content

Instantly share code, notes, and snippets.

@diyfr
Last active May 29, 2024 07:18
Show Gist options
  • Save diyfr/924471098b19b39b301e76b8b03e41cb to your computer and use it in GitHub Desktop.
Save diyfr/924471098b19b39b301e76b8b03e41cb to your computer and use it in GitHub Desktop.
Fail2ban && Traefik
[Definition]
actionstart = iptables -N f2b-traefik-auth
iptables -A f2b-traefik-auth -j RETURN
iptables -I FORWARD -p tcp -m multiport --dports 443 -j f2b-traefik-auth
actionstop = iptables -D FORWARD -p tcp -m multiport --dports 443 -j f2b-traefik-auth
iptables -F f2b-traefik-auth
iptables -X f2b-traefik-auth
actioncheck = iptables -n -L FORWARD | grep -q 'f2b-traefik-auth[ \t]'
actionban = iptables -I f2b-traefik-auth -s <ip> -j DROP
actionunban = iptables -D f2b-traefik-auth -s <ip> -j DROP
[Definition]
failregex=^{"ClientAddr":"<HOST>:.*".*"OriginStatus":401.+$
ignoreregex=
[Definition]
failregex=^{"ClientAddr":"<HOST>:.*".*"OriginStatus":404.+$
ignoreregex=
[traefik-auth]
enabled = true
bantime = 30m
findtime = 5m
maxretry = 5
banaction = docker-action
logpath = /home/docker/vol/traefik/logs/access.log
port = http,https
[traefik-scan]
enabled = true
bantime = 10m
findtime = 1m
maxretry = 10
banaction = docker-action
logpath = /home/docker/vol/traefik/logs/access.log
port = http,https
accessLog:
filePath: /var/log/traefik/access.log
format: json
fields:
defaultMode: drop
names:
StartUTC: keep
Duration: keep
OriginStatus: keep
RequestMethod: keep
# The remote address in its original form (usually IP:port).
ClientAddr: keep
RouterName: keep
headers:
defaultMode: drop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment