Spike: Apple Container networking for macos-container backend #230
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Summary
Verify whether Apple's
containerCLI can support bot-bottle's sidecar network enforcement model for the experimentalmacos-containerbackend. This is the next gating question from PR #229 / the macOS Container backend PRD.Context
PR #229 adds the backend scaffold and intentionally keeps launch disabled until the networking shape is proven. A runnable backend must not let the agent bypass the egress sidecar through direct network access.
References:
docs/prds/prd-new-macos-container-backend.mdQuestions to answer
container network create --internalprevent outbound internet access from attached containers?container runattach one container to multiple networks, either through repeated--networkflags or an equivalent command?egress,git-gate,supervise)?container list,container inspect,container image inspect, andcontainer network inspectfor robust enumeration and cleanup?Suggested validation commands
container inspect/container network inspectJSON samples.Acceptance criteria
I could not run the Apple Container networking spike on this host yet. This machine is macOS 15.6.1 and Apple Container networking features needed for the spike require macOS 26; the
containerCLI is also not installed here. We need to update macOS and install/start Apple Container before testing the questions in this issue.Reran the Apple Container networking spike on macOS 26.5.1 arm64 with Apple Container 1.0.0.
Result: the core two-network sidecar shape is viable, with caveats:
container network create --internalproduces ahostOnlynetwork; an agent attached only there could reach the sidecar by internal IP but could not ping1.1.1.1or fetchhttps://example.com.--networkflags work. The sidecar got both NAT and host-only interfaces.--dns 1.1.1.1in the spike) madehttps://example.comwork.bb-spike-230-sidecar.127.0.0.31:18080worked;127.0.0.1:18080failed), but guests could not reach that host loopback-published port through the host-only gateway. Guest-to-sidecar should use the internal network IP.I updated
docs/research/apple-container-networking-spike.mdwith commands, observed output, answers, and recommendation. Recommendation: proceed with a narrowmacos-containerlaunch prototype, but do not assume Docker Compose aliases; inspect the sidecar internal IP and pass concrete endpoints to the agent.@didericis-codex follow up: I'd like you to spike whether we can route traffic through the sidecar egress so we don't need an explicit proxy declared that the agent respects. EX: given this bottle config:
When the agent does a request to
pypi.org, I'd like something to point it to the egress sidecar proxy without specifyingHTTP_PROXY.Yes, this is the right next spike.
The previous run proved the basic isolation shape: an internal-only agent could not egress, a dual-homed sidecar could egress, and the agent could reach the sidecar by internal IP. It did not prove transparent routing. Today the viable path still requires the agent/client to be pointed at the sidecar explicitly.
I’ll spike whether we can make normal direct traffic, e.g.
pypi.org:443, flow through the sidecar withoutHTTP_PROXY/HTTPS_PROXY. The concrete questions I’d test:pf/vmnet rules safely redirect the traffic to the sidecar?I would treat this as a separate enforcement spike. The prior spike does not establish this, and I would not enable launch on the assumption that transparent routing works.
Completed the transparent egress spike and committed the write-up on
main.Commit:
529d0bc docs: add Apple Container transparent egress spikeDoc:
docs/research/apple-container-transparent-egress-spike.mdBlunt result: transparent egress is feasible, but not production-ready until we solve agent route setup without leaving
CAP_NET_ADMINin the agent runtime.What worked:
CAP_NET_ADMIN, IP forwarding, and iptables masquerade can route normal direct agent traffic out to the internet withoutHTTP_PROXY/HTTPS_PROXY.mitmdump --mode transparentwith PREROUTING redirects on the sidecar can intercept normal direct TCP 80/443 traffic.example.comwas logged by mitmproxy.pypi.orgreached mitmproxy. It failed with normal cert verification until the client trusted/skipped the mitm CA, which is consistent with our existing sidecar CA model.dnsmasqbound to the sidecar host-only IP, pointed the agent resolver at it, and direct HTTP/HTTPS still hit mitmproxy.What did not work / remains the blocker:
ip route replace default via <sidecar>fails withOperation not permitted.CAP_NET_ADMIN, which I would not accept as the final security posture.Recommended next implementation spike: start the agent through a tiny backend-owned root init that sets route + DNS to the sidecar, drops network-admin capability / switches to the normal agent user, then execs the agent. Alternative paths are finding a real Apple Container gateway setting or doing host/vmnet-level redirection. For v1, keeping explicit proxy env vars is still the simpler safe path.
Ok, will keep the proxy env vars for the initial release.