Repository navigation
Description
Summary
Add per-user multi-tenancy to the OpenShell gateway so that OIDC-authenticated
users can create / list / connect / remove only their own sandboxes on a
single shared gateway — without a namespace (or gateway) per user.
The gateway already authenticates users via OIDC and threads an Identity into
every request. It does not yet record sandbox ownership or filter by it. This
issue adds an openshell.ai/owner label, stamped server-side from the verified
caller identity, and enforces it on the sandbox CRUD/connect paths — reusing the
label-selector filtering the store already supports.
Relates to: epic #1363. Background research: docs/research/openshell-mvp.md
(§5.2 "no per-user sandbox ownership", §10 "shared-gateway multi-tenancy" deferred),
docs/research/openshell-fork-analysis.md.
Motivation
The MVP (docs/research/openshell-mvp.md) achieves isolation with
namespace-per-team gateways, and within a team all openshell-user members
share every sandbox (§5.2). Pushing that model to per-user isolation would mean a
namespace (or a whole gateway stack) per user, which does not scale:
- Namespace churn, RBAC/quota fragmentation, controller load, slow create.
- Gateway-per-user multiplies pods, certs, and DBs.
K8s namespaces are a coarse blast-radius/quota boundary, not a per-user partition.
The scalable model is one shared gateway, ownership enforced at the application
layer, with the namespace kept as a team/quota boundary.
What already exists (verified — grep to confirm exact lines)
Repo: kagenti/openshell (gateway, Rust), branch base = current mvp-v2 lineage (v0.0.49+).
| Piece | Location | Notes |
|---|---|---|
Identity { subject, display_name, roles, scopes, provider } |
crates/openshell-server/src/auth/identity.rs |
subject = OIDC sub; display_name = preferred_username |
| OIDC JWT validation + claim extraction | crates/openshell-server/src/auth/oidc.rs |
issuer/audience validation, configurable roles/scopes claim paths |
Principal::User(UserPrincipal { identity }) |
crates/openshell-server/src/auth/principal.rs |
also Sandbox, Anonymous variants |
| Principal inserted into request extensions | crates/openshell-server/src/multiplex.rs (~:470) |
req.extensions_mut().insert(principal) — available to all handlers |
| Authz = role/scope only | crates/openshell-server/src/auth/authz.rs (~:59 check) |
method-level gate; no resource-level check |
| Sandbox handlers | crates/openshell-server/src/grpc/sandbox.rs |
handle_create_sandbox (:117), handle_get_sandbox (:226), handle_list_sandboxes (:247), handle_delete_sandbox_inner (:487) — none read Principal |
| Label-selector validation | crates/openshell-server/src/grpc/validation.rs (~:464 validate_label_selector) |
equality-only, comma-separated k=v (AND), no set ops |
| List-with-selector (store) | persistence/mod.rs (:461 list_messages_with_selector), persistence/postgres.rs (:398, JSONB @>, server-side), persistence/sqlite.rs (~:423, in-memory filter) |
scoped by object_type |
| Object metadata = labels, no owner | proto/datamodel.proto ObjectMeta { id, name, created_at_ms, labels, resource_version }; migrations migrations/sqlite/001,004,005 |
no owner/subject/created_by column |
The gap: CreateSandbox stamps no owner; ListSandboxes returns all
sandboxes; GetSandbox/DeleteSandbox/connect/exec have no ownership check.
Proposed approach
Reserved, server-set label openshell.ai/owner = <identity.subject>.
- Create — read
Principal::Userfrom request extensions; set
metadata.labels["openshell.ai/owner"] = identity.subject. Strip any
client-suppliedopenshell.ai/owner(and anyopenshell.ai/-reserved keys)
from the incoming request so ownership cannot be spoofed. - List — AND the caller's
openshell.ai/owner=<subject>into the label
selector before hitting the store. Admins bypass (see admin rule below). - Get / connect / exec / SSH-bridge / policy-get — after fetching by
name/ID, returnPermissionDeniediflabels["openshell.ai/owner"]!= caller
subject. (Find all handlers that resolve a sandbox by name/ID — not just the
four above; e.g. ExecSandbox and the SSH bridge path.) - Delete / update — same ownership check before mutating.
- Admin bypass — callers with role
openshell-admin(already in
Identity.roles, seeauthz.rs) skip the owner filter/check and operate on
all sandboxes.
No proto change and no DB migration are required for the MVP of this feature —
ownership rides in the existing labels map and the existing selector path.
Why labels (not a new column) for v1
- Reuses
validate_label_selector, the Postgres JSONB filter, and the SQLite
filter that already exist — minimal surface area. - Correctness holds on both stores immediately.
- A dedicated indexed
ownercolumn (proto field + migration) is the tidy
long-term option and is listed under Scaling below, not blocking v1.
Key decisions / sharp edges (must be handled in the PRs)
- Owner is server-set from the verified
Principal, never client input.
Strip reserved keys onCreateSandbox. This is the security crux — call it out
in the PR and cover it with a test. - Label-value charset. Gateway validates label values (
validate_label_value)
and K8s pod labels are stricter (alnum/-/_/., <=63). Keycloak'ssubis a
UUID and satisfies this. If a deployment's IdP issues email-style subjects
(alice@corp), it will fail validation — document that the Kagenti Keycloak
realm must use UUIDsub(default), or hash the subject into a valid value.
Put the sanitization in one helper so a future column-based swap is localized. - Sandbox
nameis globally unique per object type in the store — two users
cannot both create a sandbox nameddev. Decide one of: (a) server-prefix the
stored name with an owner token, (b) require unique names, or (c) make
name-uniqueness owner-scoped. Document the choice; (a) or (c) is preferred for
UX. This needs a deliberate decision — flag it in the PR. - Defense-in-depth, not a substitute. Owner filtering is a control-plane
visibility/authz control. Pod-level isolation (separate SA, NetworkPolicy,
SPIFFE, supervisor Landlock/seccomp/netns) remains the data-plane boundary.
Implementation tasks (by repo)
A. kagenti/openshell (gateway, Rust) — core PR
- Add a constant for the reserved label key
openshell.ai/ownerand a
subject -> label-valuesanitizer helper. -
CreateSandbox: extractPrincipal::User; rejectAnonymous; strip
reservedopenshell.ai/keys fromrequest.labels; stamp owner label. -
ListSandboxes: inject owner equality into the effective selector;
admin-role bypass. -
GetSandbox,DeleteSandbox, and every other handler resolving a sandbox
by name/ID (ExecSandbox, SSH bridge, policy get): ownership check + admin
bypass. Auditgrpc/sandbox.rsandgrpc/for sandbox lookups. - Shared helper "may this principal access this sandbox" reused across handlers.
- Unit tests: owner stamped on create; client-supplied owner stripped; list
filtered to caller; get/delete cross-user ->PermissionDenied; admin sees
all; anonymous rejected. - Keep behavior backward-compatible when OIDC is disabled
(OPENSHELL_OIDC_ENABLED=false/ LocalDev/mTLS principals): define behavior
explicitly (e.g. owner = principal subject for mTLS CN; skip when Anonymous
auth is the configured mode). Document it.
B. kagenti/openshell-driver-openshift (compute driver, Go) — small PR
- Propagate
openshell.ai/owneronto the created sandbox pod labels
(alongside the existingopenshell.ai/tenant/kagenti.io/teamlabels)
for data-plane traceability and future NetworkPolicy/SPIFFE scoping. The
gateway passes labels through the ComputeDriver gRPC contract — confirm the
owner label is carried.
C. kagenti/kagenti — wiring, tests, docs
- e2e: per-user isolation tests (extend
kagenti/tests/e2e/). Alice and Bob
authenticate to the same gateway; Alice creates a sandbox; assert Bob's
listdoes not show it and Bob'sget/delete/connecton it ->
permission denied; assert admin sees both. Mirrors MVP §9.2 criteria add banner #6/fix typo in readme #7
but at the user level on a shared gateway. - Helm
charts/openshell/: support a shared-gateway deployment mode (one
gateway serving multiple users in a namespace) in addition to the existing
per-tenant mode. Gate behind a value, default off. - Docs: add
docs/research/openshell-per-user-tenancy.md(or fold into the
MVP doc §10) describing the model and the namespace-as-coarse-boundary
stance.
D. Scaling follow-ups (separate issues, not blocking v1)
- Shared Postgres store instead of SQLite-per-gateway (enables server-side
owner filtering at scale and gateway HA, which the MVP defers). Add a
JSONB index on(object_type, (labels->>'openshell.ai/owner')). - Optional: promote owner from a label to a dedicated indexed
ownercolumn
(ObjectMetaproto field + migration) once the label approach is proven. - Provider/credential ownership (out of scope here — this issue covers
sandboxes only).
Acceptance criteria
- On a single shared gateway with OIDC enabled and two users (alice, bob):
- alice
create-> sandbox carriesopenshell.ai/owner=<alice-sub>. - bob
listdoes not include alice's sandbox; alicelistdoes. - bob
get/delete/connect/execon alice's sandbox ->PermissionDenied. - a client attempting to set
openshell.ai/owneron create has it overwritten
by the server value. openshell-adminlists/operates across all users' sandboxes.
- alice
- Behavior with OIDC disabled is explicitly defined and tested.
- e2e suite (task C) green on Kind.
Out of scope
- Per-user provider/credential ownership.
- SPIFFE/SPIRE sandbox identity.
- Postgres migration and gateway HA (tracked as follow-ups in D).
- Any upstream NVIDIA/OpenShell contribution (kagenti fork only for now).
References
docs/research/openshell-mvp.md— §5.2 (no per-user ownership), §10 (deferred)docs/research/openshell-fork-analysis.md— fork branches, image tags, store- Gateway code:
kagenti/openshellcrates/openshell-server/src/{auth,grpc,persistence}/
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
pdettori commentedon Jun 16, 2026
Task A: Implementation Plan — kagenti/openshell per-user ownership
Code audit findings
I've audited the gateway source (
crates/openshell-server/src/grpc/sandbox.rs,service.rs,policy.rs) and confirmed the issue's mapping. Here's the complete list of handlers that resolve a sandbox by name/ID — all need ownership enforcement:handle_create_sandboxRequest<CreateSandboxRequest>handle_get_sandboxRequest<GetSandboxRequest>handle_list_sandboxesRequest<ListSandboxesRequest>handle_delete_sandboxRequest<DeleteSandboxRequest>handle_watch_sandboxRequest<WatchSandboxRequest>handle_exec_sandboxRequest<ExecSandboxRequest>handle_exec_sandbox_interactiveRequest<Streaming<ExecSandboxInput>>handle_forward_tcpRequest<Streaming<TcpForwardFrame>>handle_create_ssh_sessionRequest<CreateSshSessionRequest>handle_expose_serviceservice.rs)Request<ExposeServiceRequest>handle_attach_sandbox_providerRequest<AttachSandboxProviderRequest>handle_detach_sandbox_providerRequest<DetachSandboxProviderRequest>Additional paths via
policy.rs:handle_get_sandbox_config,handle_get_sandbox_policy_status,handle_get_sandbox_logs,handle_get_sandbox_provider_environment— these already extractPrincipalfrom extensions for sandbox-caller validation.Current state
Principalis inserted intoreq.extensions_mut()atmultiplex.rs:470— available to all handlersrequest.into_inner()immediately, discarding extensions (except policy.rs)AuthzPolicy.check()validates roles/scopes but has no resource-level ownership checkObjectMetaand are validated/stored already (including label-selector filtering in the store)Proposed implementation structure
auth/ownership.rs— single module containing:const OWNER_LABEL: &str = "openshell.ai/owner"+ reserved prefix"openshell.ai/"fn sanitize_subject(subject: &str) -> Result<String, Status>— UUID passthrough, hash fallback for non-conforming subjectsfn stamp_owner(labels: &mut HashMap<String, String>, principal: &Principal) -> Result<(), Status>— strips reserved keys, sets ownerfn check_owner(sandbox: &Sandbox, principal: &Principal, admin_role: &str) -> Result<(), Status>— returnsPermissionDeniedif not owner and not adminfn owner_selector(principal: &Principal, existing_selector: &str) -> Result<String, Status>— ANDs owner filter for listPattern for handler changes
Streaming handlers (exec_interactive, forward_tcp)
These call
request.into_inner()to get the stream, discarding extensions. The fix: extractPrincipalfrom extensions before consuming the request:Questions / decisions needed
Name uniqueness scope (issue calls this out): Do we go with (a) server-prefix stored name with owner token, (b) globally unique names (simplest, current behavior preserved), or (c) owner-scoped uniqueness? I'd lean toward (b) for v1 — simplest, no store changes, document the constraint. Thoughts?
OIDC-disabled behavior: When
OPENSHELL_OIDC_ENABLED=false, thePrincipalin extensions is eitherAnonymousorLocalDev. Proposal: skip ownership entirely when principal isAnonymous(backward compat with existing single-user local dev). ForLocalDev/Mtlsprincipals, stampidentity.subjectas owner normally.authz_policy.admin_role: TheAuthzPolicystruct is available onServerState(via config). I'll usestate.authz_policy.admin_rolefor the admin-bypass check. Confirm this is the right place (vs. a separate ownership config)?Commit plan (incremental, each green)
auth/ownership.rswith constants, sanitizer,stamp_owner,check_owner,owner_selector+ unit testsstamp_ownerintohandle_create_sandbox(strips reserved keys, stamps owner) + testsowner_selectorintohandle_list_sandboxes+ testscheck_ownerinto get/delete/watch/exec/ssh/service handlers + testsEach commit adds at least one new passing test. No reverts, no amends.
pdettori commentedon Jun 16, 2026
Per-User Resource Ownership — Extended Requirements (Providers, Inference, Policy)
Findings from live testing
Sandbox ownership (Task A/B/C) is working correctly on Kind:
However, providers and inference routes are currently shared/admin-scoped resources with no per-user isolation. This creates a gap for credentials that are inherently per-user (e.g., personal GitHub PATs, individual API keys).
Current scoping model (as-is)
userroleopenshell.ai/owner)adminroleadminroleopenshell inference set) are cluster-wide routing rules (provider + model → endpoint). Admin-only write.Requirements for per-user providers (Option A)
Goal: Allow regular users to create their own providers with personal credentials, invisible to other users on the same gateway.
Design
create_providerauth fromadmin→user(or add a newcreate_user_providerRPC withuserrole).openshell.ai/ownerto providers — same pattern as sandboxes:ghwithout conflict.Shared vs. user-owned providers
openshell.ai/owner=<sub>A sandbox can reference:
Inference routes: no change needed
Inference routes are routing configuration (provider → model → endpoint), not credentials. They should remain admin-only and gateway-wide:
openshell inference set --provider claude --model claude-sonnet-4-6inference.local— applicable to all sandboxes regardless of ownerIf a user-owned provider is bound to a sandbox, the inference route uses that provider's credentials (the user's personal key), even though the route itself is shared config.
Policy: no change needed
Policies are already per-sandbox (embedded in sandbox spec). Since sandboxes are per-user, policies are inherently per-user. No additional scoping needed.
Summary of work
openshell.ai/owneron providers, relax create auth(owner, name)not justnameNext step
Create a dedicated follow-up issue for per-user provider ownership (this issue's acceptance criteria are met for sandbox ownership).
feat(openshell): add per-user sandbox ownership e2e tests and docs (r…