Skip to content

Commit

Permalink
(MODULES-1976) Revise rule name validation for ruby 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
karmix committed Apr 24, 2015
1 parent e7121fe commit 706bb3c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ All rules employ a numbering system in the resource's title that is used for ord

You can place default rules in either `my_fw::pre` or `my_fw::post`, depending on when you would like them to run. Rules placed in the `pre` class will run first, and rules in the `post` class, last.

In iptables, the title of the rule is stored using the comment feature of the underlying firewall subsystem. Values must match '/^\d+[[:alpha:][:digit:][:punct:][:space:]]+$/'.
In iptables, the title of the rule is stored using the comment feature of the underlying firewall subsystem. Values must match '/^\d+[[:graph:][:space:]]+$/'.

####Examples of Default Rules

Expand Down Expand Up @@ -546,7 +546,7 @@ firewall { '999 this runs last':
}
```

Depending on the provider, the name of the rule can be stored using the comment feature of the underlying firewall subsystem. Values must match '/^\d+[[:alpha:][:digit:][:punct:][:space:]]+$/'.
Depending on the provider, the name of the rule can be stored using the comment feature of the underlying firewall subsystem. Values must match '/^\d+[[:graph:][:space:]]+$/'.

* `outiface`: Output interface to filter on. Values must match '/^!?\s?[a-zA-Z0-9\-\._\+\:]+$/'. Requires the `interface_match` feature. Supports interface alias (eth0:0) and negation.

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/firewall/iptables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ def self.rule_to_hash(line, table, counter)
if ! hash[:name]
num = 9000 + counter
hash[:name] = "#{num} #{Digest::MD5.hexdigest(line)}"
elsif not /^\d+[[:alpha:][:digit:][:punct:][:space:]]+$/ =~ hash[:name]
elsif not /^\d+[[:graph:][:space:]]+$/ =~ hash[:name]
num = 9000 + counter
hash[:name] = "#{num} #{/([[:alpha:][:digit:][:punct:][:space:]]+)/.match(hash[:name])[1]}"
hash[:name] = "#{num} #{/([[:graph:][:space:]]+)/.match(hash[:name])[1]}"
end

# Iptables defaults to log_level '4', so it is omitted from the output of iptables-save.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
isnamevar

# Keep rule names simple - they must start with a number
newvalues(/^\d+[[:alpha:][:digit:][:punct:][:space:]]+$/)
newvalues(/^\d+[[:graph:][:space:]]+$/)
end

newproperty(:action) do
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/iptables/conversion_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,13 @@
},
:args => ['-t', :filter, '-s', '192.168.0.1/32', '-p', :tcp, '-m', 'comment', '--comment', '000 allow from 192.168.0.1, please'],
},
'comment_string_character_validation_2' => {
:params => {
:name => "000 allow symbols ( $+<=>^`|~ ) in ruby >= 1.9",
:table => 'filter',
},
:args => ['-t', :filter, '-p', :tcp, '-m', 'comment', '--comment', '000 allow symbols ( $+<=>^`|~ ) in ruby >= 1.9'],
},
'port_property' => {
:params => {
:name => '001 port property',
Expand Down

0 comments on commit 706bb3c

Please sign in to comment.