3 <%- unless @interfaces.empty? %>
4 define external-interfaces = { <%= @interfaces.sort.uniq.join(", ") %> }
7 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 }
8 define ip-multicast-addresses = { 224.0.0.0/4 }
9 define ip6-private-addresses = { 2001:db8::/32, fc00::/7 }
10 define ip6-multicast-addresses = { ff00::/8 }
12 table inet chef-filter {
13 set ip-osm-addresses {
15 <%- unless Array(@hosts["inet"]).empty? %>
16 elements = { <%= Array(@hosts["inet"]).sort.join(", ") %> }
20 set ip6-osm-addresses {
22 <%- unless Array(@hosts["inet"]).empty? %>
23 elements = { <%= Array(@hosts["inet6"]).sort.join(", ") %> }
37 set ratelimit-icmp-echo-ip {
43 set ratelimit-icmp-echo-ip6 {
49 <%- node[:networking][:firewall][:sets].each do |set| %>
51 <%- if set.end_with?("-ip") %>
53 <%- elsif set.end_with?("-ip6") %>
57 <%- unless set.start_with?("connlimit-") %>
64 <%- node[:networking][:firewall][:helpers].each do |helper| %>
65 ct helper <%= helper[:name] %> {
66 type "<%= helper[:helper] %>" protocol <%= helper[:protocol] %>
71 limit rate 1/second log
75 chain log-and-reject {
76 limit rate 1/second log
81 <%- if node[:networking][:firewall][:allowlist].empty? %>
82 ip saddr { $ip-private-addresses, $ip-multicast-addresses } jump log-and-drop
84 ip saddr { $ip-private-addresses, $ip-multicast-addresses } ip saddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop
86 ip6 saddr { $ip6-private-addresses, $ip6-multicast-addresses } jump log-and-drop
88 ip saddr @ip-blocklist jump log-and-drop
89 ip6 saddr @ip6-blocklist jump log-and-drop
91 icmp type { echo-request } update @ratelimit-icmp-echo-ip { ip saddr limit rate 1/second } accept
92 icmp type { echo-request } drop
94 icmpv6 type { nd-neighbor-solicit, nd-neighbor-advert, nd-router-solicit, nd-router-advert } accept
95 icmpv6 type { echo-request } update @ratelimit-icmp-echo-ip6 { ip6 saddr limit rate 1/second } accept
96 icmpv6 type { echo-request } drop
98 ct state { established, related } accept
100 meta l4proto { icmp, icmpv6 } jump log-and-drop
102 tcp flags & (fin|syn|rst|psh|ack|urg) == fin|psh|urg jump log-and-drop
103 tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 jump log-and-drop
104 tcp flags & (syn|rst) == syn|rst jump log-and-drop
105 tcp flags & (fin|rst) == fin|rst jump log-and-drop
106 tcp flags & (fin|syn) == fin|syn jump log-and-drop
107 tcp flags & (fin|psh|ack) == fin|psh jump log-and-drop
108 tcp sport 0 tcp flags & (fin|syn|rst|ack) == syn jump log-and-drop
110 <%- node[:networking][:firewall][:incoming].uniq.each do |rule| %>
118 <%- if node[:networking][:firewall][:allowlist].empty? %>
119 ip daddr { $ip-private-addresses } jump log-and-drop
121 ip daddr { $ip-private-addresses } ip daddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop
123 ip6 daddr { $ip6-private-addresses } jump log-and-drop
125 <%- node[:networking][:firewall][:outgoing].each do |rule| %>
133 type filter hook input priority filter;
135 <%- unless @interfaces.empty? %>
136 iifname { $external-interfaces } jump incoming
143 type filter hook forward priority filter;
145 <%- unless @interfaces.empty? %>
146 iifname { $external-interfaces } jump incoming
147 oifname { $external-interfaces } jump outgoing
154 type filter hook output priority filter;
156 <%- unless @interfaces.empty? %>
157 oifname { $external-interfaces } jump outgoing
163 <%- if node[:roles].include?("gateway") %>
167 type nat hook postrouting priority srcnat;
169 <%- node.interfaces(:role => :external, :family => :inet).each do |external| %>
170 <%- node.interfaces(:role => :internal, :family => :inet).each do |internal| %>
171 oifname { <%= external[:interface] %> } ip saddr { <%= internal[:network] %>/<%= internal[:prefix] %> } snat <%= external[:address] %>