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 }
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(", ") %> }
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") %>
62 limit rate 1/second log
66 chain log-and-reject {
67 limit rate 1/second log
72 <%- if node[:networking][:firewall][:whitelist].empty? %>
73 ip saddr { $ip-private-addresses } jump log-and-drop
75 ip saddr { $ip-private-addresses } ip saddr != { <%= node[:networking][:firewall][:whitelist].sort.join(", ") %> } jump log-and-drop
77 ip6 saddr { $ip6-private-addresses } jump log-and-drop
79 ip saddr @ip-blacklist jump log-and-drop
80 ip6 saddr @ip6-blacklist jump log-and-drop
82 ct state { established, related } accept
84 icmp type { destination-unreachable } accept
85 icmp type { echo-request } add @ratelimit-icmp-echo-ip { ip saddr limit rate 1/second } accept
86 icmp type { echo-request } drop
88 icmpv6 type { nd-neighbor-solicit, nd-neighbor-advert, nd-router-solicit, nd-router-advert } accept
89 icmpv6 type { echo-request } add @ratelimit-icmp-echo-ip6 { ip6 saddr limit rate 1/second } accept
90 icmpv6 type { echo-request } drop
92 meta l4proto { icmp, icmpv6 } jump log-and-drop
94 tcp flags & (fin|syn|rst|psh|ack|urg) == fin|psh|urg jump log-and-drop
95 tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 jump log-and-drop
96 tcp flags & (syn|rst) == syn|rst jump log-and-drop
97 tcp flags & (fin|rst) == fin|rst jump log-and-drop
98 tcp flags & (fin|syn) == fin|syn jump log-and-drop
99 tcp flags & (fin|psh|ack) == fin|psh jump log-and-drop
100 tcp sport 0 tcp flags & (fin|syn|rst|ack) == syn jump log-and-drop
102 <%- node[:networking][:firewall][:incoming].uniq.each do |rule| %>
110 <%- if node[:networking][:firewall][:whitelist].empty? %>
111 ip daddr { $ip-private-addresses } jump log-and-drop
113 ip daddr { $ip-private-addresses } ip daddr != { <%= node[:networking][:firewall][:whitelist].sort.join(", ") %> } jump log-and-drop
115 ip6 daddr { $ip6-private-addresses } jump log-and-drop
117 <%- node[:networking][:firewall][:outgoing].each do |rule| %>
125 type filter hook input priority filter;
127 <%- unless @interfaces.empty? %>
128 iifname { $external-interfaces } jump incoming
135 type filter hook forward priority filter;
137 <%- unless @interfaces.empty? %>
138 iifname { $external-interfaces } jump incoming
139 oifname { $external-interfaces } jump outgoing
146 type filter hook output priority filter;
148 <%- unless @interfaces.empty? %>
149 oifname { $external-interfaces } jump outgoing
155 <%- if node[:roles].include?("gateway") %>
159 type nat hook postrouting priority srcnat;
161 <%- node.interfaces(:role => :external, :family => :inet).each do |external| %>
162 <%- node.interfaces(:role => :internal, :family => :inet).each do |internal| %>
163 oifname { <%= external[:interface] %> } ip saddr { <%= internal[:network] %>/<%= internal[:prefix] %> } snat <%= external[:address] %>