X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/534043ca66b46815b0338475a60ad0fac4a90323..3ee5c4d242a98a13d89a02ba7998610a20969e0c:/cookbooks/networking/templates/default/nftables.conf.erb diff --git a/cookbooks/networking/templates/default/nftables.conf.erb b/cookbooks/networking/templates/default/nftables.conf.erb index a3dae7143..05984ac3e 100644 --- a/cookbooks/networking/templates/default/nftables.conf.erb +++ b/cookbooks/networking/templates/default/nftables.conf.erb @@ -4,10 +4,12 @@ define external-interfaces = { <%= @interfaces.sort.uniq.join(", ") %> } <%- end %> -define ip-private-addresses = { 0.0.0.0, 10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.0.2.0/24, 192.168.0.0/16, 224.0.0.0/4 } -define ip6-private-addresses = { 2001:db8::/32, fc00::/7, ff00::/8 } +define ip-private-addresses = { 0.0.0.0, 10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.0.2.0/24, 192.168.0.0/16 } +define ip-multicast-addresses = { 224.0.0.0/4 } +define ip6-private-addresses = { 2001:db8::/32, fc00::/7 } +define ip6-multicast-addresses = { ff00::/8 } -table inet filter { +table inet chef-filter { set ip-osm-addresses { type ipv4_addr <%- unless Array(@hosts["inet"]).empty? %> @@ -22,24 +24,26 @@ table inet filter { <%- end %> } - set ip-blacklist { + set ip-blocklist { type ipv4_addr - flags dynamic + flags interval } - set ip6-blacklist { + set ip6-blocklist { type ipv6_addr - flags dynamic + flags interval } - set limit-icmp-echo-ip { + set ratelimit-icmp-echo-ip { type ipv4_addr flags dynamic + timeout 120s } - set limit-icmp-echo-ip6 { + set ratelimit-icmp-echo-ip6 { type ipv6_addr flags dynamic + timeout 120s } <%- node[:networking][:firewall][:sets].each do |set| %> @@ -50,6 +54,16 @@ table inet filter { type ipv6_addr <%- end %> flags dynamic +<%- unless set.start_with?("connlimit-") %> + timeout 120s +<%- end %> + } + +<%- end %> + +<%- node[:networking][:firewall][:helpers].each do |helper| %> + ct helper <%= helper[:name] %> { + type "<%= helper[:helper] %>" protocol <%= helper[:protocol] %> } <%- end %> @@ -64,22 +78,25 @@ table inet filter { } chain incoming { - ip saddr { $ip-private-addresses } jump log-and-drop - ip6 saddr { $ip6-private-addresses } jump log-and-drop - - ip saddr @ip-blacklist jump log-and-drop - ip6 saddr @ip6-blacklist jump log-and-drop +<%- if node[:networking][:firewall][:allowlist].empty? %> + ip saddr { $ip-private-addresses, $ip-multicast-addresses } jump log-and-drop +<%- else %> + ip saddr { $ip-private-addresses, $ip-multicast-addresses } ip saddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop +<%- end %> + ip6 saddr { $ip6-private-addresses, $ip6-multicast-addresses } jump log-and-drop - ct state { established, related } accept + ip saddr @ip-blocklist jump log-and-drop + ip6 saddr @ip6-blocklist jump log-and-drop - icmp type { destination-unreachable } accept - icmp type { echo-request } add @limit-icmp-echo-ip { ip saddr limit rate 1/second } accept + icmp type { echo-request } update @ratelimit-icmp-echo-ip { ip saddr limit rate 1/second } accept icmp type { echo-request } drop icmpv6 type { nd-neighbor-solicit, nd-neighbor-advert, nd-router-solicit, nd-router-advert } accept - icmpv6 type { echo-request } add @limit-icmp-echo-ip6 { ip6 saddr limit rate 1/second } accept + icmpv6 type { echo-request } update @ratelimit-icmp-echo-ip6 { ip6 saddr limit rate 1/second } accept icmpv6 type { echo-request } drop + ct state { established, related } accept + meta l4proto { icmp, icmpv6 } jump log-and-drop tcp flags & (fin|syn|rst|psh|ack|urg) == fin|psh|urg jump log-and-drop @@ -98,7 +115,11 @@ table inet filter { } chain outgoing { +<%- if node[:networking][:firewall][:allowlist].empty? %> ip daddr { $ip-private-addresses } jump log-and-drop +<%- else %> + ip daddr { $ip-private-addresses } ip daddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop +<%- end %> ip6 daddr { $ip6-private-addresses } jump log-and-drop <%- node[:networking][:firewall][:outgoing].each do |rule| %> @@ -112,7 +133,7 @@ table inet filter { type filter hook input priority filter; <%- unless @interfaces.empty? %> - iif { $external-interfaces } jump incoming + iifname { $external-interfaces } jump incoming <%- end %> accept @@ -122,8 +143,8 @@ table inet filter { type filter hook forward priority filter; <%- unless @interfaces.empty? %> - iif { $external-interfaces } jump incoming - oif { $external-interfaces } jump outgoing + iifname { $external-interfaces } jump incoming + oifname { $external-interfaces } jump outgoing <%- end %> accept @@ -133,7 +154,7 @@ table inet filter { type filter hook output priority filter; <%- unless @interfaces.empty? %> - oif { $external-interfaces } jump outgoing + oifname { $external-interfaces } jump outgoing <%- end %> accept @@ -141,13 +162,13 @@ table inet filter { } <%- if node[:roles].include?("gateway") %> -table ip nat { +table ip chef-nat { chain postrouting { type nat hook postrouting priority srcnat; <%- node.interfaces(:role => :external, :family => :inet).each do |external| %> <%- node.interfaces(:role => :internal, :family => :inet).each do |internal| %> - oif { <%= external[:interface] %> } ip saddr { <%= internal[:network] %>/<%= internal[:prefix] %> } snat <%= external[:address] %> + oifname { <%= external[:interface] %> } ip saddr { <%= internal[:network] %>/<%= internal[:prefix] %> } snat <%= external[:address] %> <%- end %> <%- end %> }