Fix: Re-apply custom firewall post-rules after VPN reconnection and rule updates #2821
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using custom firewall post-rules in
/iptables/post-rules.txt
, these rules are only applied during the initial firewall setup but are not re-applied when:This causes custom rules to be lost during normal operation, requiring manual re-application of rules (e.g., via SSH or exec into the container).
Solution
This PR adds a helper method
applyUserPostRules()
and ensures it's called after any significant firewall rule changes in:SetVPNConnection()
in vpn.goSetAllowedPort()
in ports.goSetOutboundSubnets()
in outboundsubnets.goThe changes are minimal and follow the existing code patterns.
Testing
I've tested this fix with a custom Gluetun setup using WireGuard and the following scenario:
/iptables/post-rules.txt
to allow specific trafficiptables -L
that rules remain in place after reconnection eventsUse Case
This is particularly important for users who:
Changes
applyUserPostRules()
helper method in firewall.goSetVPNConnection()
to re-apply post-rules after VPN changesSetAllowedPort()
to re-apply post-rules after port changesSetOutboundSubnets()
to re-apply post-rules after subnet changesrunUserPostRules()
(optional)