Skip to content

fix(sandbox): scope secret_refs to the session tenant - #677

Merged
xiaods merged 1 commit into
mainfrom
fix/sandbox-secret-refs-tenant-scope
Nov 16, 2026
Merged

xiaods merged 1 commit into
mainfrom
fix/sandbox-secret-refs-tenant-scope

Conversation

@xiaods

@xiaods xiaods commented Nov 16, 2026

Copy link
Copy Markdown
Owner

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_refs is now tenant-scoped at exec resolution:

  • A Secret may carry the label sandbox.k8e.io/tenant: <tenant>. A labelled Secret is readable only by a session whose spec.tenantID equals that label.
  • An unlabelled Secret is legacy-compatible for the shared default tenant only; a non-default tenant cannot reference it (otherwise the label would be advisory).
  • checkSecretTenantScope (pkg/sandboxmatrix/grpc/server.go) enforces this; readSecretKey takes the session's tenant and calls it before returning the value.
  • The gateway-internal deny-list (sandbox-apikeys) is unchanged and still applies as defence in depth.
  • The error message never includes the Secret value.

Enforcement is at exec resolution (readSecretKey) — the last point before the value enters the sandbox environment.

Operator action

Label tenant-owned Secrets:

kubectl -n sandbox-matrix label secret my-llm-secret sandbox.k8e.io/tenant=acme

Existing unlabelled Secrets keep working for the default tenant; label them before moving a tenant off default.

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's secret_ref to 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=1

All pass.

Remaining follow-ups (separate PRs)

  • F8: require a credential on loopback if the gateway host is shared.
  • F9: add AutomountServiceAccountToken: false to SandboxPodSpec.
  • F10: tighten sanitizePipPackage and shell-quote each specifier.
  • F11: require an explicit K8E_E2B_SIGNING_SECRET in production.
  • Scope snapshots (SnapshotPut/Get/List) per tenant.

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
xiaods force-pushed the fix/sandbox-secret-refs-tenant-scope branch from 6bbea6e to 9c9d237 Compare November 16, 2026 03:53
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

1 069 tests  +10   1 042 ✅ +10   6m 57s ⏱️ -12s
  121 suites ± 0      27 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 9c9d237. ± Comparison against base commit a737c24.

@xiaods
xiaods merged commit 1757d36 into main Nov 16, 2026
9 checks passed
@xiaods
xiaods deleted the fix/sandbox-secret-refs-tenant-scope branch November 16, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant