An entry of ufw_rules may now carry delete: true (a boolean) to remove the rule it describes, through community.general.ufw's delete option. Until now the role could only add rules, so a consumer could not replace a base rule, for example narrow an open allow 22/tcp to an address range and an interface.
Behaviour
tasks/rules.yml applies delete entries after every other rule, whatever their place in the list, so a replacement exists before the rule it replaces goes.
A delete is sent without its comment. ufw matches a delete with no comment against the rule whatever its comment; a delete with a different comment matches nothing and exits 0, which would leave the rule silently.
tasks/validate.yml:
the schema check requires delete to be a boolean;
a new check refuses a rule that the list both adds and deletes. Fields are normalised as ufw stores them (no direction is in, incoming/outgoing are in/out, no from/to is any, port as a string); a missing proto stays distinct from tcp, as in ufw;
the SSH lock-out guard no longer counts a delete entry.
service_rules keeps its own key list and refuses delete; it already purges its own stale rules.
README: a delete without an address removes the IPv4 and IPv6 rule; an IPv4 from allows IPv4 only.
Tests
Molecule: prepare stores a 9091/tcp rule with a comment; the base list deletes it with an entry that has a different comment and is listed first; verify checks it is gone and the untagged count is unchanged; the idempotence pass covers deleting a rule that is already gone. Two new refusals: an SSH rule that is only deleted (lock-out guard) and a rule both added and deleted, written with explicit direction: in / from: any.
Verified
All pre-commit hooks and the pre-push ansible-test sanity.
validate.yml against localhost in check mode: a sample replacement list (an SSH allow from a source range, an SSH allow on a named interface, and a delete of plain allow 22/tcp) passes; the conflicts (plain, direction: in, from: any, direction: incoming), a delete-only SSH list and a non-boolean delete are refused; the apply order puts deletes last.
A subagent review. It found the two bugs fixed in the second commit: the conflict check missed direction: in / from: any spellings, and a delete with a differing comment did nothing. It read ufw 0.36.2's matching code for the comment behaviour.
Not verified
The molecule scenario (CI only), including the commented-rule delete on a real ufw.
An entry of `ufw_rules` may now carry `delete: true` (a boolean) to remove the rule it describes, through `community.general.ufw`'s `delete` option. Until now the role could only add rules, so a consumer could not replace a base rule, for example narrow an open `allow 22/tcp` to an address range and an interface.
## Behaviour
- `tasks/rules.yml` applies delete entries after every other rule, whatever their place in the list, so a replacement exists before the rule it replaces goes.
- A delete is sent without its comment. ufw matches a delete with no comment against the rule whatever its comment; a delete with a different comment matches nothing and exits 0, which would leave the rule silently.
- `tasks/validate.yml`:
- the schema check requires `delete` to be a boolean;
- a new check refuses a rule that the list both adds and deletes. Fields are normalised as ufw stores them (no `direction` is `in`, `incoming`/`outgoing` are `in`/`out`, no `from`/`to` is `any`, port as a string); a missing `proto` stays distinct from `tcp`, as in ufw;
- the SSH lock-out guard no longer counts a delete entry.
- `service_rules` keeps its own key list and refuses `delete`; it already purges its own stale rules.
- README: a delete without an address removes the IPv4 and IPv6 rule; an IPv4 `from` allows IPv4 only.
## Tests
Molecule: prepare stores a `9091/tcp` rule with a comment; the base list deletes it with an entry that has a different comment and is listed first; verify checks it is gone and the untagged count is unchanged; the idempotence pass covers deleting a rule that is already gone. Two new refusals: an SSH rule that is only deleted (lock-out guard) and a rule both added and deleted, written with explicit `direction: in` / `from: any`.
## Verified
- All pre-commit hooks and the pre-push `ansible-test sanity`.
- `validate.yml` against localhost in check mode: a sample replacement list (an SSH allow from a source range, an SSH allow on a named interface, and a delete of plain `allow 22/tcp`) passes; the conflicts (plain, `direction: in`, `from: any`, `direction: incoming`), a delete-only SSH list and a non-boolean `delete` are refused; the apply order puts deletes last.
- A subagent review. It found the two bugs fixed in the second commit: the conflict check missed `direction: in` / `from: any` spellings, and a delete with a differing comment did nothing. It read ufw 0.36.2's matching code for the comment behaviour.
## Not verified
- The molecule scenario (CI only), including the commented-rule delete on a real ufw.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
An entry with delete: true (a boolean) removes the rule it describes,
passed to community.general.ufw's delete option. It lets a consumer
replace a base rule, such as an open SSH allow by narrower ones, which
the role could only add before.
- rules.yml applies the delete entries after every other rule, whatever
their place in the list, so the replacement exists before the old rule
goes.
- validate.yml: the schema check requires a boolean; a new check refuses
a rule the list both adds and deletes (compared without the comment,
port as a string), because the delete would win while the lock-out
guard counted the add; the lock-out guard no longer counts a delete
entry.
- service_rules keeps its own key list and does not accept delete.
Molecule: prepare stores a commented 9091 rule that the base list deletes
with an uncommented entry listed first; verify checks it is gone and the
untagged count is unchanged; the idempotence pass covers deleting a rule
that is gone. Two new refusals: an SSH rule that is only deleted (lock-out
guard) and a rule both added and deleted.
Verified locally: validate.yml against localhost in check mode (the
planned replacement list passes; the conflict, the delete-only SSH list
and a non-boolean delete are refused) and the apply order. Not verified
locally: the molecule scenario (CI only), including whether ufw matches
the commented rule from an uncommented delete.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Review findings on the delete support:
- The both-added-and-deleted check compared the written fields, so
direction: in or from: any on the added rule hid a conflict that ufw
sees (it stores no direction as in and no address as any); the delete
then removed the SSH rule the lock-out guard had counted. Fields are now
normalised as ufw stores them (incoming/outgoing as in/out too). A
missing proto stays distinct from tcp, as in ufw.
- A delete sent with a comment that differs from the stored one matches
nothing in ufw and exits 0, so the rule stayed silently. Deletes are now
sent without their comment; ufw then matches the rule whatever its
comment. The scenario's delete entry carries a different comment to
cover it, and the conflict refusal uses the explicit defaults.
- README: a delete without an address removes the IPv4 and IPv6 rules,
an IPv4 from allows IPv4 only.
- verify searches 9091/tcp, not a bare 9091 that an owner tag could hold.
Verified locally in check mode against localhost: both bypass lists and
an incoming/outgoing spelling are refused; the planned replacement list
and a no-proto add with a tcp delete pass.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
An entry of
ufw_rulesmay now carrydelete: true(a boolean) to remove the rule it describes, throughcommunity.general.ufw'sdeleteoption. Until now the role could only add rules, so a consumer could not replace a base rule, for example narrow an openallow 22/tcpto an address range and an interface.Behaviour
tasks/rules.ymlapplies delete entries after every other rule, whatever their place in the list, so a replacement exists before the rule it replaces goes.tasks/validate.yml:deleteto be a boolean;directionisin,incoming/outgoingarein/out, nofrom/toisany, port as a string); a missingprotostays distinct fromtcp, as in ufw;service_ruleskeeps its own key list and refusesdelete; it already purges its own stale rules.fromallows IPv4 only.Tests
Molecule: prepare stores a
9091/tcprule with a comment; the base list deletes it with an entry that has a different comment and is listed first; verify checks it is gone and the untagged count is unchanged; the idempotence pass covers deleting a rule that is already gone. Two new refusals: an SSH rule that is only deleted (lock-out guard) and a rule both added and deleted, written with explicitdirection: in/from: any.Verified
ansible-test sanity.validate.ymlagainst localhost in check mode: a sample replacement list (an SSH allow from a source range, an SSH allow on a named interface, and a delete of plainallow 22/tcp) passes; the conflicts (plain,direction: in,from: any,direction: incoming), a delete-only SSH list and a non-booleandeleteare refused; the apply order puts deletes last.direction: in/from: anyspellings, and a delete with a differing comment did nothing. It read ufw 0.36.2's matching code for the comment behaviour.Not verified
🤖 Generated with Claude Code