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

Add support for parsing and using --tcp-option #1126

Merged
merged 6 commits into from Jun 21, 2023

Conversation

greatflyingsteve
Copy link
Contributor

@greatflyingsteve greatflyingsteve commented May 11, 2023

As it says on the tin. Also untangles the snarl of logic around --tcp-flags, previously the only stand-alone option to the 'tcp' match extension (portspecs are treated specially). --tcp-flags was trying to eat the -m tcp in its match, which because it falls after --tcp-option in the iptables-save output if both are present, causes a whole lot of trouble in recognizing that one or the other is present. It turns out to be simpler instead just to strip -m tcp and -m udp out of the lines entirely and parse based on that, which works reliably. Testing shows that a match extension for a protocol can never be loaded when a different protocol (including multiple protocols that include the correct protocol, e.g. -p all or ! -p icmp) is specified, so there is no way for a rule containing -p tcp -m udp to ever appear in the output of iptables-save.

As an added bonus, also fixes the configuration for the Metrics/BlockLength cop, so that the max block length doesn't need to be constantly hand-incremented each time the Firewall type is given new features.

Additional info in the commit messages, but please ask about anything I forgot to include or messed up!

Resolves #1124

@greatflyingsteve greatflyingsteve requested a review from a team as a code owner May 11, 2023 06:54
@puppet-community-rangefinder
Copy link

firewall is a type

Breaking changes to this file WILL impact these 125 modules (exact match):
Breaking changes to this file MAY impact these 154 modules (near match):

This module is declared in 106 of 580 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

Rubocop's maximum value for allowed block length needs to be incremented
by hand each time the 'firewall' type gains a new feature, because the
maximum block length is hand-tuned to the size of that 'newtype' block.
Having the 'Metrics/BlockLength' cop instead ignore lengths for the
'newtype' and 'provider' methods (which inherently have very long
blocks) instead solves the problem for all 'newtype' and 'provider'
blocks at one fell swoop, and with addition of one inline disable
comment for the 'validate' block in the 'firewall' type, means all
remaining block length warnings are squelched by a max value of only 64
lines.
Add the ability to parse iptables rules we encounter that include the
'--tcp-option' flag, instead of issuing a "Skipping unparseable
iptables rule" warning.  Every Firewall resource requires a full parse
of all rules, and the warning appears each time the problem rule is
parsed; therefore these warning messages are noisy (especially on long
rule sets), and there is no way to work around this, make the parser
ignore the rule, or create other rules with Puppet in any order aside
from "above the unparseable rule."
Add support (and unit tests) for creating rules that use iptables'
'--tcp-option' flag to match the presence or non-presence of numbered
TCP options.  Remove special casing from '--tcp-flags', previously the
only argument from the TCP match extension other than '--dport' and
'--sport', and have the TCP match extension treated as a module only
during rule assembly, because due to its inconsistent usage in
iptables-save output when multiport portspecs are used, '-m tcp' or
'-m udp' will throw off parsing badly if preset.

Resolves puppetlabs#1124
Move tests for the ip6tables provider into the ip6tables provider unit
test file.  Even if it's subclassed from iptables, it should be
reasonable to expect running all tests in the ip6tables provider's
tests file to include all tests for the ip6tables provider.  Also update
several test definitions that had fallen out of sync with the iptables
provider's test framework so the test cases for ip6tables are also no
longer sensitive to specific hash order and stringified 'true'.
Provide the same support for rule parse and create for IPv6 as the
previous commit provided for IPv4
Copy link
Contributor

@LukasAud LukasAud left a comment

Choose a reason for hiding this comment

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

LGTM

@LukasAud LukasAud merged commit 9438275 into puppetlabs:main Jun 21, 2023
38 checks passed
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.

puppetlabs-firewall confused by --tcp-option
3 participants