fix(agent): apply egress nftables inside the app netns, not the host #138
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gmackie/ForgeGraph!138
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/egress-rules-host-netns"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem — every sandboxed deploy silently cripples the node
ApplyNftRulesran plainnft -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: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 execsip netns exec <ns> nft -f -, and an empty netns name is a hard error so rules can never silently land on the host again. Addedsandbox.NetnsName(slug)and reused it inNetNamespaceConfig.TDD:
nftApplyCommandargv test + empty-netns rejection test written red first.Operator state
Rogue host tables
inet fg-classback(master) andinet 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
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>🤖 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.