forked from notthebee/infra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fail2ban, modify Vaultwarden and SWAG config files
- Loading branch information
Showing
11 changed files
with
106 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Definition] | ||
_groupsre = (?:(?:,?\s*"\w+":(?:"[^"]+"|\w+))*) | ||
failregex = ^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Login failed: | ||
^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Trusted domain error. | ||
^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Wrong username or password. | ||
|
||
datepattern = ,?\s*"time"\s*:\s*"%%Y-%%m-%%d[T ]%%H:%%M:%%S(%%z)?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[Definition] | ||
failregex = ^.*Invalid admin token\. IP: <ADDR>.*$ | ||
ignoreregex = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[Definition] | ||
failregex = ^.*Username or password is incorrect\. Try again\. IP: <ADDR>\. Username:.*$ | ||
ignoreregex = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
- name: Install fail2ban | ||
package: | ||
name: fail2ban | ||
state: latest | ||
|
||
- name: Make sure the fail2ban systemd service is enabled and started | ||
service: | ||
name: fail2ban | ||
state: started | ||
enabled: yes | ||
|
||
- name: Copy custom fail2ban rules | ||
copy: | ||
src: "{{ item }}" | ||
dest: "/etc/fail2ban/filter.d" | ||
owner: "{{ username }}" | ||
group: "{{ username }}" | ||
with_fileglob: | ||
- "files/filter.d/*.conf" | ||
register: copied_rules | ||
|
||
- name: Create a list of rule files that were deployed | ||
set_fact: | ||
installed_configs: "{{ installed_configs | default([]) + [ item.dest.split('/')[-1].split('.')[0] ] }}" | ||
with_items: "{{ copied_rules.results }}" | ||
|
||
- name: Install the jail.local file | ||
template: | ||
src: "jail.local.j2" | ||
dest: "/etc/fail2ban/jail.local" | ||
|
||
- name: Install the paths-overrides.local file | ||
template: | ||
src: "paths-overrides.local.j2" | ||
dest: "/etc/fail2ban/paths-overrides.local" | ||
|
||
|
||
- name: Put the cloudflare token into the configuration file | ||
lineinfile: | ||
regex: "^cftoken =" | ||
line: "cftoken = {{ cloudflare_firewall_token }}" | ||
path: "/etc/fail2ban/action.d/cloudflare.conf" | ||
|
||
- name: Put the cloudflare email into the configuration file | ||
lineinfile: | ||
regex: "^cfuser =" | ||
line: "cfuser = {{ email }}" | ||
path: "/etc/fail2ban/action.d/cloudflare.conf" | ||
|
||
- name: Restart fail2ban | ||
service: | ||
name: fail2ban | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cftoken = {{ cloudflare_firewall_token }} | ||
cfuser = {{ email }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[DEFAULT] | ||
banaction = cloudflare | ||
complain | ||
iptables-allports | ||
bantime = -1 | ||
findtime = 600 | ||
maxretry = 3 | ||
ignoreip = 127.0.0.1/8 ::1 {{ ansible_default_ipv4.address }}/24 | ||
action = %(action_mwl)s | ||
destemail = {{ email }} | ||
sender = {{ email }} | ||
|
||
[sshd] | ||
enabled = true | ||
port = {{ security_ssh_port }} | ||
filter = sshd | ||
|
||
{% for name in installed_configs %} | ||
[{{ name }}] | ||
enabled = true | ||
port = http,https | ||
filter = {{ name }} | ||
logpath = %({{ name }}_log)s | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[DEFAULT] | ||
nextcloud_log = {{ docker_dir }}/nextcloud/data/nextcloud.log | ||
vaultwarden_log = {{ docker_dir }}/vaultwarden/vaultwarden.log | ||
vaultwarden-admin_log = {{ docker_dir }}/vaultwarden/vaultwarden.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,10 @@ | |
tags: | ||
- essential | ||
|
||
- role: fail2ban | ||
tags: | ||
- fail2ban | ||
|
||
- role: filesystems/mergerfs | ||
tags: | ||
- mergerfs | ||
|