|
1 | 1 | # set default bantime to 1 hour
|
2 |
| -- name: extend bantime |
3 |
| - become: yes |
4 |
| - replace: |
5 |
| - path: /etc/fail2ban/jail.conf |
6 |
| - regexp: bantime = 10m |
7 |
| - replace: bantime = 3600 |
8 |
| - when: debpkg_mode or nixpkg_mode |
| 2 | +- name: do debpkg_mode or nixpkg_mode tasks |
| 3 | + when: |
| 4 | + - (debpkg_mode or nixpkg_mode) |
| 5 | + block: |
| 6 | + - name: extend the default bantime to an hour |
| 7 | + become: true |
| 8 | + ansible.builtin.replace: |
| 9 | + path: '/etc/fail2ban/jail.conf' |
| 10 | + regexp: 'bantime = 10m' |
| 11 | + replace: 'bantime = 3600' |
9 | 12 |
|
10 |
| -- name: Configure journald |
11 |
| - copy: |
12 |
| - src: files/fail2ban_config/jail-ssh.conf |
13 |
| - dest: /etc/fail2ban/jail.d/sshd.local |
14 |
| - when: debpkg_mode or nixpkg_mode |
| 13 | + - name: configure journald |
| 14 | + ansible.builtin.copy: |
| 15 | + dest: '/etc/fail2ban/jail.d/sshd.local' |
| 16 | + src: 'files/fail2ban_config/jail-ssh.conf' |
15 | 17 |
|
16 |
| -- name: configure fail2ban to use nftables |
17 |
| - copy: |
18 |
| - src: files/fail2ban_config/jail.local |
19 |
| - dest: /etc/fail2ban/jail.local |
20 |
| - when: debpkg_mode or nixpkg_mode |
| 18 | + - name: configure fail2ban to use nftables |
| 19 | + ansible.builtin.copy: |
| 20 | + dest: '/etc/fail2ban/jail.local' |
| 21 | + src: 'files/fail2ban_config/jail.local' |
21 | 22 |
|
22 |
| -# postgresql |
23 |
| -- name: import jail.d/postgresql.conf |
24 |
| - template: |
25 |
| - src: files/fail2ban_config/jail-postgresql.conf.j2 |
26 |
| - dest: /etc/fail2ban/jail.d/postgresql.conf |
27 |
| - become: yes |
28 |
| - when: debpkg_mode or nixpkg_mode |
| 23 | + # postgresql |
| 24 | + - name: import jail.d/postgresql.conf |
| 25 | + ansible.builtin.template: |
| 26 | + dest: '/etc/fail2ban/jail.d/postgresql.conf' |
| 27 | + src: 'files/fail2ban_config/jail-postgresql.conf.j2' |
| 28 | + become: true |
29 | 29 |
|
30 |
| -- name: import filter.d/postgresql.conf |
31 |
| - template: |
32 |
| - src: files/fail2ban_config/filter-postgresql.conf.j2 |
33 |
| - dest: /etc/fail2ban/filter.d/postgresql.conf |
34 |
| - become: yes |
35 |
| - when: debpkg_mode or nixpkg_mode |
| 30 | + - name: import filter.d/postgresql.conf |
| 31 | + ansible.builtin.template: |
| 32 | + dest: '/etc/fail2ban/filter.d/postgresql.conf' |
| 33 | + src: 'files/fail2ban_config/filter-postgresql.conf.j2' |
| 34 | + become: true |
36 | 35 |
|
37 |
| -- name: create overrides dir |
38 |
| - file: |
39 |
| - state: directory |
40 |
| - owner: root |
41 |
| - group: root |
42 |
| - path: /etc/systemd/system/fail2ban.service.d |
43 |
| - mode: '0700' |
44 |
| - when: debpkg_mode or nixpkg_mode |
| 36 | + - name: create overrides dir |
| 37 | + ansible.builtin.file: |
| 38 | + group: 'root' |
| 39 | + mode: '0700' |
| 40 | + owner: 'root' |
| 41 | + path: '/etc/systemd/system/fail2ban.service.d' |
| 42 | + state: 'directory' |
45 | 43 |
|
46 |
| -- name: Custom systemd overrides |
47 |
| - copy: |
48 |
| - src: files/fail2ban_config/fail2ban.service.conf |
49 |
| - dest: /etc/systemd/system/fail2ban.service.d/overrides.conf |
50 |
| - when: debpkg_mode or nixpkg_mode |
| 44 | + - name: custom systemd overrides |
| 45 | + ansible.builtin.copy: |
| 46 | + dest: '/etc/systemd/system/fail2ban.service.d/overrides.conf' |
| 47 | + src: 'files/fail2ban_config/fail2ban.service.conf' |
51 | 48 |
|
52 |
| -- name: add in supabase specific ignore filters |
53 |
| - lineinfile: |
54 |
| - path: /etc/fail2ban/filter.d/postgresql.conf |
55 |
| - state: present |
56 |
| - line: "{{ item.line }}" |
57 |
| - loop: |
58 |
| - - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_admin".*$' } |
59 |
| - - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_auth_admin".*$' } |
60 |
| - - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_storage_admin".*$' } |
61 |
| - - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""authenticator".*$' } |
62 |
| - - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""pgbouncer".*$' } |
63 |
| - become: yes |
64 |
| - tags: |
65 |
| - - install-supabase-internal |
66 |
| - when: debpkg_mode or nixpkg_mode |
| 49 | + - name: add in supabase specific ignore filters |
| 50 | + ansible.builtin.lineinfile: |
| 51 | + line: "{{ ignore_item['line'] }}" |
| 52 | + path: /etc/fail2ban/filter.d/postgresql.conf |
| 53 | + state: present |
| 54 | + become: true |
| 55 | + loop: |
| 56 | + - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_admin".*$' } |
| 57 | + - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_auth_admin".*$' } |
| 58 | + - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""supabase_storage_admin".*$' } |
| 59 | + - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""authenticator".*$' } |
| 60 | + - { line: ' ^.*,.*,.*,.*,"<HOST>:.*password authentication failed for user ""pgbouncer".*$' } |
| 61 | + loop_control: |
| 62 | + loop_var: 'ignore_item' |
| 63 | + tags: |
| 64 | + - install-supabase-internal |
67 | 65 |
|
68 |
| -- name: fail2ban - disable service |
69 |
| - systemd: |
70 |
| - name: fail2ban |
71 |
| - enabled: no |
72 |
| - daemon_reload: yes |
73 |
| - when: debpkg_mode or nixpkg_mode |
| 66 | + - name: fail2ban - disable service |
| 67 | + ansible.builtin.systemd_service: |
| 68 | + daemon_reload: true |
| 69 | + enabled: false |
| 70 | + name: 'fail2ban' |
0 commit comments