-
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.
- Loading branch information
Showing
7 changed files
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Restart fail2ban.service | ||
ansible.builtin.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,35 @@ | ||
--- | ||
- name: Install fail2ban | ||
ansible.builtin.package: | ||
name: fail2ban | ||
state: present | ||
|
||
- name: Render fail2ban configuration files | ||
ansible.builtin.template: | ||
src: "{{ item }}" | ||
dest: /etc/fail2ban/{{ item }} | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
loop: | ||
- fail2ban.local | ||
- jail.local | ||
register: config_changed | ||
notify: Restart fail2ban.service | ||
|
||
- name: Render fail2ban jail drop-ins | ||
ansible.builtin.template: | ||
src: "{{ item }}" | ||
dest: /etc/fail2ban/jail.d/{{ item | basename }} | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
with_fileglob: | ||
- templates/jail.d/* | ||
notify: Restart fail2ban.service | ||
|
||
- name: Enable and start fail2ban | ||
ansible.builtin.systemd: | ||
name: fail2ban | ||
enabled: yes | ||
state: started |
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,5 @@ | ||
[Definition] | ||
|
||
# Setting this here to prevent fail2ban from warning that this is unset every | ||
# time it starts up. | ||
allowipv6 = auto |
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,10 @@ | ||
[sshd] | ||
enabled = true | ||
|
||
# Flag public key mismatches. This can cause false positives: A legitimate user | ||
# could have >5 private keys, in which case SSH will try each sequentially until | ||
# one works, triggering a ban. | ||
filter = sshd[publickey='any'] | ||
|
||
# Also ban access to our custom port | ||
port = 22,50519 |
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,21 @@ | ||
[DEFAULT] | ||
|
||
# Use systemd-journal to find logs. | ||
backend = systemd | ||
|
||
# Ban hosts for 5 minutes on first fail. | ||
bantime = 5m | ||
|
||
# Randomly add up to 2 minutes to the ban time to prevent bots from timing | ||
# their attacks. | ||
bantime.rndtime = 120 | ||
|
||
# Increase ban time for each subsequent fail. | ||
bantime.increment = true | ||
|
||
# Formula for calculating ban time. | ||
# This one doubles the ban time for each subsequent fail. | ||
bantime.formula = ban.Time * (1 << ban.Count) | ||
|
||
# Don't use hostnames for banning, but log as info. | ||
usedns = no |