-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
iptables: adjust run scripts for more configuration flexibility #31145
Conversation
@the-maldridge Relevant to your interests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also introduces a behavior change in that the service will now always enter OK state if no rules are present. This is a pretty serious change to make to the firewall, so it either needs to be justified or reverted.
8959846
to
d3f94da
Compare
Run scripts updated to exit without any rules loads. I don't consider the previous behavior of exiting 0 on incorrect use to be good form so I've updated the exit code. Either way the finish scripts shipped here don't care about $1 so this is a behavior change with no impact. |
I generally dislike splitting config files over those My only two other comments would be: The naming of the Also, why not just |
Actually |
The void-infratructure project and the void-ansible-roles/network subproject uses blah.d directories and a dhcpcd hook script to assemble a composite firewall definition out of rules dropped into .d directories. My goal here is to move that logic out of a custom ansible-managed set of scripts and into the iptables package itself in order to have a cleaner migration path away from dhcpcd as the network manager for static addressed hosts.
I don't have an opinion either way, if this is something you feel strongly about it's a fairly trivial change.
You already noted the
In the previous iteration this was handled by the single file check but you can't rely on that now since I'm trying to support rules in either or both locations. Similarly, switching to bash and pipefail doesn't work because cat will exit 1 if any input file doesn't exist, which will be the case for installs that only use iptables.rules (all classic installs). The only way to get the behavior I want is to set errexit and nullglob in bash, and then call the pipeline with timeout in order to catch a null-read in the case where no rules files exist. I consider that a heavier and harder to read change than an accumulator, though I will admit that Let me know about how you feel on rule vs. ruleset, and if you have a better approach to glob-based file detection in dash. The best I can come up with is a loop and (if necessary) accumulator but there might be something I'm missing. |
The single configuration file approach that the iptables services provide precludes using it in more complicated buildouts such as ones defined with config management tools. This change takes a hybrid approach of the old method (to preserve backwards compatibility, etc) and the method taken with void-ansible-roles/network. Changes: No longer flush tables prior to loading new data - rely on finish in all cases Load data from /etc/iptables/iptables.rules and all found /etc/iptables.d/*.rules Ditto ip6 equivalents (ip6rules.rules, ip6tables.d/*.{,6}rules) Flush nat table in both v4 and v6 mode (nat table supported on v6 since kernel 3.7) No-rule bailouts are handled with a post-load accumulator instead of exiting entirely when a rules file doesn't exist. The run script uses exit code `2' in that case to differentiate between a failed load and wrong use Caveats: the ip6tables.d match is overly explicit since dash does not provide brace expansion and there is no particularly clean way to match a single character or empty when expanding globs.
The variable should probably be named 'fragment' and in general I think there's also a case here in the fragment case that isn't being checked, which is that if iptables-restore fails for any fragment that should abort the load. |
|
We probably also need to flush everything in case a fragment fails, since it may leave the ruleset in an undesirable state, and also subsequent sv starts/restores will end up duplicating ruleset entries. |
That will happen, runsv always runs the finish script after run exits, regardless of reason. |
@ailiop-git do you have any other unaddressed concerns? @the-maldridge can you drop the Change Requested flag and merge if there are no other issues from myself or ailiop? I think I've addressed everything. |
Putting this on hold while I think about the best path to the final state. Should have done this like two weeks ago but... |
Pull Requests become stale 90 days after last activity and are closed 14 days after that. If this pull request is still relevant bump it or assign it. |
The single configuration file approach that the iptables services
provide precludes using it in more complicated buildouts such as ones
defined with config management tools. This change takes a hybrid
approach of the old method (to preserve backwards compatibility, etc)
and the method taken with void-ansible-roles/network.
Changes:
No longer flush tables prior to loading new data - rely on finish in all
cases
Load data from /etc/iptables/iptables.rules and all found
/etc/iptables.d/*.rules
Ditto ip6 equivalents (ip6rules.rules, ip6tables.d/*.{,6}rules)
Flush nat table in both v4 and v6 mode (nat table supported on v6 since
kernel 3.7)
Caveats: the ip6tables.d match is overly explicit since dash does not
provide brace expansion and there is no particularly clean way to match
a single character or empty when expanding globs.
@ailiop-git
General
Have the results of the proposed changes been tested?
Does it build and run successfully?
(Please choose at least one native build and, if supported, at least one cross build. More are better.)