Repository navigation
fix(sandbox): harden sandbox control plane - #676
Merged
Merged
Conversation
Address the findings in docs/security/sandbox-security-review.md. - Tenant isolation (opt-in): apikey.Record gains an optional tenant. The gateway derives the caller's tenant from the client-cert CommonName (the API key name) and enforces it on every session-scoped RPC: getSession/getPodIP return NotFound on mismatch (so existence is not leaked), list filters, and create stamps the bound tenant or rejects an explicit mismatch. The E2B control plane enforces the same binding (create/find/list/reacquire). Keys without a tenant keep the legacy shared-credential behaviour, so existing single-tenant installs are unaffected. - Certificate revocation is now persisted (sandbox-revoked.json), loaded on start, reconciled against the active key set on every load (including the first load after a restart), and checked at Login so a revoked certificate cannot re-enroll. - The rate limiter keys buckets on the authenticated identity (cert CN / token hash) instead of the client-supplied x-sandbox-tenant header, and gives loopback its own bucket. - Session, sub-agent, background-run and approval identifiers are crypto-random instead of timestamp-derived. - Warm-pool pods now deny ingress except kubelet TCP probes; previously the "deny-all" policy only declared egress, leaving sandboxd reachable from any pod. Adds regression tests for each path and a security review report.
Contributor
Test Results1 059 tests +13 1 032 ✅ +13 7m 3s ⏱️ -3s Results for commit 416cdba. ± Comparison against base commit d06b5f0. This pull request removes 4 and adds 17 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
DeepSource flags a nil body passed to http.NewRequest as an antipattern (GO-... / antipattern). Use http.NoBody, which is what the stdlib uses internally for a bodyless request.
|
xiaods
added a commit
that referenced
this pull request
Nov 16, 2026
A session could reference any non-reserved Secret in the sandbox namespace and have the gateway inject it into the exec environment, so one tenant could exfiltrate another tenant's provider key by naming it. This was independent of the tenant-isolation work in #676: even a caller bound to its own tenant could name any Secret. A Secret may now carry the label sandbox.k8e.io/tenant: <tenant>. A labelled Secret is readable only by a session whose spec.tenantID matches. Unlabelled Secrets stay legacy-compatible for the shared default tenant, so existing single-tenant installs keep working; a non-default tenant may not reference them. The gateway-internal deny-list is unchanged and still applies (defence in depth), and the error never includes the Secret value. Enforcement is at exec resolution (readSecretKey) — the last point before the value enters the sandbox environment.
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Applies the security hardening from
docs/security/sandbox-security-review.md(added in this PR). All changes are backward compatible: existing API keys are unbound and keep the legacy shared-credential behaviour.Findings fixed
apikey.Recordgains an optionaltenant. The gateway derives the caller's tenant from the client-cert CommonName (API key name) and enforces it on every session-scoped RPC. The E2B control plane enforces the same binding.sandbox-revoked.json), loaded on start, and reconciled against the active key set on every load — including the first load after a restart (a key deleted while the gateway was down is now revoked).Loginnow checks revocation, so a revoked certificate cannot re-enroll and mint a fresh one.x-sandbox-tenantheader; loopback gets its own bucket.sandboxd :2024reachable from any pod).Tenant isolation details
Server.apiKeyTenantsis reloaded from the Secret with the keys and swapped atomically.getSession/getPodIPreturn NotFound on a tenant mismatch (notPermissionDenied) so a cross-tenant caller cannot learn that a session exists.listSessionsfilters;createSessionWithTTLstamps the bound tenant or rejects an explicit mismatch.ExposeServicefast path,UnexposeService,ListExposed) andConfirmActionare tenant-checked.SecretKeySet.TenantsfeedsReplaceAPIKeysWithTenants; create stamps the tenant,findLive/handleConnect/listLiveSessionsscope to it,reacquireByKeyrefuses another tenant'smetadata.name.Usage
Tests
New/updated tests:
pkg/sandbox/apikey/store_test.go,pkg/sandboxmatrix/grpc/authz_test.go,pkg/sandboxmatrix/grpc/cert_store_test.go,pkg/sandboxmatrix/grpc/cert_test.go,pkg/sandboxmatrix/grpc/orchestrator_test.go,pkg/sandbox/e2b/authz_test.go,pkg/sandbox/e2b/protocol_test.go,pkg/sandboxmatrix/ratelimit/ratelimit_test.go.Validation
go build ./... go vet ./pkg/sandboxmatrix/... ./pkg/sandbox/... ./pkg/server/... go test ./pkg/sandboxmatrix/... ./pkg/sandbox/... ./pkg/sandboxmcp/... \ ./pkg/sandboxcli/... ./pkg/server/... -count=1All pass.
Follow-ups (documented in the report, not in this PR)
secret_refsis still a name-based deny-list; make it a tenant-labelled allowlist.AutomountServiceAccountToken: falsetoSandboxPodSpec.sanitizePipPackage; require an explicitK8E_E2B_SIGNING_SECRET.