Repository navigation
netns-isolation: check the firewall package the netns rules run with - #175
Conversation
…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.
viberaven
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
ACK c7b7d42
Reviewed the diff and tested locally against the pinned nixpkgs (x86_64-linux; no KVM here, so no VM run):
module-configpasses on c7b7d42 and on c7b7d42 merged into current master (abd56ed). With only the new tests on master,testNetnsRejectsNftablesWithIptablesBackendfails, 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.iptableswith the nftables backend, firewalld. Accepted: the default,networking.firewall.enable = false, nftables +backend = "iptables"+pkgs.iptablesorpkgs.iptables-legacy. In every case the verdict matches whether${networking.firewall.package}/bin/iptablesexists. - The system toplevel
.drvis 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, skippedtest_scenario).
Non-blocking:
- The name check is a denylist: a differently named package without
bin/iptablesstill 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 defaultsnetworking.nftables.flushRulesetto true, and theflush ruleseton an nftables reload also drops the iptables-nft tables, i.e. the host firewall and thenb-brMASQUERADE rule, untilfirewall.servicerestarts. 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).
…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.
Follow-up to #169.
The assertion from #169 checked
networking.firewall.backendonly. In the pinned nixpkgsnetworking.firewall.packagefollowsnetworking.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, sonb-netns-bridgefailed 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:
iptablesandnetworking.firewall.packagemust not be the nftables package. An explicitnetworking.firewall.package = pkgs.iptablesnext to nftables provides the binary and passes, so an operator who keeps the iptables firewall and adds separate nftables tables isn't locked out.networking.firewall.backend = "iptables"must fail with the message, and the same plusnetworking.firewall.package = pkgs.iptablesmust evaluate without a failed assertion.Tested
firewall.package = nftables-1.1.6and no failed assertion. This branch fails the assertion. With the package set topkgs.iptablesthe branch evaluates clean, with firewalld it fails, with nftables alone it fails as before.module-configbuilds on this branch. With only the tests added, master failstestNetnsRejectsNftablesWithIptablesBackend.nix flake checkand 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.iptablesoverride, 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.