Harden against bot floods and add post-provisioning service check
- Traefik rate-limits all routes (60 req/min standard, 300 for Nextcloud) and writes access logs to /var/log/traefik/access.log - Fail2ban watches Traefik access logs and bans IPs after 10 x 403/404 within 60 s for 24 h - Nextcloud html directory created as www-data (UID 33) so Apache can process .htaccess and serve requests correctly - scripts/check-services.sh verifies all seven endpoints return the expected HTTP status after provisioning
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
[Definition]
|
||||
# Matches Traefik CLF access log lines where the response status is 403 or 404.
|
||||
# Banning on these two codes catches vulnerability scanners (403) and path probers (404)
|
||||
# without touching legitimate 401 auth challenges or 429 rate-limit responses.
|
||||
failregex = ^<HOST> \S+ \S+ \[.*?\] ".*?" (?:403|404) .*$
|
||||
ignoreregex =
|
||||
@@ -0,0 +1,8 @@
|
||||
[traefik]
|
||||
enabled = true
|
||||
port = http,https
|
||||
filter = traefik
|
||||
logpath = /var/log/traefik/access.log
|
||||
maxretry = 10
|
||||
findtime = 60
|
||||
bantime = 86400
|
||||
@@ -3,3 +3,8 @@
|
||||
ansible.builtin.service:
|
||||
name: ssh
|
||||
state: restarted
|
||||
|
||||
- name: Restart fail2ban
|
||||
ansible.builtin.service:
|
||||
name: fail2ban
|
||||
state: restarted
|
||||
|
||||
@@ -126,6 +126,26 @@
|
||||
|
||||
# --- Fail2ban ---
|
||||
|
||||
- name: Deploy fail2ban filter for Traefik
|
||||
ansible.builtin.copy:
|
||||
src: filter.d/traefik.conf
|
||||
dest: /etc/fail2ban/filter.d/traefik.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Restart fail2ban
|
||||
tags: base
|
||||
|
||||
- name: Deploy fail2ban jail for Traefik
|
||||
ansible.builtin.copy:
|
||||
src: jail.d/traefik.conf
|
||||
dest: /etc/fail2ban/jail.d/traefik.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Restart fail2ban
|
||||
tags: base
|
||||
|
||||
- name: Enable and start fail2ban
|
||||
ansible.builtin.service:
|
||||
name: fail2ban
|
||||
|
||||
Reference in New Issue
Block a user