Open
Description
If the firewall type source
has a prefix length of zero, Puppet attempts to correct the source on every run.
Environment details
- Puppet version: 7.28.0
- OS: Rocky Linux 8.9
- Module version: 7.0.2
Steps to reproduce:
# puppet resource firewall '000 allow icmp from all' proto=icmp source=0.0.0.0/0
Notice: /Firewall[000 allow icmp from all]/source: source changed to '0.0.0.0/0'
Notice: firewall[000 allow icmp from all]: Updating: Updating Rule '000 allow icmp from all' with {:name=>"000 allow icmp from all", :source=>nil, :proto=>"icmp", :ensure=>"present", :protocol=>"IPv4", :table=>"filter", :chain=>"INPUT"}
Notice: firewall[000 allow icmp from all]: Updating: Ensuring changes to '000 allow icmp from all' persist
Notice: firewall[000 allow icmp from all]: Updating: Finished in 0.819169 seconds
firewall { '000 allow icmp from all':
proto => 'icmp',
ensure => 'present',
protocol => 'IPv4',
table => 'filter',
chain => 'INPUT',
}
# puppet resource firewall '000 allow icmp from all' proto=icmp source=0.0.0.0/0
Notice: /Firewall[000 allow icmp from all]/source: source changed to '0.0.0.0/0'
Notice: firewall[000 allow icmp from all]: Updating: Updating Rule '000 allow icmp from all' with {:name=>"000 allow icmp from all", :source=>nil, :proto=>"icmp", :ensure=>"present", :protocol=>"IPv4", :table=>"filter", :chain=>"INPUT"}
Notice: firewall[000 allow icmp from all]: Updating: Ensuring changes to '000 allow icmp from all' persist
Notice: firewall[000 allow icmp from all]: Updating: Finished in 0.844126 seconds
firewall { '000 allow icmp from all':
proto => 'icmp',
ensure => 'present',
protocol => 'IPv4',
table => 'filter',
chain => 'INPUT',
}
...
Additional Information
When Puppet checks if source
is in sync, it immediately returns nil because is
is nil
:
puppetlabs-firewall/lib/puppet/provider/firewall/firewall.rb
Lines 328 to 329 in 403fed3
But when Puppet goes to apply the changes, it modifies the
should
to be nil
because of the zero prefix length:puppetlabs-firewall/lib/puppet/provider/firewall/firewall.rb
Lines 871 to 873 in 403fed3
puppetlabs-firewall/lib/puppet_x/puppetlabs/firewall/utility.rb
Lines 89 to 90 in 403fed3
Potential Fix
Allow the insync?
method to process the source
and destination
parameters before comparing so zero prefix length values become nil:
--- lib/puppet/provider/firewall/firewall.rb 2024-02-02 12:46:57.759555325 -0600
+++ lib/puppet/provider/firewall/firewall.rb.patched 2024-02-02 13:10:22.039261534 -0600
@@ -326,6 +326,6 @@
context.debug("Checking whether '#{property_name}' is out of sync")
- # If either value is nil, no custom logic is required
- return nil if is_hash[property_name].nil? || should_hash[property_name].nil?
+ # If either value is nil, no custom logic is required unless property is source or destination
+ return nil if (is_hash[property_name].nil? || should_hash[property_name].nil?) && ! [:source, :destination].include?(property_name)
case property_name
Activity
corporate-gadfly commentedon Mar 12, 2024
With Puppet 8.5.1, and module 8.0.0, firewall rules were not idempotent as well.
To compensate, wherever
state
was used, I had to replace:with
In addition, anywhere where I had used ranges in
sport
ordport
, I had to replace-
with:
, e.g.:with
After that, firewall rules were idempotent. In that regards PR #1189 was not necessary, in my case.
Hope that helps someone.
corporate-gadfly commentedon Mar 13, 2024
firewallchain resources with Puppet 8.5.1 and module version 8.0.0 are behaving non-idempotent for me, at the moment.
To reproduce, try:
corporate-gadfly commentedon Mar 13, 2024
Here is the difference in debug output when executing:
With firewall v6.0.0:
With firewall v8.0.0:
corporate-gadfly commentedon Mar 26, 2024
@Ramesh7 : Any chance this issue can be looked at? I'm not sure how specs work in this module, but shouldn't
idempotent_apply
calls catch these issues?Ramesh7 commentedon May 24, 2024
Hey @corporate-gadfly, sorry for delay in response, I will have look in upcoming week on idempotent_apply.
Ramesh7 commentedon May 28, 2024
Hi @corporate-gadfly, I have tried on RHEL/Ubuntu and was able to reproduce the issue with given steps. Have dig more into that and here is my observations :
ip(6)tables-save
command to check the current set of chainsfirewallchain
resource converging (applying) it checks for current state, as the command returns no output so it assumes the chains are absent and it tries to create it on every run.Later I tried to create a random chain and re-run the
iptables-save
command, it return respective table's chain :After creating custom chain tried running same command :
Then tried rerunning same manifest which turn out to be idempotent :
Later I tried same on CentOS where have observed things are working as expected.
Conclusion :
ip(6)tables-save
misleading the current state of machine because of that firewallchain tries to create it and makesfirewallchain
resource non-i idempotentPlease let me know if any questions or thoughts?
Thanks
nabertrand commentedon May 28, 2024
@Ramesh7 thanks for looking into this, but I don't think @corporate-gadfly's
firewallchain
issue is related to the original PR issue of zero-prefix-lengthsource
ordestination
parameters onfirewall
resources causing the resource to be corrected on every agent run. Just wanted to make sure the original issue was also being looked into.trevorrea commentedon Jun 13, 2024
@Ramesh7 Is there any update on this please? As per what @nabertrand said above this issue is separate to the issue that was fixed at #1206
trevorrea commentedon Oct 3, 2024
I tested the latest version of 8.x today and this issue is still occurring. Can it be looked at and fixed please? There's an MR at #1189
corporate-gadfly commentedon Oct 4, 2024
Coming back to this issue, which still exists in the 8.x versions on Ubuntu 22, I asked, horror of all horrors, ChatGPT if there was a way to have the rules in the default tables show up.
The helpful hint was to add placeholder rules and then remove them. E.g.:
followed by:
After this,
iptables-save
showed me bothfilter
andnat
tables in the output.Now, I know zilch about the
nat
tables, let alone the chains and the default rules inside them. Could someone more knowledgeable comment on the above hint.Also, for reference, there is a netfilter bugzilla which mentions the sparseness of
iptables-save
with respect to default tables.trevorrea commentedon Oct 4, 2024
I did this as a workaround (I only have a few rules so it's not a big deal)
3 remaining items