fix(sandbox): allow egress to the app's data stores (Postgres/Redis/MySQL) #143

Merged
gmackie merged 1 commit from fix/sandbox-db-egress into main 2026-07-27 18:05:31 +00:00
Owner

Found while cutting agent 0.1.38: npm-registry publishes returned 500 because the in-netns egress policy (PR #138, restricted default DNS/80/443) dropped the registry's token-auth Postgres queries to hetzner-master over Tailscale (7030 dropped packets on the counter). Reads kept working (anonymous, no DB), so the outage was invisible until the first publish attempt after the registry moved onto the in-netns egress path.

Fix: deploy parses data-store connection URLs (postgres/postgresql/mysql/redis/rediss) out of the merged deployment env, maps loopback hosts to the veth host IP (mirroring rewriteLoopbackEnvForSandbox), resolves hostnames, and renders per-address ip[6] daddr <ip> tcp dport <port> accept # data store rules that apply even under the restricted default — platform-provisioned bindings are always reachable. Resolution failures skip the rule (deploy proceeds; the app surfaces its own connectivity error).

TDD red-first: datastores_test.go (URL parsing, loopback mapping, resolution w/ fake lookup, dedupe, IPv6) + TestGenerateNftRulesDataStores. Full agent go test ./... green.

Operator action already applied (flagged per convention): hand-inserted ip daddr 100.101.32.120 tcp dport 5432 accept into the fg-npm-registry netns on hetzner-fg to unblock publishing now. That rule is ephemeral (wiped by next redeploy/reconcile) — after this merges and ships in 0.1.38, npm-registry needs one redeploy to persist the rule into its reboot-reconcile state.

🤖 Generated with Claude Code

Found while cutting agent 0.1.38: npm-registry publishes returned 500 because the in-netns egress policy (PR #138, restricted default DNS/80/443) dropped the registry's token-auth Postgres queries to hetzner-master over Tailscale (7030 dropped packets on the counter). Reads kept working (anonymous, no DB), so the outage was invisible until the first publish attempt after the registry moved onto the in-netns egress path. **Fix**: deploy parses data-store connection URLs (`postgres`/`postgresql`/`mysql`/`redis`/`rediss`) out of the merged deployment env, maps loopback hosts to the veth host IP (mirroring `rewriteLoopbackEnvForSandbox`), resolves hostnames, and renders per-address `ip[6] daddr <ip> tcp dport <port> accept # data store` rules that apply **even under the restricted default** — platform-provisioned bindings are always reachable. Resolution failures skip the rule (deploy proceeds; the app surfaces its own connectivity error). TDD red-first: `datastores_test.go` (URL parsing, loopback mapping, resolution w/ fake lookup, dedupe, IPv6) + `TestGenerateNftRulesDataStores`. Full agent `go test ./...` green. **Operator action already applied** (flagged per convention): hand-inserted `ip daddr 100.101.32.120 tcp dport 5432 accept` into the `fg-npm-registry` netns on hetzner-fg to unblock publishing now. That rule is ephemeral (wiped by next redeploy/reconcile) — after this merges and ships in 0.1.38, npm-registry needs one redeploy to persist the rule into its reboot-reconcile state. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(sandbox): allow egress to the app's data stores (Postgres/Redis/MySQL)
All checks were successful
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 8m27s
ab5aee83cb
The in-netns egress policy (restricted default: DNS/80/443) silently
dropped app-to-database traffic — npm-registry's publishes 500'd because
its token-auth queries to Postgres on hetzner-master (Tailscale, 5432)
timed out. First publish attempted since the registry moved onto the
in-netns egress path exposed it.

Deploy now parses data-store connection URLs (postgres/postgresql/mysql/
redis/rediss) from the merged deployment env, maps loopback hosts to the
veth host IP (mirroring rewriteLoopbackEnvForSandbox), resolves
hostnames, and renders per-address accept rules that apply even under
the restricted default. IPv6 addresses render as ip6 daddr.

Operator action already applied on hetzner-fg: hand-inserted
'ip daddr 100.101.32.120 tcp dport 5432 accept' in the fg-npm-registry
netns to unblock publishing; the next registry redeploy on an agent with
this fix persists the rule properly (incl. reboot-reconcile state).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.