Skip to content

Fix table parsing with * in non-table names #1209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/firewall/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Puppet::Provider::Firewall::Firewall
'ip6tables' => 'ip6tables-save'
}
# Regex used to divide output of$list_command between tables
$table_regex = %r{(\*(?:nat|mangle|filter|raw|rawpost|broute|security)[^*]+)}
$table_regex = %r{(\*(?:nat|mangle|filter|raw|rawpost|broute|security)(?:[\s\S])+?)(?=^\*|\z)}
# Regex used to retrieve table name
$table_name_regex = %r{^\*(nat|mangle|filter|raw|rawpost|broute|security)}
# Regex used to retrieve Rules
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/firewallchain/firewallchain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Puppet::Provider::Firewallchain::Firewallchain
'IPv6' => 'ip6tables-save'
}
# Regex used to divide output of$list_command between tables
$table_regex = %r{(\*(?:nat|mangle|filter|raw|rawpost|broute|security)[^*]+)}
$table_regex = %r{(\*(?:nat|mangle|filter|raw|rawpost|broute|security)(?:[\s\S])+?)(?=^\*|\z)}
# Regex used to retrieve table name
$table_name_regex = %r{^\*(nat|mangle|filter|raw|rawpost|broute|security)}
# Regex used to retrieve Chains
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/puppet/provider/firewallchain/firewallchain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,18 @@
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [39:3092]
:TEST_ONE - [0:0]
COMMIT
-A TEST_ONE -p tcp -m comment --comment "001 test rule"
-A TEST_ONE -p tcp -m comment --comment "001 test * rule"
-A INPUT -p tcp -m comment --comment "004 test rule"
-A TEST_ONE -p tcp -m comment --comment "ignore_this foreign"
-A TEST_ONE -p tcp -m comment --comment "foreign"
COMMIT
# Completed on Thu Aug 10 10:15:14 2023
# Generated by iptables-save v1.8.4 on Thu Aug 10 10:15:14 2023
*raw
:PREROUTING ACCEPT [13222:23455532]
:OUTPUT ACCEPT [12523:852730]
COMMIT
-A OUTPUT -p tcp -m comment --comment "003 test rule"
COMMIT
# Completed on Thu Aug 10 10:15:14 2023
'
end
Expand All @@ -233,30 +233,30 @@
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [13:824]
:TEST_TWO - [0:0]
COMMIT
-A OUTPUT -p tcp -m comment --comment "005 test rule"
COMMIT
# Completed on Thu Aug 10 10:21:55 2023
*raw
:PREROUTING ACCEPT [13222:23455532]
:OUTPUT ACCEPT [12523:852730]
COMMIT
-A TEST_TWO -p tcp -m comment --comment "002 test rule"
COMMIT
# Completed on Thu Aug 10 10:21:55 2023
'
end

[
{
should: { name: 'TEST_ONE:filter:IPv4', purge: true, ensure: 'present' },
purge: ['001 test rule', '9003 ignore_this foreign', '9004 foreign']
purge: ['001 test * rule', '9003 ignore_this foreign', '9004 foreign']
},
{
should: { name: 'TEST_ONE:filter:IPv4', purge: true, ignore: 'ignore_this', ensure: 'present' },
purge: ['001 test rule', '9004 foreign']
purge: ['001 test * rule', '9004 foreign']
},
{
should: { name: 'TEST_ONE:filter:IPv4', purge: true, ignore_foreign: true, ensure: 'present' },
purge: ['001 test rule']
purge: ['001 test * rule']
},
{
should: { name: 'TEST_TWO:raw:IPv6', purge: true, ensure: 'present' },
Expand Down
Loading