Fix firewall rule discovery so quoted values are not scanned as real iptables options.#1275
Closed
ashishrase wants to merge 1 commit intopuppetlabs:mainfrom
Closed
Conversation
3b535d0 to
3492bb8
Compare
12f08e3 to
55b1ed8
Compare
rule_to_hash scans raw iptables-save output with whole-line regexes. Quoted values such as comments can contain text like `-p -p`, which may be misread as a real protocol token and later surface as `Unsupported proto number: -p` during firewall rule discovery. Use a quote-stripped search copy of the rule for non-quoted attributes, while still parsing quoted attributes from the original rule. This fixes the parser at the source, preserves real protocol parsing, and keeps the existing `proto => all` fallback when no protocol is set. Add provider specs covering quoted `-p` / `! -p` comment text and the end-to-end `get` behavior.
55b1ed8 to
726bef0
Compare
Author
|
Need few more test to be done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix firewall rule discovery so quoted values are not scanned as real iptables options.
Today
rule_to_hashinlib/puppet/provider/firewall/firewall.rbparses the full rawiptables-saveline with regexes for most attributes. That means flag-like text inside quoted values, such as a comment containing-p -por! -p -p, can be misread as a real protocol flag. Once that happens,process_getreceives a malformedprotovalue and discovery can later fail withUnsupported proto number: -p.This change fixes the parser at the source by:
name,string,string_hex,bytecode,u32,nflog_prefix,log_prefix) from the original rule-p tcpproto => allfallback when no real protocol is presentAlso adds provider test coverage for:
-p -pdo not setproto! -p -pdo not setproto-p tcpoutside quotes still parses asproto => tcpgetreturnsproto => allwhen no real protocol is present and does not surface-p/! -pas protocol valuesAdditional Context
[ X ] Root cause and the steps to reproduce. (If applicable)
[ X ] Thought process behind the implementation.
Root cause / reproduction
On affected systems (Rancher Kubernetes),
iptables-saveoutput may include quoted comment text containing flag-like tokens such as-p -p. Becauserule_to_hashscans the full raw rule line, that quoted text can be mistaken for a real protocol option and stored asproto => '-p'. Later in the discovery pipeline this can surface as:Unsupported proto number: -p
This can cause
Puppet::Type.type(:firewall).instancesto fail during rule discovery.Thought process behind the implementation
The goal of this change is to fix the root cause in the provider parser rather than make downstream protocol conversion more tolerant of malformed intermediate values.
process_getalready handles a missing protocol by defaulting toall, so the correct fix is to stoprule_to_hashfrom manufacturing invalid protocol values in the first place. Using a quote-stripped search copy for non-quoted attributes keeps the parser behavior intact for real rule options while preventing quoted comment text from being interpreted as flags.Related Issues (if any)
No linked issue yet.
Checklist
[ X ] 🟢 Spec tests.
[ ] 🟢 Acceptance tests:
Acceptance tests were not run locally because Docker/Litmus provisioning is not available in my environment.
[ X ] Manually verified. (For example
puppet agent -ton an affected system)