Skip to content

feat: per-user provider ownership on shared OpenShell gateway #1995

Closed

Description

@pdettori

Problem

Providers are currently gateway-wide shared resources that only admins can create. All sandboxes binding to a provider share the same credential (API key). This works for team-level LLM keys but breaks for credentials that are inherently per-user:

  • Personal GitHub PATs
  • Individual API keys with per-user billing/quota
  • OAuth tokens scoped to a user's identity
  • Any credential that should not be shared across team members

Proposed solution: per-user provider ownership (Option A)

Apply the same openshell.ai/owner pattern already proven for sandboxes to providers.

Design

  1. Relax create_provider auth from admin → user role (or add a dedicated create_user_provider RPC).
  2. Stamp openshell.ai/owner on provider create from verified OIDC identity — same mechanism as sandbox ownership.
  3. Filter provider list/get/delete by owner — users see only their own providers + shared (admin-created) providers.
  4. Sandbox-provider binding validation — a sandbox can reference:
    • Providers owned by the same user
    • Shared providers (no owner label — admin-created)
    • ❌ NOT another user's providers
  5. Provider name uniqueness scoped to (owner, name) — alice and bob can both have a provider named gh.

Shared vs. user-owned providers

Provider type Owner label Visible to Created by
Shared (team) none All users Admin
User-owned openshell.ai/owner=<sub> Owner + admin User

What does NOT change

  • Inference routes remain admin-only, gateway-wide routing config. A route references a provider by name — when a sandbox uses a user-owned provider, the inference proxy resolves that user's credential automatically.
  • Policies are already per-sandbox (inherits sandbox ownership). No change needed.
  • Admin bypass continues to work — admins can see/manage all providers.
  • OIDC-disabled mode — ownership skipped, backward-compatible (same as sandboxes).

User experience

# Bob creates his own GitHub provider with his personal PAT
export GH_TOKEN="ghp_bob_xxx"
openshell provider create --name gh --type generic \
  --credential GH_TOKEN \
  --config BASE_URL=https://api.github.com

# Alice creates her own — no conflict, scoped by owner
export GH_TOKEN="ghp_alice_yyy"
openshell provider create --name gh --type generic \
  --credential GH_TOKEN \
  --config BASE_URL=https://api.github.com

# Bob's sandbox uses Bob's key
openshell sandbox create --provider gh -- bash

# Alice's sandbox uses Alice's key — no cross-contamination
openshell sandbox create --provider gh -- bash

# Admin can still create shared team providers
openshell provider create --name claude --type anthropic \
  --credential ANTHROPIC_AUTH_TOKEN --shared

Implementation scope

Component Change
Gateway auth/ownership.rs Extend ownership to Provider object type
Gateway grpc/provider.rs Add owner stamp on create, filter on list/get/delete
Gateway grpc/sandbox.rs Validate provider binding (same-owner or shared)
Gateway store layer Provider name uniqueness scoped to (owner, name)
CLI No change needed (already sends credentials at create time)
Helm/deploy scripts No change needed

Acceptance criteria

  • On a shared gateway with OIDC enabled and two users (alice, bob):
    • alice creates provider gh with her PAT → provider carries openshell.ai/owner=<alice-sub>
    • bob creates provider gh with his PAT → no conflict, separate provider
    • bob list providers does not include alice's gh; alice's list does not include bob's
    • bob cannot bind alice's provider to his sandbox → error
    • both can use admin-created shared providers (e.g., claude)
    • admin can list/manage all providers across all users
  • Backward compatible: existing shared providers (no owner) continue to work for all users
  • e2e test covering cross-user provider isolation

Related

Activity

  1. added
    enhancement
    on Jun 16, 2026
  2. pdettori commented on Jun 16, 2026

    @pdettori
    MemberAuthor

    Implementation Analysis

    Codebase State

    PR #18 (merged to mvp-v2) established per-user sandbox ownership. The machinery lives in:

    • crates/openshell-server/src/auth/ownership.rs — stamp_owner(), check_owner(), owner_selector()
    • crates/openshell-server/src/grpc/sandbox.rs — uses all three at create/get/list/delete

    The provider handler (crates/openshell-server/src/grpc/provider.rs) currently has no ownership logic. Auth is enforced purely at the RPC level:

    Method Current auth
    create_provider role = "admin"
    get_provider role = "user" (no ownership filter)
    list_providers role = "user" (no ownership filter)
    update_provider role = "admin"
    delete_provider role = "admin"

    Implementation Plan

    graph TD
        subgraph "Phase 1: Ownership plumbing"
            A[Relax create_provider role → user] --> B[Stamp ownership in handle_create_provider]
            B --> C[Add check_owner gate on get/update/delete]
            C --> D[Add owner_selector filtering on list_providers]
        end
    
        subgraph "Phase 2: Name uniqueness scoping"
            E[Scope provider name uniqueness to owner,name] --> F[Update store layer: UniqueViolation aware of owner scope]
            F --> G[Allow alice/gh + bob/gh to coexist]
        end
    
        subgraph "Phase 3: Sandbox-provider binding"
            H[Validate provider binding on sandbox create] --> I[Provider must be same-owner or shared]
        end
    
        subgraph "Phase 4: Tests"
            J[Unit tests: cross-user isolation] --> K[Unit tests: admin bypass]
            K --> L[Unit tests: backward compat for unowned providers]
        end
    
        A --> E
        D --> H
        G --> H
    
    Loading

    Key Design Decisions

    1. Ownership module is generic enough — stamp_owner, check_owner, owner_selector work on any HashMap<String, String> labels. The module docstring says "sandbox" but the code is entity-agnostic. I'll update the docstring.

    2. Name uniqueness scoping — Currently the store enforces name uniqueness per ObjectType (i.e., all providers share a single namespace). For (owner, name) scoping, two approaches:

      • (a) Composite name: encode as {owner}/{name} internally, expose name in API responses — simplest, no store changes
      • (b) Store-layer label-aware unique constraint: more correct but more invasive

      Recommendation: Option (a) — composite key {owner_value}:{name} in the store, with the API layer stripping the prefix. This parallels how sandbox ownership works with label selectors. Shared providers (admin-created) use an empty prefix.

    3. rpc_auth role changes:

      • create_provider: admin → user (any authenticated user can create their own)
      • update_provider: admin → user (ownership check inside handler gates access)
      • delete_provider: admin → user (same)
      • get_provider / list_providers: stays user (ownership filtering added inside handler)
    4. Backward compatibility: Existing providers without openshell.ai/owner label → treated as shared (visible to all, manageable by admin). Same pattern as sandbox ownership.

    5. OIDC-disabled mode: When principal is None, skip ownership stamping — provider behaves as shared. Same backward-compat path as sandboxes.

    Acceptance Test Plan

    • Two-user scenario (alice, bob) on shared gateway with OIDC:
      • alice creates provider gh → stamped with her owner label
      • bob creates provider gh → no conflict, separate record
      • bob list → sees only bob's gh + any admin-created shared providers
      • bob cannot get/update/delete alice's provider → PermissionDenied
      • admin can list/manage all providers
    • Pre-existing shared providers (no owner label) remain accessible to all users
    • Sandbox-provider binding validates ownership alignment

    Work Plan

    Branch: feat/per-user-provider-ownership-1995 off mvp-v2 in kagenti/OpenShell

    Estimated: 4-5 commits (ownership plumbing, name scoping, binding validation, tests, docstring updates)

  3. pdettori commented on Jun 17, 2026

    @pdettori
    MemberAuthor

    Progress: Per-user provider ownership — Implementation started

    Branch: feat/per-user-provider-ownership-1995 on kagenti/OpenShell (commit 32ae5d4c)

    Completed

    Task Status Summary
    1. Make ownership module entity-generic ✅ ownership.rs docstring updated; stamp_owner, check_owner, owner_selector already work for any entity
    2. Add ownership stamping/checking to provider CRUD ✅ All 7 provider mutation handlers guarded
    5. Unit tests for ownership isolation ✅ 12 tests covering create/get/list/update/delete with owner, non-owner, admin, and shared scenarios

    Approach

    flowchart LR
        subgraph "Role relaxation"
            A[provider CRUD] -->|was| B[admin role]
            A -->|now| C[user role]
        end
        subgraph "Ownership enforcement"
            D[create] --> E[stamp openshell.ai/owner]
            F[get/update/delete/refresh] --> G[check_provider_owner]
            H[list] --> I[filter: own + shared]
        end
        subgraph "Admin bypass"
            J[admin role] --> K[sees all, mutates all]
        end
    
    Loading

    Key design decisions:

    • Provider methods relaxed from role = "admin" → role = "user" (except ImportProviderProfiles / DeleteProviderProfile which remain admin — they're system-level operations)
    • Ownership check happens in the handler after RBAC, same pattern as sandbox ownership (PR Change PoC to demo #18)
    • Shared providers (no owner label) remain visible and usable by all users — backwards compatible with pre-ownership providers
    • Spoofed owner labels in create requests are overwritten with the caller's subject
    • Update preserves existing owner label (internally clones existing record, so label can't be tampered)

    Deferred (follow-up)

    Task Notes
    3. Scope provider name uniqueness to (owner, name) Requires store-layer changes to put_if / name-uniqueness constraints
    4. Validate provider-sandbox binding ownership alignment Cross-entity check: sandbox can only reference own or shared providers

    These are lower-risk enhancements that can be done in a separate PR once the core ownership enforcement is merged.

    Test results

    All 796 unit tests pass (12 new ownership isolation tests + 784 pre-existing).

  4. added a commit that references this issue on Jun 17, 2026
    bea0db4
  5. added 2 commits that reference this issue on Jun 23, 2026
    95b262b
    8277d6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions