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(", ") %> }
35 set ratelimit-icmp-echo-ip {
40 set ratelimit-icmp-echo-ip6 {
45 <%- node[:networking][:firewall][:sets].each do |set| %>
47 <%- if set.end_with?("-ip") %>
49 <%- elsif set.end_with?("-ip6") %>
57 limit rate 1/second log
61 chain log-and-reject {
62 limit rate 1/second log
67 <%- if node[:networking][:firewall][:whitelist].empty? %>
68 ip saddr { $ip-private-addresses } jump log-and-drop
70 ip saddr { $ip-private-addresses } ip saddr != { <%= node[:networking][:firewall][:whitelist].sort.join(", ") %> } jump log-and-drop
72 ip6 saddr { $ip6-private-addresses } jump log-and-drop
74 ip saddr @ip-blacklist jump log-and-drop
75 ip6 saddr @ip6-blacklist jump log-and-drop
77 ct state { established, related } accept
79 icmp type { destination-unreachable } accept
80 icmp type { echo-request } add @ratelimit-icmp-echo-ip { ip saddr limit rate 1/second } accept
81 icmp type { echo-request } drop
83 icmpv6 type { nd-neighbor-solicit, nd-neighbor-advert, nd-router-solicit, nd-router-advert } accept
84 icmpv6 type { echo-request } add @ratelimit-icmp-echo-ip6 { ip6 saddr limit rate 1/second } accept
85 icmpv6 type { echo-request } drop
87 meta l4proto { icmp, icmpv6 } jump log-and-drop
89 tcp flags & (fin|syn|rst|psh|ack|urg) == fin|psh|urg jump log-and-drop
90 tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 jump log-and-drop
91 tcp flags & (syn|rst) == syn|rst jump log-and-drop
92 tcp flags & (fin|rst) == fin|rst jump log-and-drop
93 tcp flags & (fin|syn) == fin|syn jump log-and-drop
94 tcp flags & (fin|psh|ack) == fin|psh jump log-and-drop
95 tcp sport 0 tcp flags & (fin|syn|rst|ack) == syn jump log-and-drop
97 <%- node[:networking][:firewall][:incoming].uniq.each do |rule| %>
105 <%- if node[:networking][:firewall][:whitelist].empty? %>
106 ip daddr { $ip-private-addresses } jump log-and-drop
108 ip daddr { $ip-private-addresses } ip daddr != { <%= node[:networking][:firewall][:whitelist].sort.join(", ") %> } jump log-and-drop
110 ip6 daddr { $ip6-private-addresses } jump log-and-drop
112 <%- node[:networking][:firewall][:outgoing].each do |rule| %>
120 type filter hook input priority filter;
122 <%- unless @interfaces.empty? %>
123 iifname { $external-interfaces } jump incoming
130 type filter hook forward priority filter;
132 <%- unless @interfaces.empty? %>
133 iifname { $external-interfaces } jump incoming
134 oifname { $external-interfaces } jump outgoing
141 type filter hook output priority filter;
143 <%- unless @interfaces.empty? %>
144 oifname { $external-interfaces } jump outgoing
150 <%- if node[:roles].include?("gateway") %>
154 type nat hook postrouting priority srcnat;
156 <%- node.interfaces(:role => :external, :family => :inet).each do |external| %>
157 <%- node.interfaces(:role => :internal, :family => :inet).each do |internal| %>
158 oifname { <%= external[:interface] %> } ip saddr { <%= internal[:network] %>/<%= internal[:prefix] %> } snat <%= external[:address] %>