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, 224.0.0.0/4 }
8 define ip6-private-addresses = { 2001:db8::/32, fc00::/7, ff00::/8 }
10 table inet chef-filter {
11 set ip-osm-addresses {
13 <%- unless Array(@hosts["inet"]).empty? %>
14 elements = { <%= Array(@hosts["inet"]).sort.join(", ") %> }
18 set ip6-osm-addresses {
20 <%- unless Array(@hosts["inet"]).empty? %>
21 elements = { <%= Array(@hosts["inet6"]).sort.join(", ") %> }
35 set ratelimit-icmp-echo-ip {
41 set ratelimit-icmp-echo-ip6 {
47 <%- node[:networking][:firewall][:sets].each do |set| %>
49 <%- if set.end_with?("-ip") %>
51 <%- elsif set.end_with?("-ip6") %>
55 <%- unless set.start_with?("connlimit-") %>
62 <%- node[:networking][:firewall][:helpers].each do |helper| %>
63 ct helper <%= helper[:name] %> {
64 type "<%= helper[:helper] %>" protocol <%= helper[:protocol] %>
69 limit rate 1/second log
73 chain log-and-reject {
74 limit rate 1/second log
79 <%- if node[:networking][:firewall][:allowlist].empty? %>
80 ip saddr { $ip-private-addresses } jump log-and-drop
82 ip saddr { $ip-private-addresses } ip saddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop
84 ip6 saddr { $ip6-private-addresses } jump log-and-drop
86 ip saddr @ip-blocklist jump log-and-drop
87 ip6 saddr @ip6-blocklist jump log-and-drop
89 icmp type { echo-request } update @ratelimit-icmp-echo-ip { ip saddr limit rate 1/second } accept
90 icmp type { echo-request } drop
92 icmpv6 type { nd-neighbor-solicit, nd-neighbor-advert, nd-router-solicit, nd-router-advert } accept
93 icmpv6 type { echo-request } update @ratelimit-icmp-echo-ip6 { ip6 saddr limit rate 1/second } accept
94 icmpv6 type { echo-request } drop
96 ct state { established, related } accept
98 meta l4proto { icmp, icmpv6 } jump log-and-drop
100 tcp flags & (fin|syn|rst|psh|ack|urg) == fin|psh|urg jump log-and-drop
101 tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 jump log-and-drop
102 tcp flags & (syn|rst) == syn|rst jump log-and-drop
103 tcp flags & (fin|rst) == fin|rst jump log-and-drop
104 tcp flags & (fin|syn) == fin|syn jump log-and-drop
105 tcp flags & (fin|psh|ack) == fin|psh jump log-and-drop
106 tcp sport 0 tcp flags & (fin|syn|rst|ack) == syn jump log-and-drop
108 <%- node[:networking][:firewall][:incoming].uniq.each do |rule| %>
116 <%- if node[:networking][:firewall][:allowlist].empty? %>
117 ip daddr { $ip-private-addresses } jump log-and-drop
119 ip daddr { $ip-private-addresses } ip daddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop
121 ip6 daddr { $ip6-private-addresses } jump log-and-drop
123 <%- node[:networking][:firewall][:outgoing].each do |rule| %>
131 type filter hook input priority filter;
133 <%- unless @interfaces.empty? %>
134 iifname { $external-interfaces } jump incoming
141 type filter hook forward priority filter;
143 <%- unless @interfaces.empty? %>
144 iifname { $external-interfaces } jump incoming
145 oifname { $external-interfaces } jump outgoing
152 type filter hook output priority filter;
154 <%- unless @interfaces.empty? %>
155 oifname { $external-interfaces } jump outgoing
161 <%- if node[:roles].include?("gateway") %>
165 type nat hook postrouting priority srcnat;
167 <%- node.interfaces(:role => :external, :family => :inet).each do |external| %>
168 <%- node.interfaces(:role => :internal, :family => :inet).each do |internal| %>
169 oifname { <%= external[:interface] %> } ip saddr { <%= internal[:network] %>/<%= internal[:prefix] %> } snat <%= external[:address] %>