14. Forced egress (macOS)
14. Forced egress (macOS)¶
Result: predictions held, including the gap. On a host-only network a
job VM can't reach the internet, the LAN, the tailnet or another job's VM
except through the proxy, which refuses private targets. But it reaches
every service the Mac itself listens on, at all of the Mac's addresses: its
host-only address, its LAN addresses and its tailnet address. Closing that
needs a pf rule.
How we expected it to work¶
Written before running.
Mechanism¶
apple/container's container network create --internal makes a
"host-only" network. We expect a VM on it to reach the Mac's address on
that network and nothing beyond: no NAT to the LAN, the internet or the
tailnet. The proxy runs on the Mac, listening only on that network's host
address. Each job gets its own internal network, so jobs can't reach each
other.
Expected gaps, to be checked rather than assumed:
- The Mac's own services. Anything on the Mac listening on all
interfaces (SSH, development servers, AirPlay receiver) would be reachable
from the VM, because host-only means "reaches the host". Closing that
needs a
pfrule (root, once) allowing only the proxy port from the job networks. - DNS. The internal network may still hand VMs the forwarder at the network's gateway; through the proxy, jobs don't need it.
Predictions¶
| Check | Expected |
|---|---|
| Direct TCP to 1.1.1.1:443 | fails |
https://example.com through the proxy |
200; logged allow |
Through the proxy to LAN, tailnet, localhost |
403 |
| Direct TCP to the LAN gateway, smaug's tailnet address | fails |
| Direct TCP to the Mac's SSH or another listening port on the host address | succeeds without pf; that is the gap to close |
| Direct TCP to a VM on another job's network | fails |
Setup (2026-11-22)¶
- The MacBook as in #9–#12.
container network create --internal allmyram-job1andallmyram-job2: modehostOnly, subnets 192.168.128.0/24 and 192.168.129.0/24, the Mac at.1on each. - The Mac listens on all interfaces at ports 5000 and 7000
(
ControlCenter, the AirPlay receiver) and 49265 (rapportd). spike/macos_forced_egress_check.py: a probe VM onallmyram-job1, a target VM (python -m http.server 8000) onallmyram-job2standing in for another job,spike/egress_proxy.pylistening on 192.168.128.1:3128, checks run in the probe withcontainer exec.
Raw results¶
| Check | Predicted | Outcome |
|---|---|---|
| Mac → other job's VM :8000 | connects | connected |
| Direct TCP 1.1.1.1:443 | fails | timed out |
| Direct DNS example.com | fails | failed after 5 s |
https://example.com via proxy |
200 | 200 |
Proxy → LAN gateway, smaug's tailnet address, localhost, the Mac's 192.168.128.1:5000, the other job's VM |
403 | 403 for all five, each logged deny not-global:<address> |
| Direct TCP LAN gateway :80, smaug tailnet :22, other job's VM :8000 | fails | timed out, all three |
| Direct TCP Mac 192.168.128.1 :5000, :7000, :49265 | connects (the gap) | connected, all three |
| Direct TCP Mac LAN addresses 192.168.1.189:5000, 192.168.1.154:5000 | unknown | connected |
| Direct TCP Mac tailnet address 100.80.88.77:5000 | unknown | connected |
| Direct TCP Mac 192.168.129.1:5000 (the other job network's host address) | unknown | timed out |
What we learned¶
- Host-only networks stop everything past the Mac, and one network per job keeps jobs apart, even from the host address on the other job's network.
- They don't stop the Mac. A job reaches any service listening on all interfaces at the Mac's host-only, LAN and tailnet addresses, because all of those are the Mac. On a Mac mini that is SSH, screen sharing, file sharing and any development server the owner leaves running. The proxy can't help: these connections never go near it.
- Without a working DNS server, the job's own lookups fail after 5 s; jobs don't need DNS when the proxy resolves for them, but anything that tries to look a name up first will stall.
What it changes¶
- macOS passes the forced-egress gate only with a
pfrule: from job networks, allow TCP to the proxy port on the job's host address and drop everything else arriving at the Mac./etc/pf.confalready loadsanchor "com.apple/*", so the rule can live in its own anchor without editing Apple's file. This needs root once at install (andpfenabled), and must be tested before macOS ships as a runner. - Jobs should get a DNS setting that fails fast, or none, so tools don't stall 5 s before using the proxy.
With the pf anchor (2026-11-22)¶
Gavin ran spike/macos_pf_anchor.sh on (rules in anchor
com.apple/allmyram: pass TCP from each job network to its host address
port 3128, block everything else in from the job networks; pfctl -E with
a token). Same checks, run again:
| Check | Without pf |
With pf |
|---|---|---|
https://example.com via proxy |
200 | 200 |
| Proxy → private targets (5) | 403 | 403 |
| Direct TCP Mac 192.168.128.1 :5000, :7000, :49265 | connected | timed out |
| Direct TCP Mac LAN 192.168.1.189:5000, 192.168.1.154:5000 | connected | timed out |
| Direct TCP Mac tailnet 100.80.88.77:5000 | connected | timed out |
| Everything else | as above | unchanged |
The gap is closed. With the anchor, a job VM reaches the public
internet through the proxy and nothing else: not the Mac, the LAN, the
tailnet or other jobs. macOS passes the forced-egress gate for v1, with the
anchor and pf enabled as part of the one-time root install. The runner
must keep the anchor's job-network list in step with the networks it
creates (or reserve one address range for them).