mxc icon indicating copy to clipboard operation
mxc copied to clipboard

Seatbelt: accept loopback-only `egress.allow` port rules (alongside `runtimeConfig.networkProxy`)

Open geuben opened this issue 1 month ago • 1 comments

Description of the new feature / enhancement

Problem

On macOS, a Seatbelt-contained process can reach host loopback in only two ways:

  • ingress.hostLoopback: "allow", which opens every port: (allow network-outbound (remote ip "localhost:*"));
  • the loopback runtimeConfig.networkProxy, which only proxy-aware HTTP clients can use.

There's nothing in between. For coding-agent sandboxes this forces a bad choice. Test suites need to reach one or two local services, for example a Postgres container on localhost:5432, a build daemon or a test server. But the same loopback also carries Node inspector (9229) and Chrome remote debugging (9222) ports, kubectl port-forwards and other projects' databases, and reaching some of these is a sandbox escape in itself.

Downstream, this is what's behind github/copilot-cli#5105. There, Gradle and Kotlin daemons and Rails against a local Docker database fail with EPERM, even with allowLocalNetwork: true. Copilot's runtime maps that setting to ingress.default: allow with hostLoopback: deny, so a sandboxed process can't even connect to a listener it started itself.

What Seatbelt can already do

The backend docs list "Reach a loopback address / port ✅ Kernel-enforced, port-scoped". The backend already emits a single-port rule for the proxy:

(allow network-outbound (remote ip "localhost:<proxy port>"))

The same rule for caller-listed ports would give port-scoped host loopback. Today, however:

  • egress.allow is rejected on Seatbelt whenever it's non-empty ("no CIDR/port/protocol primitive exists");
  • the 1.0.0 policy spec requires egress.allow and egress.deny to be empty whenever runtimeConfig.networkProxy is set, and Copilot always sets a proxy.

Proposed technical implementation details

Proposal

  1. Seatbelt: accept egress.allow rules whose to consists only of loopback CIDRs (127.0.0.0/8 or 127.0.0.1/32, and ::1/128), with explicit TCP ports. Each port becomes (allow network-outbound (remote ip "localhost:<port>")). Keep rejecting any other to, and any rule without ports.
  2. Spec: allow loopback-only egress.allow rules alongside runtimeConfig.networkProxy. They don't weaken the proxy's destination filtering, which is about non-local traffic.
  3. Port ranges (endPort): SBPL has no range syntax. Either expand ranges up to a small cap or reject them on Seatbelt.

Example:

"network": {
  "egress": {
    "default": "deny",
    "allow": [{ "to": [{ "cidr": "127.0.0.1/32" }, { "cidr": "::1/128" }],
                "ports": [{ "protocol": "tcp", "port": 5432 }] }]
  },
  "ingress": { "default": "deny", "hostLoopback": "deny" },
  "runtimeConfig": { "networkProxy": "http://127.0.0.1:<port>" }
}

Caveats worth documenting

  • As the Seatbelt doc already notes, localhost in SBPL means every address bound to this host, LAN IPs included. A port rule therefore also allows that port on the host's LAN addresses. In practice that's still far narrower than localhost:*.
  • This covers outbound only. It doesn't solve "connect to a listener this sandbox started on an ephemeral port", which needs ingress.default: allow plus knowing the port ahead of time. Ideas for that would be welcome, but port-scoped host loopback alone would unblock the common "tests need the local database" case.

Once this is in mxc, Copilot's runtime would need to expose it, for example as port-level allowedHosts entries or a localPorts setting. I'll link this issue from copilot-cli#5105.

geuben avatar Oct 15 '26 12:10 geuben

Hi Reuben, thanks for the feature request. Will definitely take a look at this.

theelliotm avatar Oct 16 '26 00:10 theelliotm