fix(ufw): mask nftables.service so an upgrade cannot flush the rules #522

Merged
Defame1297 merged 1 commits from fix/ufw-mask-nftables into main 2026-12-06 07:52:10 +00:00
Owner

What and why

When nftables.service is enabled (Ubuntu container templates enable it by default), the nftables package's postinst restarts it on upgrade. The stock /etc/nftables.conf begins with flush ruleset, so every rule ufw and Docker had loaded is deleted, and the host runs without its firewall until they reload.

The ufw role now masks the unit without stopping it, because the unit's ExecStop flushes too. The mask applies when the role enables ufw, and a new opt-out input, ufw_mask_nftables, turns it off. The fragment warns that a host loading its own ruleset through nftables.service must opt out before upgrading.

Closes nothing: there is no Kamino issue for this.

Verified

  • The pre-commit hooks passed on the commit.
  • Package scripts (noble 1.0.9 and resolute 1.1.7) and the systemd, debhelper and init-system-helpers sources were read; the commit message gives the mechanism.
  • By hand on real Ubuntu 24.04 hosts: after a manual systemctl mask, upgrading nftables left every ufw and Docker rule in place, and after a reboot the unit stayed inactive while ufw and Docker loaded their rules.
  • Molecule: the new verify play reinstalls the package with the unit masked and checks that ufw's chains survive. A control case without the mask checks that they are flushed. See this pull request's CI run.

Not verified

  • ufw_mask_nftables: false, and Docker's rules in molecule (the scenario has no Docker).
  • apt remove nftables with the unit masked. By reading the source no flush happens, but that is not tested.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code:claude-opus-5-5

## What and why When `nftables.service` is enabled (Ubuntu container templates enable it by default), the `nftables` package's postinst restarts it on upgrade. The stock `/etc/nftables.conf` begins with `flush ruleset`, so every rule ufw and Docker had loaded is deleted, and the host runs without its firewall until they reload. The `ufw` role now masks the unit without stopping it, because the unit's `ExecStop` flushes too. The mask applies when the role enables ufw, and a new opt-out input, `ufw_mask_nftables`, turns it off. The fragment warns that a host loading its own ruleset through `nftables.service` must opt out before upgrading. Closes nothing: there is no Kamino issue for this. ## Verified - The pre-commit hooks passed on the commit. - Package scripts (noble 1.0.9 and resolute 1.1.7) and the systemd, debhelper and init-system-helpers sources were read; the commit message gives the mechanism. - By hand on real Ubuntu 24.04 hosts: after a manual `systemctl mask`, upgrading `nftables` left every ufw and Docker rule in place, and after a reboot the unit stayed inactive while ufw and Docker loaded their rules. - Molecule: the new verify play reinstalls the package with the unit masked and checks that ufw's chains survive. A control case without the mask checks that they are flushed. See this pull request's CI run. ## Not verified - `ufw_mask_nftables: false`, and Docker's rules in molecule (the scenario has no Docker). - `apt remove nftables` with the unit masked. By reading the source no flush happens, but that is not tested. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code:claude-opus-5-5
Claude added 1 commit 2026-12-05 22:39:34 +00:00
fix(ufw): mask nftables.service so an upgrade cannot flush the rules
Build / build (pull_request) Successful in 33s
Molecule / select (pull_request) Successful in 2s
Lint / lint (pull_request) Successful in 4m5s
Molecule / scenarios (pull_request) Successful in 12m51s
Molecule / Result (pull_request) Successful in 0s
c617bee02a
When nftables.service is enabled, the nftables package's postinst
restarts it on upgrade. The stock /etc/nftables.conf begins with
`flush ruleset` and the unit's ExecStop flushes too, so every rule ufw
and Docker loaded was deleted until they reloaded.

The role now masks the unit without stopping it, gated on ufw_enabled
and the new opt-out input ufw_mask_nftables. systemd refuses every job
but a stop on a masked unit, so the postinst's try-restart fails
before anything runs (the postinst ignores the failure) and the unit
does not start at boot. Masking works when the unit is absent too.

Assisted-by: Claude Code:claude-opus-5-5
Defame1297 merged commit 9dba48a30d into main 2026-12-06 07:52:10 +00:00
Defame1297 deleted branch fix/ufw-mask-nftables 2026-12-06 07:52:11 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#522