From e8eee3be551f31432b97b36e51394c5e243c4782 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 11 Nov 2026 20:39:19 +0000 Subject: [PATCH] host_firewall: routed_v6 prefixes pass the uplink drop, foreign IPv6 destinations still drop --- host_firewall/defaults/main.yml | 4 ++++ host_firewall/templates/host.nft.j2 | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/host_firewall/defaults/main.yml b/host_firewall/defaults/main.yml index 052d1d9..f273d90 100644 --- a/host_firewall/defaults/main.yml +++ b/host_firewall/defaults/main.yml @@ -121,6 +121,10 @@ firewall: # addresses of the subnet to the host; with ip_forward they would be forwarded and masqueraded with the host address. # Not for hosts whose forwarded inbound traffic is not DNATed in netfilter (Cilium NodePorts are DNATed in BPF). uplinks: {} + # IPv6 prefixes routed to guests (name -> prefix). New forwarded connections that arrive on an uplink pass the uplink drop + # when they are addressed to one of them; everything else still drops, so the host never routes foreign destinations back + # out of the uplink. The guest firewalls decide about the ports. + routed_v6: {} # Reject outbound TCP 25; the mail group turns it off. block_smtp_out: true # EU-27 plus CH, NO, GB, IS, LI (ipdeny country codes). Empty leaves the geo diff --git a/host_firewall/templates/host.nft.j2 b/host_firewall/templates/host.nft.j2 index c7486d1..9d8c525 100644 --- a/host_firewall/templates/host.nft.j2 +++ b/host_firewall/templates/host.nft.j2 @@ -36,6 +36,7 @@ set {{ name }} { {% set journal_rule = list(journal.clients) and journal.port %} {% set scrapers = firewall.scrapers | default({}, true) %} {% set forward_guard = firewall.forward_guard | default({}, true) | dict2items | rejectattr('value', 'none') | list %} +{% set routed_v6 = list(firewall.routed_v6) %} {% set blocklists = firewall.spamhaus or firewall.firehol %} {% macro port_values(map) -%} {{ map | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | map('string') | unique | join(' ') }} @@ -494,8 +495,14 @@ table inet host { {% endfor %} {% for name, iface in firewall.uplinks.items() if iface is not none %} +{% if routed_v6 %} + # {{ name }}: from outside only what was DNATed here, admitted by a forward_guard zone above or addressed to a routed IPv6 prefix. + iifname "{{ iface }}" ct state new ct status & dnat == 0 meta nfproto ipv4 counter drop + iifname "{{ iface }}" ct state new ct status & dnat == 0 ip6 daddr != { {{ routed_v6 }} } counter drop +{% else %} # {{ name }}: from outside only what was DNATed here or admitted by a forward_guard zone above. iifname "{{ iface }}" ct state new ct status & dnat == 0 counter drop +{% endif %} {% endfor %} {% if firewall.block_smtp_out %}