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

Fix nftables module check function doesn't understand that braces are optional #67079

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nicholasmhughes
Copy link
Collaborator

What does this PR do?

See issue for details

What issues does this PR fix or reference?

Fixes #67078

Previous Behavior

See issue for details

New Behavior

The braces are effectively ignored for comparison purposes

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices, including the
PR Guidelines.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@nicholasmhughes nicholasmhughes requested a review from a team as a code owner November 29, 2024 20:52
Copy link
Contributor

@dmurphy18 dmurphy18 left a comment

Choose a reason for hiding this comment

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

Should use f-strings at this point.
Can you email [email protected] to discuss salt extensions too, since this PR has your attention and reaching out to you has failed so far.

BTW pipelines are under development, so it will be a while before they are running correctly, hopefully by the end of the week,

salt/modules/nftables.py Outdated Show resolved Hide resolved
)
search_rule = f"{rule} #"
out = __salt__["cmd.run"](cmd, python_shell=False).find(search_rule)
cmd = f"{_nftables_cmd()} --handle list chain {nft_family} {table} {chain}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove --numeric? While I don't think multiple --numeric args has any different effect, at least one does and is probably desired.

search_rule = f"{rule} #"
out = __salt__["cmd.run"](cmd, python_shell=False).find(search_rule)
cmd = f"{_nftables_cmd()} --handle list chain {nft_family} {table} {chain}"
search_rule = f"{rule} #".replace("{ ", "{? ?").replace(" }", " ?}?")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to be in the business of trying to parse and maintain the syntax of nftables rules. I suggest trying to find a way to have the tools canonicalize both rules. nft also has a --json flag to give json output which may also be cleaner/safer to handle.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are other things that would make the rules not normalized and therefore not match like extra whitespaces. Here is a list according to copilot:

Whitespace: Variations in spaces or tabs can impact rule formatting, although it generally doesn’t affect functionality.

Comments: Inline or separate comments within rules might not be present in the canonical form.

Ordering: The sequence of rules and attributes can differ.

Default actions: When default actions aren’t explicitly stated, different interpretations may arise.

Aliases: Using aliases for set names or interfaces may introduce variations.

Optional attributes: Omitting certain attributes might create differences.

Nesting: The manner and extent of nesting in expressions might vary.

cmd = f"{_nftables_cmd()} --handle list chain {nft_family} {table} {chain}"
search_rule = f"{rule} #".replace("{ ", "{? ?").replace(" }", " ?}?")
out = __salt__["cmd.run"](cmd, python_shell=False)
found = re.search(search_rule, out)
Copy link
Contributor

Choose a reason for hiding this comment

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

We did not escape the search_rule before using it as a regex so regex special characters like . and [ will not be treated as literal.

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

Successfully merging this pull request may close these issues.

[BUG] nftables module check function doesn't understand that braces are optional
3 participants