Skip to content

Commit a8affb5

Browse files
committed
(CAT-1224) firewall type/provider code updates
- loosen type restrictions for src_range/dst_range/to. - Add increased validation for src_range/dst_range. - Ensure string_hex is compared with whitespaces removed.
1 parent 1cf5c84 commit a8affb5

File tree

4 files changed

+968
-948
lines changed

4 files changed

+968
-948
lines changed

Diff for: lib/puppet/provider/firewall/firewall.rb

+21-1
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,20 @@ def self.validate_input(is, should)
687687
end
688688
# Log prefix size is limited
689689
raise 'Parameter `nflog_prefix`` must be less than 64 characters' if should[:nflog_prefix] && should[:nflog_prefix].length > 64
690+
691+
[:dst_range, :src_range].each do |key|
692+
next unless should[key]
693+
matches = %r{^([^\-\/]+)-([^\-\/]+)$}.match(should[key])
694+
raise(ArgumentError, "The IP range must be in 'IP1-IP2' format.") unless matches
695+
696+
[matches[1], matches[2]].each do |addr|
697+
begin # rubocop:disable Style/RedundantBegin
698+
PuppetX::Firewall::Utility.host_to_ip(addr)
699+
rescue StandardError
700+
raise("Invalid IP address \"#{addr}\" in range \"#{should[key]}\"")
701+
end
702+
end
703+
end
690704
end
691705

692706
# Certain attributes need processed in ways that can vary between IPv4 and IPv6
@@ -917,7 +931,7 @@ def insync?(context, _name, property_name, is_hash, should_hash)
917931
is = is_hash[property_name]
918932
should = should_hash[property_name]
919933

920-
should = 'IPv4' if should == 'iptables'
934+
is = 'IPv4' if is == 'iptables'
921935
should = 'IPv6' if should == 'ip6tables'
922936

923937
is == should
@@ -1015,6 +1029,12 @@ def insync?(context, _name, property_name, is_hash, should_hash)
10151029
# Range can be passed as `-` but will always be set/returned as `:`
10161030
is_hash[property_name] == should_hash[property_name].gsub(%r{-}, ':') if should_hash[property_name].is_a?(String)
10171031
is_hash[property_name] == should_hash[property_name].map { |port| port.to_s.gsub(%r{-}, ':') } if should_hash[property_name].is_a?(Array)
1032+
when :string_hex
1033+
# Compare the values with any whitespace removed
1034+
is = is_hash[property_name].to_s.gsub(%r{\s+}, '')
1035+
should = should_hash[property_name].to_s.gsub(%r{\s+}, '')
1036+
1037+
is == should
10181038
else
10191039
# Ensure that if both values are arrays, that they are sorted prior to comparison
10201040
return nil unless is_hash[property_name].is_a?(Array) && should_hash[property_name].is_a?(Array)

Diff for: lib/puppet/type/firewall.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -341,21 +341,21 @@
341341
DESC
342342
},
343343
src_range: {
344-
type: 'Optional[Pattern[/^(?:!\s)?\d+\.\d+\.\d+\.\d+-\d+\.\d+\.\d+\.\d++$/]]',
344+
type: 'Optional[String[1]]',
345345
desc: <<-DESC
346346
The source IP range. For example:
347347
348348
src_range => '192.168.1.1-192.168.1.10'
349349
350-
You can also negate the range by putting ! in front. For example:
350+
You can also negate the range by apending a `!`` to the front. For example:
351351
352-
! src_range => '192.168.1.1-192.168.1.10'
352+
src_range => '! 192.168.1.1-192.168.1.10'
353353
354354
The source IP range must be in 'IP1-IP2' format.
355355
DESC
356356
},
357357
dst_range: {
358-
type: 'Optional[Pattern[/^(?:!\s)?\d+\.\d+\.\d+\.\d+-\d+\.\d+\.\d+\.\d+$/]]',
358+
type: 'Optional[String[1]]',
359359
desc: <<-DESC
360360
The destination IP range. For example:
361361
@@ -1189,7 +1189,7 @@
11891189
DESC
11901190
},
11911191
to: {
1192-
type: 'Optional[Pattern[/^\d+\.\d+\.\d+\.\d+(?:\/\d+)?$/]]',
1192+
type: 'Optional[String[1]]',
11931193
desc: <<-DESC
11941194
For NETMAP this will replace the destination IP
11951195
DESC

0 commit comments

Comments
 (0)