Skip to content

netns-isolation: check the firewall package the netns rules run with - #175

Merged
seberm merged 4 commits into
bitcoinix:masterfrom
ostermayer:netns-firewall-package
Oct 29, 2026
Merged

seberm merged 4 commits into
bitcoinix:masterfrom
ostermayer:netns-firewall-package

Conversation

@ostermayer

@ostermayer ostermayer commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #169.

The assertion from #169 checked networking.firewall.backend only. In the pinned nixpkgs networking.firewall.package follows networking.nftables.enable, not the backend, so a host with nftables enabled and the backend set to "iptables" by hand passed evaluation and still ran the netns rules with the nftables package. That package has no iptables binary, so nb-netns-bridge failed and every netns service stayed down. The assertion message even suggested that setting, since it said to make the firewall use the iptables backend.

What changed:

  • The assertion checks the package the rules run with: the backend must be iptables and networking.firewall.package must not be the nftables package. An explicit networking.firewall.package = pkgs.iptables next to nftables provides the binary and passes, so an operator who keeps the iptables firewall and adds separate nftables tables isn't locked out.
  • The message says what the package is and names the override as the second way out. It still ends with "uses the iptables backend and package".
  • Two configuration checks: nftables on plus networking.firewall.backend = "iptables" must fail with the message, and the same plus networking.firewall.package = pkgs.iptables must evaluate without a failed assertion.

Tested

  • Evaluation on my KVM host against the pinned nixpkgs: with nftables on and the backend set to iptables, master gives firewall.package = nftables-1.1.6 and no failed assertion. This branch fails the assertion. With the package set to pkgs.iptables the branch evaluates clean, with firewalld it fails, with nftables alone it fails as before.
  • module-config builds on this branch. With only the tests added, master fails testNetnsRejectsNftablesWithIptablesBackend.
  • nix flake check and the VM scenarios run in CI.

DeepSeek V4.1 Flash 1017 (max) found this in a full-tree audit of master right after #169 merged, and Codex (GPT-6 Astra, xhigh) confirmed it by evaluation against the pinned nixpkgs. Codex then reviewed the fix twice: the first commit refused every nftables host, which also rejects the explicit pkgs.iptables override, so the second commit checks the package by name instead, and the third names the backend in the message's override hint after Codex pointed out that the package alone isn't enough. GLM 5.3 (max) audited the tree at a05494a and 38b1155 with Astra as the second opinion: three findings on the first, none on the second, nothing in the two files this PR touches. The three are #133, #153 (Astra calls it a false positive and points at #66 instead) and an info note that RTL writes its config with the default umask. The third commit changes message text only, so I didn't rerun it.

…bles

The assertion from bitcoinix#169 checked networking.firewall.backend only.
networking.firewall.package follows networking.nftables.enable, not the
backend, so a host with nftables enabled and the backend set to
"iptables" by hand passed evaluation and still ran the netns rules with
the nftables package, which has no iptables binary. The bridge unit
failed and every netns service stayed down.

Check networking.nftables.enable as well and add the configuration test
for that combination.
…witch

An explicit networking.firewall.package = pkgs.iptables next to an
enabled nftables provides the binary the netns rules need, so refusing
every nftables host was too strict. Reject the nftables package by name
and accept any other package with the iptables backend. A test covers
the explicit override.
The message offered the package override alone, but with nftables
enabled the backend still defaults to nftables, so the override needs
networking.firewall.backend = "iptables" next to it.
@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: modules modules/ and pkgs/lib.nix labels Oct 28, 2026

@seberm seberm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

utACK

@viberaven viberaven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No actionable findings at c7b7d42.

Confirmed the pinned nixpkgs firewall package default follows networking.nftables.enable independently of the selected backend. Three focused Nix evaluations passed: nftables alone is rejected, nftables with the iptables backend but the default package is rejected, and explicitly selecting both the iptables backend and pkgs.iptables passes assertions.

Validation was limited to source review and focused evaluation; the full module suite was not completed locally, and VM tests were not run because /dev/kvm is unavailable.

Review performed with Codex (GPT-6 Astra).

@sebsgent sebsgent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK c7b7d42

Reviewed the diff and tested locally against the pinned nixpkgs (x86_64-linux; no KVM here, so no VM run):

  • module-config passes on c7b7d42 and on c7b7d42 merged into current master (abd56ed). With only the new tests on master, testNetnsRejectsNftablesWithIptablesBackend fails, so the test catches the bug.
  • Evaluated the assertion over a small matrix (bitcoind + netns-isolation). Rejected: nftables alone, nftables + backend = "iptables" with the default package, pkgs.iptables with the nftables backend, firewalld. Accepted: the default, networking.firewall.enable = false, nftables + backend = "iptables" + pkgs.iptables or pkgs.iptables-legacy. In every case the verdict matches whether ${networking.firewall.package}/bin/iptables exists.
  • The system toplevel .drv is identical to master for both the default and the explicit-override config, so the change is eval-only and can't alter a working node (and explains the cached, skipped test_scenario).

Non-blocking:

  • The name check is a denylist: a differently named package without bin/iptables still evaluates and then fails at runtime. That fails closed (netns services stay down, nothing gets exposed), so fine as is.
  • For the override path the message now suggests: if the host also sets networking.nftables.ruleset/rulesetFile, nixpkgs defaults networking.nftables.flushRuleset to true, and the flush ruleset on an nftables reload also drops the iptables-nft tables, i.e. the host firewall and the nb-br MASQUERADE rule, until firewall.service restarts. That's from reading nixpkgs, not tested. Maybe worth a docs sentence or a follow-up, not this PR.

Before merge: the description says DeepSeek, Codex and GLM found the bug and drove two revisions, but none of the commits has the Assisted-by: trailer that AGENTS.md requires. It can be added in the squash-merge message.

Review performed with Claude Code (Claude Opus 5.5).

@seberm
seberm enabled auto-merge October 29, 2026 09:20
@seberm
seberm merged commit 033fa1c into bitcoinix:master Oct 29, 2026
11 checks passed
@ostermayer
ostermayer deleted the netns-firewall-package branch November 8, 2026 22:18
prusnak added a commit that referenced this pull request Nov 10, 2026
…ded (#188)

The WireGuard preset binds the REST ports of the enabled `*connect`
helpers to 0.0.0.0 and guards them, and `restrictPeer`, only through
`networking.firewall.extraCommands`. Its assertion required the iptables
backend, but some layouts pass that check and still end with no
firewall. This is the same kind of gap #175 closed for netns-isolation.

What changed, one commit on current master:

- **Package check.** `networking.firewall.package` defaults to
`pkgs.nftables` whenever `networking.nftables` is enabled, whatever the
backend says. The firewall service then has no `iptables` binary and
fails at its first rule. The assertion now rejects the nftables package
unless `networking.firewall.extraPackages` holds iptables, which the
service also puts on its PATH.
- **flushRuleset check.** `pkgs.iptables` is iptables-nft, so the rules
live in the nftables ruleset. With `networking.nftables.flushRuleset`,
every start or reload of `nftables.service` runs `flush ruleset` and
deletes them while `firewall.service` stays active. NixOS turns it on by
default when `ruleset` or `rulesetFile` is set or `system.stateVersion`
is older than 23.11. A separate assertion rejects it and points to
`networking.nftables.tables` with `flushRuleset = false`.
- **Table name check.** `nftables.service` deletes and recreates every
table in `networking.nftables.tables`. A table named `filter` in the
`ip` or `ip6` family is the one iptables-nft keeps `nixos-fw` in, so
that's rejected too. `inet filter` still passes. Raw `flush` or `delete`
lines in `ruleset`, `rulesetFile` or `extraDeletions` aren't checked.
- The messages say to restart `firewall.service` once after a fix, since
the first nftables reload still runs the old deletions file.
- `docs/services.md` lists the preset's firewall requirements in the
WireGuard setup step.
- Configuration checks: nftables with the iptables backend fails, the
iptables package or `extraPackages` passes, `ruleset` set fails,
`system.stateVersion = lib.mkForce "23.05"` fails, tables only passes,
an `ip filter` table fails.

## Tested

- `module-config` on my KVM host on top of master: 67 tests pass. With
master's preset and the new tests, the four rejection tests fail. With
the previous PR head's preset, the `ruleset` and `stateVersion` tests
fail.
- In the pinned nixpkgs, `nftables.nix` sets the `flushRuleset` default
to `mkDefault (versionOlder stateVersion "23.11" || rulesetFile != null
|| ruleset != "")`, and recreates each table in `tables` on reload.
- The `wireguard-lndconnect` VM scenario passes.

DeepSeek V4.1 Flash 1017 (max) found the package gap in the gate runs on
#170 and #184 and Codex (GPT-6 Astra, xhigh) confirmed it both times.
@sebsgent found the flushRuleset hole. Claude Opus 5.5 wrote this
version. Codex (GPT-5.6 Sol, xhigh) reviewed it in two passes and found
two real issues: the `ip filter` table clash, and that the first reload
after a fix still applies the old deletions. Both are in. Its point that
any package not named `nftables` passes is by design, the same check as
#175. DeepSeek V4.1 Flash 1017 (max) and GLM 5.3 (max) audited the tree
at 1cea5a7 with Codex (GPT-6 Astra, xhigh) as the second opinion: seven
findings, none in the files this PR touches. They're in RTL, mempool
settings, the shared Tor SOCKS port and the netns source filter, and
Astra marked the three netns ones false positives.

netns-isolation has the same flushRuleset and table-name hole: a flush
deletes `nb-netns-bridge`'s MASQUERADE rule and the host's `nixos-fw`,
while the per-namespace rules survive. That's a separate PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: modules modules/ and pkgs/lib.nix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants