host_firewall: GreenSnow set greensnow_v4 drops inbound new connections of the listed hosts

This commit is contained in:
2026-10-30 09:01:25 +00:00
parent f92b36ceaa
commit ca34bd8363
6 changed files with 234 additions and 3 deletions
+54 -1
View File
@@ -59,7 +59,7 @@
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
mode: "0644"
loop: [nft-host.service, nft-host-geo.service, nft-host-geo.timer, nft-host-spamhaus.service, nft-host-spamhaus.timer, nft-host-firehol.service, nft-host-firehol.timer, nft-host-scanners.service, nft-host-scanners.timer]
loop: [nft-host.service, nft-host-geo.service, nft-host-geo.timer, nft-host-spamhaus.service, nft-host-spamhaus.timer, nft-host-firehol.service, nft-host-firehol.timer, nft-host-scanners.service, nft-host-scanners.timer, nft-host-greensnow.service, nft-host-greensnow.timer]
register: firewall_units
- name: Install the rollback script
@@ -287,6 +287,59 @@
path: /etc/nftables.d/host-scanners.nft
state: absent
- name: GreenSnow set
when: firewall.greensnow
block:
- name: Install the GreenSnow set updater
ansible.builtin.copy:
src: nft-host-greensnow
dest: /usr/local/sbin/nft-host-greensnow
mode: "0755"
# The rule set includes this file, so a missing one would fail the load at boot.
- name: Build the GreenSnow set on first run
ansible.builtin.command: /usr/local/sbin/nft-host-greensnow
args:
creates: /etc/nftables.d/host-greensnow.nft
- name: Read the GreenSnow set file
ansible.builtin.stat:
path: /etc/nftables.d/host-greensnow.nft
register: firewall_greensnow
- name: Require non-empty GreenSnow set
ansible.builtin.assert:
that: firewall_greensnow.stat.exists and firewall_greensnow.stat.size > 0
fail_msg: /etc/nftables.d/host-greensnow.nft is missing or empty, refusing to apply the firewall
# Check mode neither installs the updater nor builds the set.
when: not ansible_check_mode
- name: Enable the GreenSnow set timer
ansible.builtin.systemd:
name: nft-host-greensnow.timer
enabled: true
state: started
daemon_reload: "{{ firewall_units is changed }}"
# Check mode does not install the unit.
ignore_errors: "{{ ansible_check_mode }}"
- name: Stop the GreenSnow set refresh
when: not firewall.greensnow
block:
- name: Disable the GreenSnow set timer
ansible.builtin.systemd:
name: nft-host-greensnow.timer
enabled: false
state: stopped
daemon_reload: "{{ firewall_units is changed }}"
# Check mode does not install the unit.
ignore_errors: "{{ ansible_check_mode }}"
- name: Remove the GreenSnow set file
ansible.builtin.file:
path: /etc/nftables.d/host-greensnow.nft
state: absent
- name: Render the rule set
ansible.builtin.template:
src: host.nft.j2