fix(agent): apply egress nftables inside the app netns, not the host #138

Merged
gmackie merged 1 commit from fix/egress-rules-host-netns into main 2026-07-23 19:51:48 +00:00
Owner

Problem — every sandboxed deploy silently cripples the node

ApplyNftRules ran plain nft -f - in the host network namespace. The generated egress table (hook output, policy drop, allow only established/lo/DNS/80/443) therefore landed on the host:

  • the node's entire outbound traffic got throttled to DNS/HTTP(S) — node-to-node SSH, ICMP, and any non-web port dead
  • the app inside the netns got no egress policy at all

Both halves of the sandbox contract inverted.

Observed live on hetzner-master after today's classback deploy: master could not reach hetzner-fg on 4873/22/ICMP (Caddy → npm.forgegraf.com 502s; drop counter at 2360 packets), while 80/443 kept working — which made it look like a network/firewall mystery. The same rogue table appeared on hetzner-fg after the npm-registry redeploy. Diagnosed by dumping native nft output-hook chains (nft list ruleset) after iptables-legacy showed nothing.

Fix

ApplyNftRules(netnsName, rules) now execs ip netns exec <ns> nft -f -, and an empty netns name is a hard error so rules can never silently land on the host again. Added sandbox.NetnsName(slug) and reused it in NetNamespaceConfig.

TDD: nftApplyCommand argv test + empty-netns rejection test written red first.

Operator state

Rogue host tables inet fg-classback (master) and inet fg-npm-registry (fg) already hand-deleted; worker/bob swept clean. Fleet effect requires the next agent release (0.1.36, together with #135).

🤖 Generated with Claude Code

## Problem — every sandboxed deploy silently cripples the node `ApplyNftRules` ran plain `nft -f -` in the **host** network namespace. The generated egress table (`hook output`, `policy drop`, allow only established/lo/DNS/80/443) therefore landed on the host: - the **node**'s entire outbound traffic got throttled to DNS/HTTP(S) — node-to-node SSH, ICMP, and any non-web port dead - the **app** inside the netns got no egress policy at all Both halves of the sandbox contract inverted. **Observed live on hetzner-master** after today's classback deploy: master could not reach hetzner-fg on 4873/22/ICMP (Caddy → npm.forgegraf.com 502s; drop counter at 2360 packets), while 80/443 kept working — which made it look like a network/firewall mystery. The same rogue table appeared on hetzner-fg after the npm-registry redeploy. Diagnosed by dumping native nft output-hook chains (`nft list ruleset`) after iptables-legacy showed nothing. ## Fix `ApplyNftRules(netnsName, rules)` now execs `ip netns exec <ns> nft -f -`, and an **empty netns name is a hard error** so rules can never silently land on the host again. Added `sandbox.NetnsName(slug)` and reused it in `NetNamespaceConfig`. TDD: `nftApplyCommand` argv test + empty-netns rejection test written red first. ## Operator state Rogue host tables `inet fg-classback` (master) and `inet fg-npm-registry` (fg) already hand-deleted; worker/bob swept clean. Fleet effect requires the next agent release (0.1.36, together with #135). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(agent): apply egress nftables inside the app netns, not the host
All checks were successful
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 5m22s
ffd558cc85
ApplyNftRules ran plain 'nft -f -' in the host network namespace. The
generated egress table (hook output, policy drop, allow only
established/lo/DNS/80/443) therefore landed on the HOST: every sandboxed
deploy silently throttled the entire node's outbound traffic to
DNS/HTTP(S) — while the app inside the netns got no egress policy at
all, defeating both the node and the sandbox.

Observed live on hetzner-master after a classback deploy: the node could
not reach other nodes on 22/4873/ICMP (Caddy->npm-registry 502s,
node-to-node SSH dead), with the drop counter at 2360 packets. The same
table appeared on hetzner-fg after an npm-registry deploy. Both rogue
tables ('table inet fg-classback', 'table inet fg-npm-registry') were
hand-deleted from the host namespaces.

ApplyNftRules now requires the netns name and execs
'ip netns exec <ns> nft -f -'; an empty name is an error so the rules
can never silently land on the host again.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
Owner

🤖 Bob subscription review — APPROVE: Diff updates ApplyNftRules to require a netns, updates the sole caller in main.go, adds NetnsName helper, and includes tests. Self-consistent and complete.

🤖 Bob subscription review — **APPROVE**: Diff updates ApplyNftRules to require a netns, updates the sole caller in main.go, adds NetnsName helper, and includes tests. Self-consistent and complete.
gmackie deleted branch fix/egress-rules-host-netns 2026-07-23 19:51:48 +00:00
Sign in to join this conversation.
No description provided.