host_firewall: forward_policy log|drop admits replies, DNAT, trusted and pod interfaces, forward_ifaces for routed-only links

This commit is contained in:
2026-11-11 21:48:43 +00:00
parent c2a2a1ea0e
commit 08078324c9
3 changed files with 37 additions and 2 deletions
+7
View File
@@ -131,6 +131,13 @@ firewall:
# forwarding hosts (Kubernetes with Cilium, Docker, routing peers) otherwise route packets for foreign destinations that # forwarding hosts (Kubernetes with Cilium, Docker, routing peers) otherwise route packets for foreign destinations that
# the datacenter sends to them back out. An uplink (see above) is already covered and left out. # the datacenter sends to them back out. An uplink (see above) is already covered and left out.
no_reflect: {} no_reflect: {}
# Forward chain default. accept: forwarded traffic passes unless a rule above drops it. log: traffic that no accept rule
# (replies, DNATed connections, trusted interfaces: wt0, cluster, internal and guest ifaces, routed_v6 bridges) admits is
# logged with fw-fwd-drop: and counted, to find the interfaces a host still needs. drop: the same traffic is dropped.
forward_policy: accept
# Interfaces (name -> interface, wildcards allowed) whose forwarded traffic is accepted without trusting their input,
# e.g. a transit bridge to a guest that only needs routing.
forward_ifaces: {}
# Reject outbound TCP 25; the mail group turns it off. # Reject outbound TCP 25; the mail group turns it off.
block_smtp_out: true block_smtp_out: true
# EU-27 plus CH, NO, GB, IS, LI (ipdeny country codes). Empty leaves the geo # EU-27 plus CH, NO, GB, IS, LI (ipdeny country codes). Empty leaves the geo
+5
View File
@@ -10,6 +10,11 @@
fail_msg: "wt0 address {{ ansible_wt0.ipv4.address }} is missing from firewall.cluster.v4" fail_msg: "wt0 address {{ ansible_wt0.ipv4.address }} is missing from firewall.cluster.v4"
when: firewall.cluster.v4 | default({}, true) | length > 0 and ansible_wt0.ipv4.address is defined when: firewall.cluster.v4 | default({}, true) | length > 0 and ansible_wt0.ipv4.address is defined
- name: Check the forward policy
ansible.builtin.assert:
that: firewall.forward_policy | default('accept', true) in ['accept', 'log', 'drop']
fail_msg: "firewall.forward_policy is {{ firewall.forward_policy }}, expected accept, log or drop"
- name: Remove the include block of the old nftables role - name: Remove the include block of the old nftables role
ansible.builtin.blockinfile: ansible.builtin.blockinfile:
path: /etc/nftables.conf path: /etc/nftables.conf
+25 -2
View File
@@ -444,10 +444,13 @@ table inet host {
ip6 saddr @geo_v6 accept ip6 saddr @geo_v6 accept
{% endif %} {% endif %}
} }
{% if forward_guard or blocklists or firewall.scanners or rl_forward or firewall.block_smtp_out or firewall.uplinks or no_reflect %} {% set forward_policy = firewall.forward_policy | default('accept', true) %}
{% set forward_ifaces = firewall.forward_ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
{% set forward_trusted = (['wt0'] + cluster_ifaces + internal_ifaces + guest_ifaces + forward_ifaces) | unique | list %}
{% if forward_guard or blocklists or firewall.scanners or rl_forward or firewall.block_smtp_out or firewall.uplinks or no_reflect or forward_policy != 'accept' %}
chain forward { chain forward {
type filter hook forward priority filter; policy accept; type filter hook forward priority filter; policy {{ 'drop' if forward_policy == 'drop' else 'accept' }};
{% if no_reflect %} {% if no_reflect %}
# A packet that arrives on the interface of the default route and would leave through it again is a foreign # A packet that arrives on the interface of the default route and would leave through it again is a foreign
@@ -520,6 +523,26 @@ table inet host {
ct status & dnat == 0 ip daddr != @cluster_v4 tcp dport 25 reject with tcp reset ct status & dnat == 0 ip daddr != @cluster_v4 tcp dport 25 reject with tcp reset
ct status & dnat == 0 ip6 daddr != @cluster_v6 tcp dport 25 limit rate {{ firewall.log.out_rate }} log prefix "fw-out-reject: " ct status & dnat == 0 ip6 daddr != @cluster_v6 tcp dport 25 limit rate {{ firewall.log.out_rate }} log prefix "fw-out-reject: "
ct status & dnat == 0 ip6 daddr != @cluster_v6 tcp dport 25 reject with tcp reset ct status & dnat == 0 ip6 daddr != @cluster_v6 tcp dport 25 reject with tcp reset
{% endif %}
{% if forward_policy != 'accept' %}
# What is forwarded on purpose: replies, connections DNATed here, traffic that arrives on a trusted interface (mesh,
# cluster, internal and guest interfaces) and traffic to the pods (Cilium translates services before netfilter, so
# connections from outside arrive as client -> pod without ct status dnat). One rule per interface: a set that mixes
# wildcards and plain names did not match wt0. Everything else is logged and, with forward_policy drop, dropped.
ct state established,related accept
ct status dnat accept
{% for iface in forward_trusted %}
iifname "{{ iface }}" accept
{% endfor %}
{% for iface in cluster_ifaces %}
oifname "{{ iface }}" accept
{% endfor %}
{% if routed_v6 %}
meta nfproto ipv6 oifname { "{{ routed_v6 | join('", "') }}" } accept
{% endif %}
limit rate {{ firewall.log.in_rate }} log prefix "fw-fwd-drop: "
counter
{% endif %} {% endif %}
} }
{% endif %} {% endif %}