Skip to content

Bubblewrap backend: support egress-only networking via slirp4netns #1085

Open

Description

@AmitoVrito

Context

The Bubblewrap sandbox backend (BubblewrapBackend, merged in #1084) currently supports only the none network policy — fully isolated via --unshare-net. During the pre-merge security review we deliberately made egress_only fail closed rather than ship the original behavior.

The original PR implemented egress_only by simply omitting --unshare-net, which left the sandbox in the host network namespace. That is not egress-only: it exposes host loopback services (unauthenticated local DBs/admin UIs) and the cloud metadata endpoint (169.254.169.254, i.e. IAM credential theft) — strictly more access than outbound-only. bwrap has no NAT of its own, so it cannot provide true egress-only networking unassisted.

Today, callers needing outbound access from a sandbox must use the podman or docker backend (which use a NAT bridge). This issue tracks giving bwrap real egress-only support.

Proposal

Implement egress_only for BubblewrapBackend via slirp4netns, the standard userspace network helper for rootless containers:

  1. Keep --unshare-net (the sandbox always gets its own network namespace — no host loopback/metadata access).
  2. Launch slirp4netns against the sandboxed process's network namespace to provide a NAT'd tap device with outbound-only connectivity.
  3. The usual wiring: run bwrap with --unshare-net + --info-fd to read the child PID, start slirp4netns --configure --mtu=65520 <pid> tap0, and use a sync fd (--block-fd/--userns-block-fd) so the child waits until the tap is ready before exec.
  4. Advertise egress_only in probe().network_policies only when the slirp4netns binary is present; otherwise continue to fail closed.

Acceptance criteria

  • probe() lists egress_only iff slirp4netns is available on the host.
  • With egress_only: outbound TCP/DNS works, but host loopback (127.0.0.1) and the link-local metadata endpoint (169.254.169.254) are unreachable from inside the sandbox.
  • With none: unchanged (fully isolated).
  • If slirp4netns is unavailable and egress_only is requested, start() fails closed with a clear message (current behavior).
  • Failure of the slirp setup must fail safe (no connectivity), never fall back to sharing the host namespace.

Notes / risks

  • The multi-process fd-sync dance does not fit the current one-shot run_process(full_command) helper in sandbox/backends/base.py — it needs a sidecar process kept alive for the command's duration plus teardown. Expect non-trivial plumbing there.
  • This is genuinely Linux-host + real-binary territory, so it needs a real integration test gated on slirp4netns + bwrap being installed (wired into CI so it actually runs, not silently skipped), per the house testing standards. Monkeypatched command-construction unit tests are not sufficient on their own here.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions