Relationships
#4779 @swamp/cfgmgmt firewall: pre-check edge cases (firewalld undo and old-version detection, iptables inherited comments)
Opened by stack72 · 11/15/2026· Shipped 11/15/2026
Follow-up to swamp-club #4776 (also #4774 and #4773). The @swamp/cfgmgmt firewall pre-checks added there have three edge cases, raised by the verification review and left for later.
1. firewalld undo can change a rule that was already in the permanent config. gather reads only the running rules (firewall-cmd --list-ports and --list-rich-rules without --permanent). Take a rule that is in the permanent config but not live, such as one added with --permanent and never reloaded. With ensure: present, apply runs firewall-cmd --permanent --add-port=80/tcp, firewalld warns ALREADY_ENABLED and exits 0. If --check-config then fails for an unrelated reason (another broken zone file), the undo runs --permanent --remove-port=80/tcp and removes a rule that was there before. The same happens the other way round for ensure: absent.
Possible fix: read the permanent config before the write (--permanent --query-port or --query-rich-rule) and undo only a change the write actually made.
2. firewalld treats any check failure mentioning an unknown option as an old firewalld. The test on the output of firewall-cmd --check-config is a regex for "unrecognized" or "unknown option". A firewalld that supports --check-config can still fail on a config file whose error text contains those words. That failure is then read as "this firewalld has no --check-config", and apply goes on to --reload a configuration that failed its check.
Possible fix: match the exact wording that means the option itself is missing (unrecognized arguments: --check-config), or test for the option first with firewall-cmd --help.
3. The iptables add pre-check can wrongly refuse a rule whose existing comment has quotes. iptablesRule builds the iptables-restore --test line with --comment "<comment>", which relies on the comment rule forbidding double quotes and backslashes. When the config sets no comment, the comment is taken from the matched rule on the host, which nothing checks. If that comment contains a double quote or backslash, the test line is malformed and the add is refused as "rejected the rule".
Possible fix: escape double quotes and backslashes in the restore form, or skip the inherited comment on an add, where it is never used.
Smaller items from the same review, worth fixing in the same pass:
- On the iptables backend, the own-session guard refuses removing a rule with no source or destination when the session is IPv6, though an IPv4 iptables rule cannot affect it. Only IPv4 and IPv4-mapped sessions should count there.
- In
_lib/ssh.ts, the comment describingPERMANENT_SSH_ERRORnow sits aboveDEAD_LINK_OPTS; move the new block above that comment. - The systemd settle test asserts the apply took under 3 s of wall-clock time; assert on the command text alone so a slow CI host cannot flake it.
Shipped
Click a lifecycle step above to view its details.
system commented 11/15/2026, 9:59:27 PM
Classified automatically when this issue was filed.
- Source: Extensions
If you feel this classification is incorrect, add a ripple to tell us so.
stack72 commented 11/15/2026, 10:18:12 PM
Triage note on item 3 (iptables add inheriting a host comment with quotes): this cannot happen. ruleDetails is set only when the wanted rule already exists, an add runs only when it does not, and the iptables-restore test line is built only for adds, so an add only ever carries the config's own comment, which the schema keeps free of quotes and backslashes. No code change; a test now pins that an add next to a rule with a quoted comment builds its test line from the config alone. Items 1, 2 and 4 and the two nits are fixed on branch 4779.
Sign in to post a ripple.