From: Tom Hughes Date: Sat, 11 Mar 2023 14:45:11 +0000 (+0000) Subject: Fix newline suppression in ERB template X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/611b7465e12dd869b9635b241c8d65165860ad89 Fix newline suppression in ERB template --- diff --git a/cookbooks/networking/templates/default/nftables.conf.erb b/cookbooks/networking/templates/default/nftables.conf.erb index 05984ac3e..4a16fb098 100644 --- a/cookbooks/networking/templates/default/nftables.conf.erb +++ b/cookbooks/networking/templates/default/nftables.conf.erb @@ -1,8 +1,8 @@ #!/usr/sbin/nft -f -<%- unless @interfaces.empty? %> +<% unless @interfaces.empty? -%> define external-interfaces = { <%= @interfaces.sort.uniq.join(", ") %> } -<%- end %> +<% 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 } define ip-multicast-addresses = { 224.0.0.0/4 } @@ -12,16 +12,16 @@ define ip6-multicast-addresses = { ff00::/8 } table inet chef-filter { set ip-osm-addresses { type ipv4_addr -<%- unless Array(@hosts["inet"]).empty? %> +<% unless Array(@hosts["inet"]).empty? -%> elements = { <%= Array(@hosts["inet"]).sort.join(", ") %> } -<%- end %> +<% end -%> } set ip6-osm-addresses { type ipv6_addr -<%- unless Array(@hosts["inet"]).empty? %> +<% unless Array(@hosts["inet"]).empty? -%> elements = { <%= Array(@hosts["inet6"]).sort.join(", ") %> } -<%- end %> +<% end -%> } set ip-blocklist { @@ -46,27 +46,27 @@ table inet chef-filter { timeout 120s } -<%- node[:networking][:firewall][:sets].each do |set| %> +<% node[:networking][:firewall][:sets].each do |set| -%> set <%= set %> { -<%- if set.end_with?("-ip") %> +<% if set.end_with?("-ip") -%> type ipv4_addr -<%- elsif set.end_with?("-ip6") %> +<% elsif set.end_with?("-ip6") -%> type ipv6_addr -<%- end %> +<% end -%> flags dynamic -<%- unless set.start_with?("connlimit-") %> +<% unless set.start_with?("connlimit-") -%> timeout 120s -<%- end %> +<% end -%> } -<%- end %> +<% end -%> -<%- node[:networking][:firewall][:helpers].each do |helper| %> +<% node[:networking][:firewall][:helpers].each do |helper| -%> ct helper <%= helper[:name] %> { type "<%= helper[:helper] %>" protocol <%= helper[:protocol] %> } -<%- end %> +<% end -%> chain log-and-drop { limit rate 1/second log drop @@ -78,11 +78,11 @@ table inet chef-filter { } chain incoming { -<%- if node[:networking][:firewall][:allowlist].empty? %> +<% if node[:networking][:firewall][:allowlist].empty? -%> ip saddr { $ip-private-addresses, $ip-multicast-addresses } jump log-and-drop -<%- else %> +<% else -%> ip saddr { $ip-private-addresses, $ip-multicast-addresses } ip saddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop -<%- end %> +<% end -%> ip6 saddr { $ip6-private-addresses, $ip6-multicast-addresses } jump log-and-drop ip saddr @ip-blocklist jump log-and-drop @@ -107,24 +107,24 @@ table inet chef-filter { tcp flags & (fin|psh|ack) == fin|psh jump log-and-drop tcp sport 0 tcp flags & (fin|syn|rst|ack) == syn jump log-and-drop -<%- node[:networking][:firewall][:incoming].uniq.each do |rule| %> +<% node[:networking][:firewall][:incoming].uniq.each do |rule| -%> <%= rule %> -<%- end %> +<% end -%> jump log-and-drop } chain outgoing { -<%- if node[:networking][:firewall][:allowlist].empty? %> +<% if node[:networking][:firewall][:allowlist].empty? -%> ip daddr { $ip-private-addresses } jump log-and-drop -<%- else %> +<% else -%> ip daddr { $ip-private-addresses } ip daddr != { <%= node[:networking][:firewall][:allowlist].sort.join(", ") %> } jump log-and-drop -<%- end %> +<% end -%> ip6 daddr { $ip6-private-addresses } jump log-and-drop -<%- node[:networking][:firewall][:outgoing].each do |rule| %> +<% node[:networking][:firewall][:outgoing].each do |rule| -%> <%= rule %> -<%- end %> +<% end -%> accept } @@ -132,9 +132,9 @@ table inet chef-filter { chain input { type filter hook input priority filter; -<%- unless @interfaces.empty? %> +<% unless @interfaces.empty? -%> iifname { $external-interfaces } jump incoming -<%- end %> +<% end -%> accept } @@ -142,10 +142,10 @@ table inet chef-filter { chain forward { type filter hook forward priority filter; -<%- unless @interfaces.empty? %> +<% unless @interfaces.empty? -%> iifname { $external-interfaces } jump incoming oifname { $external-interfaces } jump outgoing -<%- end %> +<% end -%> accept } @@ -153,24 +153,24 @@ table inet chef-filter { chain output { type filter hook output priority filter; -<%- unless @interfaces.empty? %> +<% unless @interfaces.empty? -%> oifname { $external-interfaces } jump outgoing -<%- end %> +<% end -%> accept } } -<%- if node[:roles].include?("gateway") %> +<% if node[:roles].include?("gateway") -%> 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| %> +<% node.interfaces(:role => :external, :family => :inet).each do |external| -%> +<% node.interfaces(:role => :internal, :family => :inet).each do |internal| -%> oifname { <%= external[:interface] %> } ip saddr { <%= internal[:network] %>/<%= internal[:prefix] %> } snat <%= external[:address] %> -<%- end %> -<%- end %> +<% end -%> +<% end -%> } } -<%- end %> +<% end -%>