Repository navigation
fix(sandbox): scope secret_refs to the session tenant - #677
Merged
Merged
Conversation
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.
xiaods
force-pushed
the
fix/sandbox-secret-refs-tenant-scope
branch
from
November 16, 2026 03:53
6bbea6e to
9c9d237
Compare
|
Contributor
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
Follow-up to #676. Closes F7 from
docs/security/sandbox-security-review.md: 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 — even a caller bound to its own tenant could name any Secret.Change
secret_refsis now tenant-scoped at exec resolution:sandbox.k8e.io/tenant: <tenant>. A labelled Secret is readable only by a session whosespec.tenantIDequals that label.defaulttenant only; a non-default tenant cannot reference it (otherwise the label would be advisory).checkSecretTenantScope(pkg/sandboxmatrix/grpc/server.go) enforces this;readSecretKeytakes the session's tenant and calls it before returning the value.sandbox-apikeys) is unchanged and still applies as defence in depth.Enforcement is at exec resolution (
readSecretKey) — the last point before the value enters the sandbox environment.Operator action
Label tenant-owned Secrets:
Existing unlabelled Secrets keep working for the
defaulttenant; label them before moving a tenant offdefault.Tests
New
pkg/sandboxmatrix/grpc/secret_scope_test.go:TestCheckSecretTenantScope— table over labelled/unlabelled × matching/mismatched/empty tenant.TestReadSecretKey_TenantScope— owner can read, other tenant and default cannot read a labelled secret; default can read an unlabelled secret, a non-default tenant cannot.TestResolveSessionEnv_RejectsCrossTenantSecret— end-to-end: an attacker session'ssecret_refto a victim-labelled Secret fails and does not leak the value.Validation
go build ./... go vet ./pkg/sandboxmatrix/... go test ./pkg/sandboxmatrix/... ./pkg/sandbox/... ./pkg/sandboxmcp/... \ ./pkg/sandboxcli/... ./pkg/server/... -count=1All pass.
Remaining follow-ups (separate PRs)
AutomountServiceAccountToken: falsetoSandboxPodSpec.sanitizePipPackageand shell-quote each specifier.K8E_E2B_SIGNING_SECRETin production.SnapshotPut/Get/List) per tenant.