summaryrefslogtreecommitdiffstats
path: root/roles/common/templates/etc/nftables.conf.j2
diff options
context:
space:
mode:
Diffstat (limited to 'roles/common/templates/etc/nftables.conf.j2')
-rwxr-xr-xroles/common/templates/etc/nftables.conf.j239
1 files changed, 20 insertions, 19 deletions
diff --git a/roles/common/templates/etc/nftables.conf.j2 b/roles/common/templates/etc/nftables.conf.j2
index 8d81d4c..f603ed9 100755
--- a/roles/common/templates/etc/nftables.conf.j2
+++ b/roles/common/templates/etc/nftables.conf.j2
@@ -73,7 +73,7 @@ table netdev filter {
# bogon filter (cf. RFC 6890 for non-global ip addresses)
define bogon = {
0.0.0.0/8 # this host, on this network (RFC 1122 sec. 3.2.1.3)
-{% if not addr | ipaddr('10.0.0.0/8') %}
+{% if not addr | ansible.utils.ipaddr('10.0.0.0/8') %}
, 10.0.0.0/8 # private-use (RFC 1918)
{% endif %}
, 100.64.0.0/10 # shared address space (RFC 6598)
@@ -82,7 +82,7 @@ table netdev filter {
, 172.16.0.0/12 # private-use (RFC 1918)
, 192.0.0.0/24 # IETF protocol assignments (RFC 6890 sec. 2.1)
, 192.0.2.0/24 # documentation (RFC 5737)
-{% if not addr | ipaddr('192.168.0.0/16') %}
+{% if not addr | ansible.utils.ipaddr('192.168.0.0/16') %}
, 192.168.0.0/16 # private-use (RFC 1918)
{% endif %}
, 198.18.0.0/15 # benchmarking (RFC 2544)
@@ -145,7 +145,7 @@ table inet raw {
}
table inet filter {
- # blackholes
+ # blackholes (timeout must match /etc/fail2ban/jail.local)
set fail2ban { type ipv4_addr; timeout 10m; }
set fail2ban6 { type ipv6_addr; timeout 10m; }
@@ -155,16 +155,8 @@ table inet filter {
iif lo accept
- # XXX Bullseye: this is a rather crude match as nftables 0.9.0 lacks support for ipsec expressions
- # to match match inbound resp. outbound policies and source resp. destination tunnel addresses.
- # https://serverfault.com/questions/971735/how-to-match-reqid-in-nftables
- # https://blog.fraggod.net/2016/09/25/nftables-re-injected-ipsec-matching-without-xt_policy.html
- # (We can't use marks to match post-ESP decapsulation here because that doesn't work well with UDP
- # encapsulation.) We'll also pin the reqid to the lowest address byte in ipsec.conf(5); that way
- # peers can't impersonate each other.
meta l4proto esp accept
- # ip saddr {{ ipsec_subnet }} ip daddr {{ ipsec[inventory_hostname_short] }} ipsec in reqid $i accept
- ip saddr {{ ipsec_subnet }} ip daddr {{ ipsec[inventory_hostname_short] }} meta secpath exists accept
+ ip daddr {{ ipsec[inventory_hostname_short] }} jump ipsec-in
# incoming ICMP/ICMPv6 traffic was filtered in the ingress chain already
meta l4proto { icmp, icmpv6 } counter accept
@@ -186,8 +178,8 @@ table inet filter {
ip6 version 6 udp sport 547 udp dport 546 ct state related,established accept
{% endif %}
- meta l4proto tcp ip saddr @fail2ban counter drop
- meta l4proto tcp ip6 saddr @fail2ban6 counter drop
+ ip saddr @fail2ban counter drop
+ ip6 saddr @fail2ban6 counter drop
tcp dport $in-tcp-ports ct state related,established accept
tcp dport $in-tcp-ports ct state new counter accept
@@ -200,12 +192,8 @@ table inet filter {
oif lo accept
- # XXX Bullseye: unlike for input we can't use marks or test for
- # secpath existence here, because by the time we see a packet to
- # 172.16.0.0/24 we don't know if it'll be encapsulated
meta l4proto esp accept
- # ip saddr {{ ipsec[inventory_hostname_short] }} ip daddr {{ ipsec_subnet }} ipsec out reqid $i accept
- ip saddr {{ ipsec[inventory_hostname_short] }} ip daddr {{ ipsec_subnet }} accept
+ ip saddr {{ ipsec[inventory_hostname_short] }} jump ipsec-out
meta l4proto { icmp, icmpv6 } counter accept
@@ -234,4 +222,17 @@ table inet filter {
meta l4proto udp counter reject
counter reject
}
+
+ chain ipsec-in {
+{% for h in ipsec.keys() | difference([inventory_hostname_short]) | sort %}
+ ip saddr {{ ipsec[h] }} ipsec in reqid {{ ipsec[h].replace(":",".").split(".")[-1] }} counter accept
+{% endfor %}
+ log prefix "ipsec-in " drop
+ }
+ chain ipsec-out {
+{% for h in ipsec.keys() | difference([inventory_hostname_short]) | sort %}
+ ip daddr {{ ipsec[h] }} ipsec out reqid {{ ipsec[h].replace(":",".").split(".")[-1] }} counter accept
+{% endfor %}
+ log prefix "ipsec-out " drop
+ }
}