Add Fail2ban to Gitea and Bitwarden
This commit is contained in:
parent
eccd6b7874
commit
b52ccabd22
@ -10,3 +10,9 @@
|
||||
name: wg-quick@wg0
|
||||
state: restarted
|
||||
listen: restart_wireguard
|
||||
|
||||
- name: Restart Fail2ban
|
||||
service:
|
||||
name: fail2ban
|
||||
state: restarted
|
||||
listen: restart_fail2ban
|
||||
|
@ -3,6 +3,11 @@
|
||||
name: ufw
|
||||
state: present
|
||||
|
||||
- name: Install Fail2ban
|
||||
apt:
|
||||
name: fail2ban
|
||||
state: present
|
||||
|
||||
- name: Deny incoming traffic by default
|
||||
ufw:
|
||||
default: deny
|
||||
|
@ -78,6 +78,12 @@
|
||||
register: bitwarden_systemd
|
||||
notify: rebuild_bitwarden
|
||||
|
||||
- name: Install Bitwarden's Fail2ban jail
|
||||
template:
|
||||
src: fail2ban-jail.conf.j2
|
||||
dest: /etc/fail2ban/jail.d/bitwarden.conf
|
||||
notify: restart_fail2ban
|
||||
|
||||
- name: Reload systemd manager configuration
|
||||
systemd:
|
||||
daemon_reload: true
|
||||
|
9
roles/bitwarden/templates/fail2ban-jail.conf.j2
Normal file
9
roles/bitwarden/templates/fail2ban-jail.conf.j2
Normal file
@ -0,0 +1,9 @@
|
||||
# {{ ansible_managed }}
|
||||
[bitwarden]
|
||||
enabled = true
|
||||
filter = bitwarden
|
||||
logpath = /var/lib/bitwarden/bwdata/logs/identity/Identity/*
|
||||
maxretry = 10
|
||||
findtime = 3600
|
||||
bantime = 900
|
||||
action = iptables-allports
|
@ -81,6 +81,18 @@
|
||||
dest: "{{ gitea_root }}/.env"
|
||||
notify: restart_gitea
|
||||
|
||||
- name: Install Gitea's Fail2ban filter
|
||||
template:
|
||||
src: fail2ban-filter.conf.j2
|
||||
dest: /etc/fail2ban/filter.d/gitea.conf
|
||||
notify: restart_fail2ban
|
||||
|
||||
- name: Install Gitea's Fail2ban jail
|
||||
template:
|
||||
src: fail2ban-jail.conf.j2
|
||||
dest: /etc/fail2ban/jail.d/gitea.conf
|
||||
notify: restart_fail2ban
|
||||
|
||||
- name: Start and enable Gitea service
|
||||
service:
|
||||
name: "{{ docker_compose_service }}@{{ gitea_name }}"
|
||||
|
@ -12,6 +12,7 @@ services:
|
||||
environment:
|
||||
- USER_UID={{ getent_passwd.git[1] }}
|
||||
- USER_GID={{ getent_group.git[1] }}
|
||||
- GITEA__log__MODE=file
|
||||
- GITEA__server__ROOT_URL=${gitea_rooturl}
|
||||
- GITEA__server__DOMAIN=${gitea_domain}
|
||||
- GITEA__server__SSH_DOMAIN=${gitea_domain}
|
||||
@ -25,7 +26,8 @@ services:
|
||||
- GITEA__service__DISABLE_REGISTRATION=${gitea_disable_registration}
|
||||
volumes:
|
||||
- {{ gitea_volume }}:/data
|
||||
- /home/git/.ssh/:/data/git/.ssh
|
||||
- /home/git/.ssh:/data/git/.ssh
|
||||
- /var/log/gitea:/data/gitea/log
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
|
||||
|
4
roles/gitea/templates/fail2ban-filter.conf.j2
Normal file
4
roles/gitea/templates/fail2ban-filter.conf.j2
Normal file
@ -0,0 +1,4 @@
|
||||
# {{ ansible_managed }}
|
||||
[Definition]
|
||||
failregex = .*(Failed authentication attempt|invalid credentials|Attempted access of unknown user).* from <HOST>
|
||||
ignoreregex =
|
18
roles/gitea/templates/fail2ban-jail.conf.j2
Normal file
18
roles/gitea/templates/fail2ban-jail.conf.j2
Normal file
@ -0,0 +1,18 @@
|
||||
# {{ ansible_managed }}
|
||||
[gitea]
|
||||
enabled = true
|
||||
filter = gitea
|
||||
logpath = /var/log/gitea/gitea.log
|
||||
maxretry = 10
|
||||
findtime = 3600
|
||||
bantime = 900
|
||||
action = iptables-allports
|
||||
|
||||
[gitea-docker]
|
||||
enabled = true
|
||||
filter = gitea
|
||||
logpath = /var/log/gitea/gitea.log
|
||||
maxretry = 10
|
||||
findtime = 3600
|
||||
bantime = 900
|
||||
action = iptables-allports[chain="FORWARD"]
|
Loading…
Reference in New Issue
Block a user