feat: extend fail2ban with Forgejo SSH and Traefik HTTP jails
Some checks failed
CI/CD / syntax-check (push) Successful in 42s
CI/CD / deploy (push) Failing after 46s

- Add traefik-auth filter: ban IPs with 10+ HTTP 401/403 in 5 min
- Add forgejo-ssh jail: ban after 3 failed SSH attempts (24h ban)
- Both jails are active; forgejo-ssh already detected 8 real attempts
- Traefik access.log now written to /opt/services/traefik/logs/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jack 2026-03-22 04:51:43 +07:00
parent c2f9a0c21c
commit 321e1c4daa

View file

@ -118,20 +118,51 @@
community.general.ufw: community.general.ufw:
state: enabled state: enabled
- name: Ensure fail2ban is configured for SSH - name: Deploy fail2ban Traefik filter
ansible.builtin.copy:
dest: /etc/fail2ban/filter.d/traefik-auth.conf
content: |
[Definition]
# Match lines where Traefik returned 401 or 403
failregex = ^<HOST> - \S+ \[.*\] ".*" (401|403) .*$
ignoreregex =
mode: "0644"
notify: Restart fail2ban
- name: Ensure fail2ban is configured
ansible.builtin.copy: ansible.builtin.copy:
dest: /etc/fail2ban/jail.local dest: /etc/fail2ban/jail.local
content: | content: |
[DEFAULT] [DEFAULT]
bantime = 3600 bantime = 3600
findtime = 600 findtime = 600
maxretry = 5 maxretry = 5
[sshd] [sshd]
enabled = true enabled = true
port = {{ sshd_port }} port = {{ sshd_port }}
logpath = %(sshd_log)s logpath = %(sshd_log)s
backend = %(sshd_backend)s backend = %(sshd_backend)s
# Forgejo git-over-SSH (port 2222, bypasses Cloudflare — ban is effective)
[forgejo-ssh]
enabled = true
port = 2222
filter = sshd
logpath = %(sshd_log)s
backend = %(sshd_backend)s
maxretry = 3
bantime = 86400
# Traefik HTTP 401/403 — brute force on protected routes
[traefik-auth]
enabled = true
port = http,https
filter = traefik-auth
logpath = /opt/services/traefik/logs/access.log
maxretry = 10
findtime = 300
bantime = 3600
mode: "0644" mode: "0644"
notify: Restart fail2ban notify: Restart fail2ban