host_firewall: drop new connections that enter and leave through the default-route interface

This commit is contained in:
2026-11-11 21:14:34 +00:00
parent 27f6635cc1
commit c2a2a1ea0e
2 changed files with 14 additions and 1 deletions
+5
View File
@@ -126,6 +126,11 @@ firewall:
# never routes foreign destinations back out of the uplink or into the mesh and other interfaces. The kernel routes the
# prefix of the guest bridge, so no address is listed. The guest firewalls decide about the ports. IPv4 stays DNAT only.
routed_v6: {}
# Interfaces (name -> interface) whose forwarded traffic must not leave through the interface it arrived on, added to the
# interfaces of the default routes (IPv4 and IPv6) that every host gets. New connections that would be reflected drop;
# 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.
no_reflect: {}
# 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
+9 -1
View File
@@ -37,6 +37,8 @@ set {{ name }} {
{% set scrapers = firewall.scrapers | default({}, true) %}
{% set forward_guard = firewall.forward_guard | default({}, true) | dict2items | rejectattr('value', 'none') | list %}
{% set routed_v6 = firewall.routed_v6 | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
{% set uplink_ifaces = firewall.uplinks | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | list %}
{% set no_reflect = ((firewall.no_reflect | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | list) + ([ansible_default_ipv4.interface | default(none), ansible_default_ipv6.interface | default(none)] | select | list)) | unique | difference(uplink_ifaces) | list %}
{% 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(' ') }}
@@ -442,10 +444,16 @@ table inet host {
ip6 saddr @geo_v6 accept
{% endif %}
}
{% if forward_guard or blocklists or firewall.scanners or rl_forward or firewall.block_smtp_out or firewall.uplinks %}
{% if forward_guard or blocklists or firewall.scanners or rl_forward or firewall.block_smtp_out or firewall.uplinks or no_reflect %}
chain forward {
type filter hook forward priority filter; policy accept;
{% if no_reflect %}
# A packet that arrives on the interface of the default route and would leave through it again is a foreign
# destination the datacenter routed to this host: it is not forwarded, or the host acts as a reflector.
iifname { "{{ no_reflect | join('", "') }}" } oifname { "{{ no_reflect | join('", "') }}" } ct state new counter drop
{% endif %}
{% if rl_forward %}
# Docker-published ports and port forwards arrive here after DNAT; pod and guest egress is not DNATed.