13. Forced egress (Linux)
13. Forced egress (Linux)¶
Result: every prediction held, and each layer holds on its own. A gVisor job reaches the public internet only through the proxy; the LAN, the tailnet, the host, other jobs and private-resolving names are refused by the proxy and unreachable directly. With the no-route layer deliberately defeated, the host firewall still drops everything.
How we expected it to work¶
Written before running, so the results could prove it wrong.
Mechanism¶
Three layers, each of which alone should stop a job leaving except through the proxy:
- No route. Pods join CNI network
allmyram-egresson bridgeallmyram-e0(10.78.0.0/24), with no gateway, no default route and no masquerading. Inside the gVisor sandbox, gVisor's own network stack copies the pod's routes, so the only destinations it can address are on10.78.0.0/24. A job runs withoutCAP_NET_ADMIN(CRI's default), so it can't add a route. - Host firewall (nft table
inet allmyram_egress): traffic arriving from the bridge may only open TCP connections to the proxy port (10.78.0.1:3128), plus replies to connections the host opened (the runner forwarding tailcat to a job). Nothing from or to the bridge is forwarded. So even with a route, a job can't reach the host's other services, the LAN or the tailnet. - No pod-to-pod bridging (nft table
bridge allmyram_isolate): frames aren't switched between ports ofallmyram-e0, so jobs can't reach each other directly; they use tailcat.
The proxy (spike/egress_proxy.py, unprivileged, listening only on
10.78.0.1:3128) resolves each target itself and allows it only if every
resolved address is globally routable (Python's ipaddress.is_global,
which excludes private ranges, loopback, link-local, 100.64.0.0/10 and so
the tailnet, ULA, multicast and reserved space). It connects to the
address it checked and logs every decision.
Predictions¶
From a gVisor job (HTTPS_PROXY set), with a second pod listening on
port 8000 as a target:
| Check | Expected |
|---|---|
| Direct TCP to 1.1.1.1:443 | fails at once: no route |
| Direct DNS lookup of a public name | fails: the host's resolver is off-subnet |
https://example.com through the proxy |
200; proxy logs allow |
| Through the proxy to smaug's LAN gateway | 403; logged deny not-global |
| Through the proxy to the laptop's tailnet address | 403; deny not-global |
Through the proxy to localhost |
403; deny not-global:127.0.0.1 |
Through the proxy to 10.78.0.1:22 (the host) |
403 |
| Through the proxy to the other pod | 403 |
| Direct TCP to the LAN gateway, the laptop's tailnet address | fails: no route |
Direct TCP to 10.78.0.1:22 (host SSH, on-subnet) |
times out: firewall drops it |
| Direct TCP to the other pod | times out: no bridging |
| From the host, TCP to the other pod's port 8000 | succeeds (shows the pod was listening, and that the runner can still reach jobs) |
If a direct connection succeeds, the enforcement claim is false and Linux doesn't ship as a runner until it's fixed.
Setup (2026-11-22)¶
- smaug as in #7–#8, plus
spike/install_forced_egress.shrun once by Gavin withsudo(bridge, CNI network, the two nft tables;nftableswas already installed,nftis in/usr/sbin). spike/egress_proxy.py --listen 10.78.0.1:3128running asgavin.spike/forced_egress_check.py: a target pod (python -m http.server 8000) and a probe pod, both gVisor, onallmyram-egress; the probe runs the checks withHTTPS_PROXYset. Run twice: as designed, and with--with-route, which gives the probeNET_ADMINand has it adddefault via 10.78.0.1before the checks, to test the firewall without the no-route layer.
Raw results¶
| Check | Predicted | As designed | With a default route added |
|---|---|---|---|
| Host → other pod :8000 | connects | connected | connected |
| Direct TCP 1.1.1.1:443 | fails | Network unreachable, 0.02 s |
timed out, 3 s |
| Direct DNS (example.com) | fails | Try again |
Try again |
https://example.com via proxy |
200 | 200 | 200 |
| Proxy → LAN gateway 192.168.1.1:80 | 403 | 403 | 403 |
| Proxy → laptop tailnet 100.80.88.77:22 | 403 | 403 | 403 |
Proxy → localhost:22 |
403 | 403 | 403 |
| Proxy → host 10.78.0.1:22 | 403 | 403 | 403 |
| Proxy → other pod :8000 | 403 | 403 | 403 |
| Direct TCP LAN gateway :80 | fails | Network unreachable |
timed out |
| Direct TCP laptop tailnet :22 | fails | Network unreachable |
timed out |
| Direct TCP host :22 | times out | timed out | timed out |
| Direct TCP other pod :8000 | times out | timed out | Host is unreachable |
Proxy log for the first run (abridged): example.com → allow, rule
public, resolved to 2 IPv4 + 2 IPv6 addresses; 192.168.1.1, 100.80.88.77,
localhost (127.0.0.1, ::1), 10.78.0.1 and 10.78.0.10 → deny, rule
not-global:<address>. Every check through the proxy has a matching line
with the job's address as client.
What we learned¶
- Forced egress works on Linux with gVisor, with plain CNI and nft; no gVisor-specific configuration. gVisor's netstack takes the pod's routes, so "no default route" means the job can't address the outside at all.
- The firewall holds alone. With a default route added inside the sandbox, every direct connection off the job network times out at the host. Defense in depth is real, not assumed.
- A job must never get
NET_ADMIN. With it, gVisor let the job add a route. The firewall still held, but the runner should refuse any job spec asking for capabilities. - The proxy's "only globally routable addresses" rule covered every private
case, including a hostname (
localhost) resolving to loopback. - Not covered: IPv6 (the job network is IPv4-only, so jobs have no IPv6 at all), and UDP (no route for it either; the proxy carries TCP only, so a job can't send UDP anywhere, which is intended).
pkill -f egress_proxy.pykilled the shell running it, exactly as in round 1. Patterns forpkill -fmust not match the invoking command line.
What it changes¶
- Linux passes the forced-egress gate for v1. The install step gains the
bridge, the CNI network and an nft table loaded by its own systemd unit
(never Debian's
nftables.service, which flushes other rulesets). - The runner rejects job specs requesting Linux capabilities.