Skip to content

fix(box): let direct-egress tools verify TLS without the gateway - #412

Merged
opieter-aws merged 2 commits into
mainfrom
feature/direct-egress-tools
Nov 13, 2026
Merged

opieter-aws merged 2 commits into
mainfrom
feature/direct-egress-tools

Conversation

@opieter-aws

@opieter-aws opieter-aws commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Problem

[tool.<name>.network] contain_egress = false (and the same key on a stdio MCP server) is meant to let one program connect directly, outside the gateway. Two things stopped it from working:

  1. All platforms. environment::compose set Core's proxy and CA names in both egress modes. A direct-egress process still got HTTPS_PROXY and friends pointing at the gateway, and the six CA names at the gateway's CA. Any proxy-aware client (Go, gh, reqwest, curl) sent its traffic through the gateway anyway, so the escape did nothing.
  2. macOS. A direct-egress process could not verify any certificate through Apple's trust check. The sandbox denied com.apple.trustd.agent (OSStatus -26276) and com.apple.SecurityServer (-9808 from Secure Transport). That breaks Go ≤ 1.26, Go 1.27 with an older go.mod, Rust rustls-platform-verifier and native-tls, and very likely Swift.

Solution

Rule: a direct-egress program behaves as it does on the host. Box adds no proxy or CA setting of its own for it, and refuses none.

  • crates/box/src/run/contain/boundary.rs: environment::Inputs now takes a Route instead of a bare trust_bundle. Route::Gateway { trust_bundle } composes exactly what it did before. Route::Native sets none of HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy, NODE_USE_ENV_PROXY, NO_PROXY, no_proxy, and none of the six CA names. A native leaf also gets no read grant on the gateway's CA. Box sets no default CA file on either platform: a fixed file changes which roots a client trusts (on macOS, rustls-native-certs reads only SSL_CERT_FILE when it is set, and /private/etc/ssl/cert.pem lacks keychain-added roots such as a TLS-inspection root).
  • crates/box/src/record/config/env.rs, process.rs: a [tool.<name>] or stdio [mcp.<name>] table with contain_egress = false may set those 13 proxy and CA names in its env (refused_native_egress_name), for a company proxy or CA bundle. A file it names still needs a read_file entry. Gateway tables and the agent still refuse them, because the gateway's CA must win for interception to work. PWD, USER, OTEL_EXPORTER_OTLP_*, LD_* and DYLD_* stay refused everywhere. A tool pack that knows its client reads only a file sets that file in the table's env.
  • crates/containment/src/backend/macos/seatbelt.rs: Network::AllowAll (how native egress renders) adds (allow mach-lookup (global-name "com.apple.trustd.agent")) and (allow mach-lookup (global-name "com.apple.SecurityServer")), as the program has on the host. native-tls needs SecurityServer; the other clients need only trustd. The gateway path (Network::Localhost) and the agent get neither.
  • Startup report: a native trust: line under the existing native egress: line:
    strands-box: [tool.x] native trust: no proxy and no CA variable from Box, so its client uses its own defaults or its table's env; the trustd and SecurityServer services for the system's certificate checks (the services clause on macOS only).
  • Docs: new decision a native-egress process keeps its own proxy and trust settings, and updates to the CA-trust decision, docs/user/config.md (the refused-names list), docs/user/egress.md, docs/user/mcp.md, docs/design/egress.md, docs/design/macos-enforcement.md, crates/box/README.md, crates/box/AGENTS.md, and the macOS measurements in crates/containment/AGENTS.md.

Interfaces that moved (frozen surfaces): the composed environment of a contain_egress = false process, and the env names such a table may set. A gateway-routed process, including the agent, is unchanged. The public check_workload_env keeps refusing all 13 names, because it has no table context; it is stricter than Core for direct tables.

Keychain finding and its limits. SecurityServer also serves the keychain and authorization. On a Mac, a throwaway login-keychain generic password stayed unreadable through /usr/bin/security with both services allowed, because Box still refuses reads of the keychain files. So the program reaches the host's services, not the host's keychain files. Data-protection and iCloud keychain items were not tested; their service (secd) stays denied.

Related Issues

Fixes #409. Related: #344, #311.

Type of Change

Bug fix

Testing

On Linux aarch64 at 4a38874 (on origin/main 88e8c19):

  • cargo build, cargo test, cargo clippy --all-targets, cargo fmt --check with --all-features for strands-box and strands-box-containment: all pass, no new clippy warnings in either crate (the vendored strands-shell warnings are unchanged). mcp_alias_fallback needs --test-threads=1 on this host ("Text file busy" race); it passes that way. site_manifest passes.
  • New and changed tests:
    • only_a_native_egress_leaf_renders_the_trust_services: the agent and a gateway leaf render neither service; a native leaf renders both (box-level render, runs on Linux too).
    • the_trust_services_render_only_with_native_egress (seatbelt render): both services render once with AllowAll, never with the gateway's localhost port.
    • a_native_egress_leaf_gets_no_proxy_or_ca_from_core_and_keeps_its_own: no proxy or CA name and no gateway-CA grant from Core; a declared HTTPS_PROXY and SSL_CERT_FILE reach the process unchanged.
    • only_a_native_egress_table_may_set_the_proxy_and_ca_names: a direct table accepts the proxy and CA names, a gateway table refuses them with "set by the box itself", and PWD, USER, OTEL_EXPORTER_OTLP_ENDPOINT and LD_PRELOAD stay refused on a direct table.
    • a_gateway_leaf_routes_through_the_proxy_and_trusts_the_gateway_ca: every proxy name, every CA name at the gateway's CA, and the CA grant, unchanged.
    • a_leaf_holds_no_operator_variable_only_its_spec_phantom_and_core_names asserts the routing names only for the gateway mode; the_disclosure_names_native_egress_only_when_it_is_selected checks the native trust: line.
  • Earlier manual Linux run (at the first revision, same env behaviour on Linux): a gateway /usr/bin/env tool gets all 13 proxy and CA names; a contain_egress = false /usr/bin/printenv tool gets none. A direct curl tool verified api.github.com with the system roots once /etc/pki was granted, and failed with curl: (77) on /etc/pki/tls/certs/ca-bundle.crt without it.

On macOS 26 arm64, at 4a38874, with no test patches and a Box Core box.toml only (one gateway tool and one contain_egress = false tool per probe, GET https://api.github.com/zen, gh uses gh api /zen with a fake token):

Program gateway direct
gh 2.104.0 OK OK
gh 2.103.3 (Go 1.27) OK OK
Go 1.26.8 probe -26276 OK
Go 1.27.3, go.mod 1.27 OK OK
Go 1.27.3, go.mod 1.26 -26276 OK
Rust reqwest 0.13 default (platform verifier) -26276 OK
Rust reqwest 0.13 native-tls -9808 OK
Rust reqwest 0.12 rustls-native-roots, no CA file OK OK
Rust reqwest 0.12 rustls-native-roots, env.SSL_CERT_FILE = "/private/etc/ssl/cert.pem" + read_file - OK
login-keychain generic password via /usr/bin/security - not readable (readable outside the box)
  • The gateway column is unchanged from today.
  • The gateway tool's environment holds all 13 proxy and CA names, at the gateway port and <box_dir>/trust/cert.pem. The direct tool's environment holds none of them.
  • The direct tool's startup report shows the new native trust: line.
  • The sandbox log shows com.apple.trustd.agent and com.apple.SecurityServer denials only from the gateway tools.
  • The same run at the previous revision 5b78b71 (which set SSL_CERT_FILE on direct tools) gave the same results for every shared row.

Not covered

  • rustls-native-certs with no CA file found Apple's built-in roots. Roots an administrator added to /Library/Keychains/System.keychain (for example a TLS-inspection root) were not tested; Box refuses that tree, so such a client may miss them. Its tool pack or the operator can set SSL_CERT_FILE to a company bundle in that case.
  • gh built with Go 1.26 (gh 2.89) was not rerun on a Mac: the Mac had gh 2.103.3 and 2.104.0. The Go 1.26.8 probe covers the same toolchain.
  • Adding extra trusted CAs for gateway tools and the agent (on top of the gateway's CA) is a separate design and not in this PR.
  • Only tools and servers the operator opts out of the gateway are helped, with the usual cost: no per-request policy, no credential injection.
  • Not in this PR: in the manual Linux run, a direct-egress curl could not resolve host names (curl: (6)) even with /etc/resolv.conf's target granted. The TLS check was done with --resolve. That is a separate, existing limit of direct egress on Linux.

Checklist

  • I have read the CONTRIBUTING document
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment thread crates/box/src/run/contain/boundary.rs Resolved
Comment thread crates/box/src/run/contain/boundary.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The fix is correct for the problem it names: a native leaf no longer receives the gateway's routing and CA names, and only Network::AllowAll renders the two trust services. The inline comments are about what the native leaf trusts after that: the keychain on macOS, and the CA and proxy names an operator cannot set.

Review Categories
  • Approval (root AGENTS.md): The PR says it moves the composed environment, which is a frozen surface. It also adds Mach services, one of which serves the keychain, and it records a new decision entry. Root AGENTS.md asks for "the user's explicit approval before writing code", and says to record a decision "only after the user decides it". [BUG] contain_egress = false tools still use the gateway, and cannot verify TLS on macOS #409 is the author's own issue and has no maintainer comment. Please link the approval before merge.
  • macOS evidence: On Linux, the SYSTEM_TRUST_BUNDLE = Some(..) arm of a_native_egress_leaf_gets_no_proxy_and_trusts_the_system_bundle never runs, and the PR states that the macOS end-to-end check is pending. The macOS CI result and the Mac run (including the probe without SSL_CERT_FILE from the inline comment) should come before merge.

Checked and held:

  • (Gateway, Some) is the only case that grants or names the gateway's CA. (Gateway, None), (Native, Some) and (Native, None) all give None.
  • reads() finds that the leaf minimum's /etc/ssl covers /private/etc/ssl/cert.pem after canonicalization. A stated read on /etc/ssl covers it too. A stated non-read entry that replaces the cell adds a disclosed File read.
  • The agent and gateway leaves render Network::Localhost and never get trustd or SecurityServer. The RUNTIME_SERVICES cell renders above (deny network*).
  • The disclosure's native trust: line matches the composed environment on each platform.
  • The new tests pass on Linux at 9f78a5d. The seatbelt render test also runs there.

The split into a Route enum keeps the gateway path's composed environment the same, and the tests pin that.

@github-actions

Copy link
Copy Markdown

Re-review at 5b78b71: The PR's own changes match what I reviewed at 9f78a5d: the same 8 files, +378/−22, and the commented lines are at the same places (boundary.rs:1536, :1570). The new head seems to be the same change on a newer main. On Linux the 10 boundary tests and the seatbelt render test pass at this head, once the workspace binaries are built (strands-box-sock-alias is now also needed).

Both open threads still apply, and neither has a reply yet:

  • SSL_CERT_FILE on macOS hides keychain roots from clients built on rustls-native-certs.
  • env still refuses the proxy and CA names on a direct-egress table with the reason "set by the box itself".

The summary's merge preconditions also still apply: a linked approval for the frozen composed environment and the new decision, and a macOS run.

Assessment: Comment (unchanged).

@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review at 4a38874)

This revision changes the design. Box no longer sets a CA file for a direct-egress process, and that process's table may set the proxy and CA names. The second change resolves the env thread. The first was made before the macOS measurement it depended on (see the reply in the SSL_CERT_FILE thread).

Review Categories
  • Evidence: The only direct rustls-native-certs run that passed used the file default that this revision removes. Rerun it on a Mac before merge.
  • Approval (root AGENTS.md): This revision moves two frozen surfaces: the composed environment, and which env names a table may set. It also rewrites the decision entry. Root AGENTS.md asks for the user's explicit approval before code and before a decision is recorded. Please link that approval before merge.

Checked and held:

  • ProcessSpec::validate judges both [tool.*] and stdio [mcp.*] (contained_specs keeps a non-default network). The agent's network table is still refused, so no agent can reach refused_native_egress_name.
  • Credential phantoms still refuse all 13 names (box_owned_environment is unchanged for them). PWD, USER, OTEL_EXPORTER_OTLP_* and LD_*/DYLD_* stay refused on direct tables.
  • compose applies the table's env before Core's names, and Route::Native adds none of them, so an operator's HTTPS_PROXY or SSL_CERT_FILE reaches the process unchanged. A gateway route is unchanged.
  • (Gateway, Some) is still the only case that grants or names the gateway's CA.
  • Only Network::AllowAll renders trustd and SecurityServer. The agent and gateway leaves render neither.
  • On Linux at 4a38874, the related strands-box lib tests (194) and the seatbelt render test pass.

@opieter-aws
opieter-aws merged commit 09b5827 into main Nov 13, 2026
31 of 33 checks passed
@opieter-aws
opieter-aws deleted the feature/direct-egress-tools branch November 13, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] contain_egress = false tools still use the gateway, and cannot verify TLS on macOS

2 participants