X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/7ceeae1a312e18a1bb2d05c357455f3c058e3975..5fb76dc7c3c0de9177b690895aed29d479aa144a:/cookbooks/networking/resources/firewall_rule.rb diff --git a/cookbooks/networking/resources/firewall_rule.rb b/cookbooks/networking/resources/firewall_rule.rb index 92256936a..6f429ac5d 100644 --- a/cookbooks/networking/resources/firewall_rule.rb +++ b/cookbooks/networking/resources/firewall_rule.rb @@ -29,11 +29,11 @@ property :family, :kind_of => [String, Symbol] property :source, :kind_of => String, :required => true property :dest, :kind_of => String, :required => true property :proto, :kind_of => String, :required => true -property :dest_ports, :kind_of => [String, Integer], :default => "-" -property :source_ports, :kind_of => [String, Integer], :default => "-" -property :rate_limit, :kind_of => String, :default => "-" -property :connection_limit, :kind_of => [String, Integer], :default => "-" -property :helper, :kind_of => String, :default => "-" +property :dest_ports, :kind_of => [String, Integer, Array] +property :source_ports, :kind_of => [String, Integer, Array] +property :rate_limit, :kind_of => String +property :connection_limit, :kind_of => [String, Integer] +property :helper, :kind_of => String property :compile_time, TrueClass, :default => true @@ -69,16 +69,13 @@ action_class do when "inet6" then "ip6" end - proto = case new_resource.proto - when "udp" then "udp" - when "tcp", "tcp:syn" then "tcp" - end + proto = new_resource.proto - if new_resource.source_ports != "-" + if new_resource.source_ports rule << "#{proto} sport { #{nftables_source_ports} }" end - if new_resource.dest_ports != "-" + if new_resource.dest_ports rule << "#{proto} dport { #{nftables_dest_ports} }" end @@ -98,11 +95,9 @@ action_class do rule << "#{ip} daddr { #{addresses} }" end - if new_resource.proto == "tcp:syn" - rule << "ct state new" - end + rule << "ct state new" if new_resource.proto == "tcp" - if new_resource.connection_limit != "-" + if new_resource.connection_limit set = "connlimit-#{new_resource.rule}-#{ip}" node.default[:networking][:firewall][:sets] << set @@ -120,6 +115,16 @@ action_class do rule << "update @#{set} { #{ip} saddr limit rate #{rate}/second burst #{burst} packets }" end + if new_resource.helper + helper = "#{new_resource.rule}-#{new_resource.helper}" + + node.default[:networking][:firewall][:helpers] << { + :name => helper, :helper => new_resource.helper, :protocol => proto + } + + rule << "ct helper set #{helper}" + end + rule << case action when :accept then "accept" when :drop then "jump log-and-drop" @@ -134,10 +139,10 @@ action_class do end def nftables_source_ports - new_resource.source_ports.to_s.sub(/:$/, "-65535").gsub(":", "-") + Array(new_resource.source_ports).map(&:to_s).join(",") end def nftables_dest_ports - new_resource.dest_ports.to_s.sub(/:$/, "-65535").gsub(":", "-") + Array(new_resource.dest_ports).map(&:to_s).join(",") end end