All SendBox docs

SendBox · Security

Egress enforcement trust boundary and runtime integration contract

Status: production runtime integration. Companion to docs/architecture/egress-enforcement.md. This document defines the trust boundary of sendbox-egress, its threat model, the residual risks it does not close, and the contract a runtime supervisor must satisfy to integrate it.

Trust boundary

untrusted workload (agent cgroup)
  |-- loopback DNS/public SOCKS --> trusted gateways (broker cgroup + SO_MARK)
  `-- loopback npm HTTP ---------> trusted package proxy (registry cgroup)
                                      `-- registry-only loopback SOCKS
                                          --> trusted gateway (broker + SO_MARK)

nftables default-drop denies every other cgroup/destination combination
  • Untrusted: every workload process beneath the delegated agent ancestor. It runs in nested execution leaves and may reach only the loopback DNS and public CONNECT broker ports plus the workload-facing npm proxy when enabled.
  • Trusted broker: DNS/SOCKS gateways in the broker cgroup mark their external sockets and enforce PolicyEngine in userspace.
  • Trusted registry proxy: the package analyzer runs as a separate unprivileged identity in the registry cgroup. It can reach only its registry-only loopback SOCKS listener and cannot set SO_MARK.
  • Trusted supervisor: arms enforcement and places every service in its expected cgroup. nftables enforces identity and reachability in the kernel as defense in depth.
  • The boundary is a Linux network namespace with the crate-owned nftables table. The crate never modifies anything outside its owned table, cgroup subtree, and namespace.

What the kernel layer enforces

  • The agent cgroup can originate traffic only to the exact loopback broker ports (CONNECT always; DNS only when allow_dns = true), the configured npm proxy port, and, in a governed session with brokered credentials, the credential relay port (15084). The relay is served by the trusted guest supervisor and forwards to the host over the authenticated control channel, not through the broker cgroup.
  • The registry cgroup can originate traffic only to the exact registry-only SOCKS port. It cannot reach public broker ports or external destinations.
  • The broker cgroup can originate external traffic only when the socket carries the fixed SO_MARK, and never to cloud-metadata addresses.
  • Any other process (a sibling in none of the owned cgroups) is denied the broker ports and external egress. This is the concrete improvement over UID-based isolation: sharing a UID no longer grants broker-class reachability.
  • New inbound to the broker's own loopback ports is scoped by iif lo + exact destination + port. The originating identity is not visible at the input hook, but the output chain already permits only the intended source-cgroup and destination-port pair.
  • All UDP/QUIC from the agent (other than DNS to the broker) is dropped; the CONNECT broker additionally answers UnsupportedProtocol (native protocol) or Command not supported (SOCKS5 BIND/UDP ASSOCIATE) for any non-TCP request. Raw AF_PACKET sockets operate below the IP layer and are not visible to the inet filter hooks — dropping CAP_NET_RAW from the agent is the runtime's responsibility (see contract below).

What the userspace brokers enforce

  • A selectable client-facing front end (ConnectFrontend): the crate's native bounded CONNECT framing (default) or standard SOCKS5 (RFC 1928, no-auth, CONNECT only). The front end is fixed per instance from configuration, never auto-detected from client bytes. Both front ends enforce policy through the identical resolve/pin/decide/dial path; only the wire framing differs.
  • Domain allow/deny with blocked-domain precedence and wildcard rules that never match an apex or an unrelated suffix.
  • An address-class check no domain grant can override; a restricted class (loopback, link-local, RFC 1918, ULA, multicast, metadata, unspecified) needs an explicit IP/CIDR grant.
  • IPv4-mapped-IPv6 canonicalization so a blocked/allowed CIDR cannot be bypassed or missed through address encoding.
  • DNS validation of every CNAME hop and returned address, TTL capping, and an expiring (name, ip) authorization that pins the exact validated address — a later CONNECT can only use an address a DNS answer actually validated, defeating rebinding.
  • Deterministic DNS query-name exfiltration budgets: total QNAME/label limits, a QTYPE allowlist, a response-record cap, and per-window query-count, query-octet, distinct-name, and distinct-dynamic-label budgets with bounded state. Every structural/budget field is range-validated (fail closed) at compile time.
  • An exact github.com grant delegates to validated, expiring public destinations from the fixed official HTTPS Meta API. Every broker uses the same snapshot revision; refresh/expiry retires DNS pins and rechecks in-flight resolution/dial decisions. Meta CIDRs cannot unlock private, link-local, metadata or other restricted classes.

The trusted gateway retrieves Meta through its marked dialer, without credentials, redirects or environment proxies, and verifies TLS for api.github.com. It publishes provenance before activating a candidate. Initial fetch or provenance-publication failure prevents readiness; refresh outages retain only a bounded last-good lease. See refresh and evidence for exact limits.

Threat model and mitigations

ThreatMitigation
Direct outbound bypassing the brokerKernel default-drop; the agent ancestor match confines every nested execution leaf to public loopback broker ports and the optional npm proxy.
Workload bypasses package analysis with an npm registry override or direct tarball URLThe workload policy denies the configured npm upstream and the agent cgroup cannot reach the registry-only SOCKS listener.
Compromised package proxy dials externally or reaches the public brokerThe registry cgroup can reach only the trusted registry SOCKS port and has no SO_MARK capability.
Sharing the broker's identity to egresscgroup v2 identity + required SO_MARK; a sibling process is denied.
DNS rebindingExpiring (name, ip) authorization pins the exact validated address.
SSRF to cloud metadataAddress-class denial in policy and an explicit kernel drop for the broker.
DNS-tunneling exfiltrationDeterministic, bounded structural limits and per-window budgets.
Broker crash leaving traffic openRules persist on broker death (fail closed); the guard re-arms on restart.
Partial/failed ruleset updateAtomic destroy + create transaction; a failed update leaves the previous table intact. A failed re-arm never runs nft cleanup, so a live instance's table is preserved rather than destroyed.
Lingering process during teardownFail-closed teardown removes cgroups first; if a cgroup still holds a process, the nftables table is retained (the process cannot regain egress) and the error is surfaced. Teardown is retryable: cgroup and nftables removal are tracked independently, so a later call retries whichever stage failed.
Off-path DNS response spoofingThe forwarding resolver connects its UDP socket to the exact upstream, so the kernel drops any reply whose source is not the full upstream SocketAddr (address and port), not merely the same IP.
Symlink race on cgroup pathsAll cgroup filesystem operations are descriptor-relative via cap-std (RESOLVE_BENEATH); an escaping symlink under the root is refused.
Raw-socket egress bypassThe agent runs unprivileged with CAP_NET_RAW dropped; the live suite asserts every capability set is empty and that raw-socket creation is denied.
Unbounded DNS-only cache growthThe authorization cache prunes expired entries on insert and enforces a deterministic hard capacity derived from the DNS budget.
CONNECT resolution bypassing DNS controlsA fresh CONNECT-path resolution applies the same DnsGuard (structural limits, QTYPE allowlist, response cap, budget); with allow_dns = false it does not resolve at all.
Slowloris / floodsBounded handshakes, per-message caps, bounded concurrency, inline (never spawned) rejections.

Residual risks (explicitly not closed)

  • Shared-cloud delegation. The requested Meta scope includes Actions CIDRs and wildcard cloud/storage services that can host unrelated tenants. A direct-IP grant is network reachability, not GitHub ownership, authentication or operation approval. Existing deny/private/MCP/package boundaries remain necessary. The feed is authenticated by HTTPS, not a separately signed GitHub artifact.
  • Snapshot transitions. Removing a grant affects new connections; existing tunnels are bounded to 300 seconds, not forcibly revoked. Exported evidence contains the latest refresh attempt and expiry, not every transition.
  • Metadata by hostname over an uncovered address. The metadata address list (address::METADATA_V4_ADDRESSES / METADATA_V6_ADDRESSES) is deterministic but not exhaustive. A provider that serves metadata purely by a hostname resolving to an address not on the list must be blocked with blocked_domains.
  • Query-name exfiltration within budget. The budgets bound exfiltration bandwidth deterministically; they do not make a broad allowed_domains policy safe. A narrow allowlist remains the primary control.
  • Raw sockets. AF_PACKET is below the IP filter hooks; the runtime must drop CAP_NET_RAW (and generally run the agent unprivileged). The live suite proves this by running the agent under setpriv with all capability sets cleared and no_new_privs, then asserting raw-socket creation is denied — but the production runtime is still responsible for the equivalent privilege drop.
  • Loopback upstream resolvers. The forwarding resolver's upstream must be external (reached via the marked broker path), not a loopback service inside the sandbox namespace, which the input chain does not admit.
  • Capability/privilege of the agent. cgroup identity does not drop capabilities; privilege drop is the runtime supervisor's job.
  • Inherited configuration descriptors. The harness accepts a pre-opened --policy-fd / --fixtures-fd and otherwise reads with O_NOFOLLOW before any namespace/cgroup transition. Stable Rust's std::process::Command cannot pass an arbitrary inherited fd to a child across a setpriv/ip netns exec re-exec, so the live path reads config in-process before transitions rather than reopening a predictable path afterward.

Runtime integration contract

A runtime supervisor integrating this crate must:

  1. Create the sandbox network namespace and any veth/routing before arming.
  2. Call ArmedEgress::arm (or arm_under with a namespace-scoped NftRunner). It refuses to arm unless enforcement is fully installed and verified.
  3. Retain CAP_NET_ADMIN in the namespace for the broker (to set SO_MARK and load nftables); preflight probes this.
  4. Start every DNS/SOCKS gateway in the broker cgroup, configured with the MarkDialer and a ForwardingResolver carrying the same mark. Pick the CONNECT front end (ConnectFrontend::Custom or Socks5) to match the client; the choice is fixed configuration, never negotiated from bytes.
  5. If package analysis is enabled, start the proxy in the registry cgroup with a distinct UID/GID, cleared capabilities, no_new_privs, and no socket-mark privilege. Expose its trusted SOCKS listener only to that cgroup.
  6. For production execution, arm with controller delegation, keep the agent ancestor empty, and start workloads only in descendant execution leaves. Direct place_agent is deliberately rejected in delegated mode.
  7. Run the agent unprivileged with CAP_NET_RAW dropped (raw sockets are out of the inet hooks' scope) and no_new_privs set.
  8. Keep the broker and registry cgroups stable across service restarts — re-place new pids rather than recreating cgroups, so loaded nftables cgroup identities stay valid.
  9. On shutdown, stop the agent and registry proxy, then drop/teardown the guard. Teardown is fail-closed ordered (cgroups before nftables), idempotent, and absent-safe; a surfaced error means enforcement was deliberately retained and must be logged and retried, not ignored.

The crate remains provider-neutral. Production integration lives in sendbox-host, authenticated bootstrap, the Apple/Kata providers, and the guest Egress service. Hyperlight rejects restrictive egress policy because it does not implement this persistent guest boundary.