Skip to content
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

Force firewall chain delete #1104

Merged
merged 1 commit into from Jun 14, 2023
Merged

Force firewall chain delete #1104

merged 1 commit into from Jun 14, 2023

Conversation

cruelsmith
Copy link
Contributor

@cruelsmith cruelsmith commented Jan 2, 2023

Flush chain to get rid of unmanaged firewall rules in that chain else the remove of the chain will fail.


This PR fixes #1064 where you want to ensure that all unmanaged firewall chains and rules are removed but still want to be able to whitelist unmanaged rules of a chain via ignore or ignore_foreign.
Code to reproduce:

resources { 'firewallchain':
  purge => true,
}

firewallchain { 'INPUT:filter:IPv4':
  purge  => true,
  ignore => [
    '-j fail2ban-', # ignore the fail2ban jump rule
  ],
}

firewallchain { 'fail2ban-sshd:filter:IPv4':
  purge          => true,
  ignore_foreign => true, # ignore not puppet managed rules in this chain
}

Note: A additional resources { 'firewall': purge => true } is not allowed here in this case because firewall will else remove the normally ignored rules by firewallchain.

> puppet agent -t
> iptables -N test
> iptables -I test -j RETURN
> puppet agent -t

With this change the second puppet run will not fail and remove every unmanaged chain like this 'test' chain.

Note: If there is still a reference from a rule outside of the chain that should be removed the puppet resource will fail until this reference has been removed. That means there could be still cases where multiple puppet runs are needed.


Fixes #1064

@cruelsmith cruelsmith requested a review from a team as a code owner January 2, 2023 16:17
@CLAassistant
Copy link

CLAassistant commented Jan 2, 2023

CLA assistant check
All committers have signed the CLA.

Flush chain to get rid of unmanaged firewall rules in that chain
else the remove of the chain will fail.
Copy link
Member

@david22swan david22swan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@david22swan david22swan merged commit b593518 into puppetlabs:main Jun 14, 2023
1 check passed
@david22swan
Copy link
Member

Thx for the fix, noticed this a while back but never got around to doing it myself.

@pskopnik
Copy link

Thanks @cruelsmith!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Purge rules in firewallchain before removing chain (iptables)
5 participants