diff --git a/handlers/main.yml b/handlers/main.yml index ed38948..714136b 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -27,3 +27,8 @@ service: name: nginx state: reloaded + +- name: restart fail2ban + service: + name: fail2ban + state: restarted diff --git a/host_vars/akatosh.yml b/host_vars/akatosh.yml index 87269cb..573a0fe 100644 --- a/host_vars/akatosh.yml +++ b/host_vars/akatosh.yml @@ -30,6 +30,9 @@ cloud_nginx_sites: port: 8087 max_body: 2g # song uploads +fail2ban_ignoreip: + - home.hoekveen.net + stroopwafel_dir: /opt/stroopwafel stroopwafel_repo: gitea@git.hoekveen.net:mark/stroopwafel.git stroopwafel_version: master diff --git a/playbook.yml b/playbook.yml index cc11d7e..4bff292 100644 --- a/playbook.yml +++ b/playbook.yml @@ -118,10 +118,17 @@ mode: "0775" loop: [nextcloud, hdwiki, gitea, authentik, drone, "hoekveen.net"] - import_tasks: tasks/nextcloud.yml + tags: nextcloud - import_tasks: tasks/hdwiki.yml + tags: hdwiki - import_tasks: tasks/gitea.yml + tags: gitea - import_tasks: tasks/nightingale.yml + tags: nightingale - import_tasks: tasks/stroopwafel.yml + tags: stroopwafel + - import_tasks: tasks/fail2ban.yml + tags: fail2ban - import_tasks: tasks/cloud_nginx.yml - name: Ensure the backup user can run the forced-command pull user: diff --git a/tasks/fail2ban.yml b/tasks/fail2ban.yml new file mode 100644 index 0000000..33ed561 --- /dev/null +++ b/tasks/fail2ban.yml @@ -0,0 +1,17 @@ +- name: Install fail2ban + apt: + name: [fail2ban, python3-systemd] + state: present +- name: Configure sshd jail + template: + src: fail2ban/sshd.local.j2 + dest: /etc/fail2ban/jail.d/sshd.local + owner: root + group: root + mode: "0644" + notify: restart fail2ban +- name: Enable fail2ban + service: + name: fail2ban + state: started + enabled: true diff --git a/tasks/fail2ban/sshd.local.j2 b/tasks/fail2ban/sshd.local.j2 new file mode 100644 index 0000000..ee1606b --- /dev/null +++ b/tasks/fail2ban/sshd.local.j2 @@ -0,0 +1,14 @@ +[DEFAULT] +backend = systemd +banaction = nftables-multiport +banaction_allports = nftables-allports +ignoreip = {{ (['127.0.0.1/8', '::1'] + fail2ban_ignoreip | default([])) | join(' ') }} +bantime = {{ fail2ban_bantime | default('1h') }} +bantime.increment = true +bantime.maxtime = {{ fail2ban_bantime_max | default('1w') }} +findtime = {{ fail2ban_findtime | default('10m') }} +maxretry = {{ fail2ban_maxretry | default(5) }} + +[sshd] +enabled = true +port = ssh