Skip to content

feat: read-only Vault references for externally managed provider credentials #5881

Open

Description

@laik

User Story

I run OpenShell gateways against an enterprise HashiCorp Vault where a separate publishing system owns and rotates secret values. I need OpenShell providers to consume those existing Vault secrets read-only, so sandboxes always use the current published value while Vault remains the single source of truth.

Problem Statement

The Vault credential driver is a gateway-owned storage backend: credential values are written to a managed path (openshell/provider-credentials/<hash>) derived from workspace/provider/credential identity, and any other logical path is rejected. There is no way to point a provider credential at an existing Vault path and have the gateway read it in place.

Impact / Why This Matters

  • To use a value already published to Vault, operators must read it out and re-enter it through provider create/update. The secret then exists in two places, and the OpenShell copy goes stale whenever the publishing system rotates it; every rotation requires a manual re-sync.
  • In storage-only mode the Vault driver adds little over the built-in encrypted database credential store: if OpenShell only stores values it was handed, the database is equally safe. The value of Vault integration in an enterprise is consuming centrally governed secrets — rotation, audit, and access policy stay in Vault, and OpenShell is a consumer, not a second owner.
  • This blocks adoption for deployments where Vault is populated by an external secret-publishing pipeline, which is a common enterprise pattern.

Proposed Design

A provider credential can be declared as a read-only reference to an existing Vault secret instead of an OpenShell-stored value:

  • The reference names the secret location (mount, path, field; KV v1 and v2) and resolves through the configured driver address, including api_path_prefix (feat: support enterprise API path prefix in Vault credential driver URLs #5818).
  • The gateway reads the referenced value when supplying the credential to a sandbox. It never writes or deletes the referenced secret; the external publishing system remains the owner.
  • Rotations performed by the external system are picked up without operator action, either at credential supply time or on the existing credential refresh cadence.
  • A missing or unreadable referenced path fails closed with an actionable error; no stale or empty value is injected.
  • Deleting the provider removes only the reference, never the external secret.

Suggested UX

Notional, for human review:

openshell provider create --name corp-api --type corp-api \
  --credential-ref API_TOKEN=vault://secret/myapp/token#value

provider get shows the reference (mount/path/field), not the value. The exact configuration surface (CLI flag, provider config key, or driver-level mapping) is open for discussion.

Acceptance Criteria

  • A provider credential can reference an existing Vault KV path (v1 and v2) without OpenShell writing to that path.
  • A sandbox attached to the provider receives the current Vault value through normal placeholder resolution, including deployments with api_path_prefix set.
  • After the external system updates the value, subsequent credential supply reflects the update without operator action.
  • Missing or unreadable referenced paths fail closed with an actionable error.
  • Provider deletion leaves the external secret untouched.

Alternatives Considered

  • Static provider plus manual re-sync on rotation: works today, but duplicates the secret, breaks the single source of truth, and the operational cost grows with rotation frequency.
  • Built-in database credential store: equally secure for storage, but has the same copy-and-sync problem and does not consume Vault-governed secrets.
  • Custom network middleware fetching from Vault per request: would re-implement Vault auth, caching, and failure handling outside the credential model, and bypasses provider/placeholder semantics and endpoint binding.
  • A new credential refresh strategy that reads external KV: a plausible supply mechanism for this feature rather than a separate alternative; the user-facing requirement is the read-only reference itself.

Agent Investigation

  • crates/openshell-driver-vault/src/lib.rs: managed_secret_path derives openshell/provider-credentials/<sha256[..40]> from workspace/provider_id/provider_name/credential_key/object_id; validate_managed_secret_path rejects any other logical path. Handles are v1:<logical_path>. Store/read/delete all operate on this managed layout.
  • The shared URL builder from feat: support enterprise API path prefix in Vault credential driver URLs #5818 (api_path_for_reference) already applies api_path_prefix to reads, so reference reads can reuse it unchanged.
  • The server's provider refresh worker (provider_refresh sweep) is an existing cadence a periodic reference re-read could hook into.
  • Verified on a live deployment (gateway 0.1.7-api-prefix, enterprise-style prefix /v1/bu-a/): the managed write/read/delete lifecycle works end-to-end through the prefix; the gap is purely the absence of a read-only external reference mode.

Related: #5818, #5871, #5709.

Activity

  1. laik commented on Nov 22, 2026

    @laik
    Author

    Design sketch and implementation outline

    Why storage-only mode does not serve this use case

    Two points sharpen the motivation:

    1. Storage alone adds nothing. If OpenShell only stores values it was handed, the built-in encrypted database credential store is equally safe. The reason to integrate Vault is to consume secrets that stay governed by Vault — access policy, audit, and rotation — with OpenShell as a read-only consumer.
    2. Rotation actively breaks the copy. Enterprise Vault rotates secrets precisely to limit exposure. A value copied into OpenShell-managed storage goes stale on the first rotation: workloads then present a revoked secret and fail (or worse, keep working against a stale value until someone notices). Manual re-sync per rotation is not an acceptable operational model. The external publishing system must remain the single source of truth, and OpenShell must read through to it.

    Key observation: the read path is already live

    Verified on a live deployment (gateway with api_path_prefix, enterprise-style prefix /v1/bu-a/): the Vault GET happens at credential resolution time, i.e. at the moment the sandbox makes the credentialed request — the prefix proxy access log shows the GET timestamped to the request. Resolution is not a startup-time snapshot.

    Consequence: rotation-following is nearly free. If resolution reads the referenced external path instead of a managed copy, every request picks up the current published value. No cache invalidation, no new refresh strategy needed for a first version.

    Flow comparison

    Today (stored mode):
      provider create  -> store_credential -> write managed path -> handle
      sandbox request  -> resolve_credentials(handle) -> read managed path -> inject
    
    Reference mode:
      provider create --credential-ref -> NO store call; persist the reference
                                          (mount/path/field) as credential metadata
      sandbox request  -> resolve_credentials -> recognize reference -> KV GET the
                                          external path -> extract field -> inject
      provider delete  -> remove reference metadata only; external secret untouched
    

    The sandbox side (placeholders, endpoint binding, supervisor proxy) is unchanged; it only receives the value from the gateway as it does today.

    Code outline (notional sketches)

    The driver trait (openshell-credential-issuer/src/embedded.rs) has exactly three operations: store_credential, delete_credential, resolve_credentials. Reference mode is a branch in each:

    1. Credential model — a credential's source becomes a variant:

    enum CredentialSource {
        Stored { handle: CredentialHandle },              // today's behavior
        VaultRef { mount: String, path: String,
                   field: String, kv_version: KvVersion }, // new
    }

    The reference itself is not secret; it lives in provider credential metadata. Proto + CLI surface (--credential-ref KEY=vault://<mount>/<path>#<field>, shape open for discussion) follow the public API conventions in proto/README.md.

    2. Issuer branches (openshell-credential-issuer):

    • store: VaultRef -> skip store_credential, persist metadata only.
    • resolve: VaultRef -> driver read-through (below).
    • delete: VaultRef -> delete metadata only, never call delete_credential.

    3. Driver read-through (openshell-driver-vault):

    async fn resolve_reference(&self, r: &VaultRef) -> Result<String, Status> {
        let token = self.login().await?;                          // existing k8s auth
        let api = api_path_for_reference(&r.mount, r.kv_version, &r.path);
                                                                  // api_path_prefix applied (#5818)
        let resp = self.kv_get(&api, &token).await?;              // existing transport
        extract_field(resp, r.kv_version, &r.field)               // v2: data.data.<field>, v1: data.<field>
    }

    All Vault mechanics already exist: login, TLS, the shared URL builder (which applies api_path_prefix to reads unchanged), KV v1/v2 parsing. Today validate_managed_secret_path rejects any non-managed logical path on both read and delete; reference handles (e.g. v1:ref:<mount>/<path>#<field>) bypass that validation because they never enter the managed lifecycle.

    4. Authorization boundary (the main design decision)

    A reference must not let one workspace read another's secrets. Proposed: a driver-level allowlist in gateway.toml, e.g.

    [openshell.credential_drivers.vault]
    reference_path_allowlist = ["secret/tenant-a/", "secret/shared/"]

    References outside the allowlist are rejected at provider creation and at resolution (fail closed). Missing/unreadable paths fail closed with an actionable error; no stale or empty value is injected. External reads emit OCSF audit events consistent with existing credential operations.

    Scope estimate

    • proto/ + server model: reference source variant, validation (largest piece, API design).
    • openshell-credential-issuer: three branches + reference handle semantics.
    • openshell-driver-vault: read-only entry + field extraction (small; reuses feat: support enterprise API path prefix in Vault credential driver URLs #5818 builder).
    • openshell-cli: --credential-ref entry, provider get shows the reference, not the value.
    • Tests: unit + the existing Vault/OpenBao e2e fixture; docs: configuration.mdx for the allowlist field.

    Rough order: 800–1500 lines across 5–6 crates — larger than #5818 (~450 lines) but no hard blockers; the Vault read itself is one GET. The design effort concentrates on the multi-tenant path authorization and the public API shape.

    Optional later: short-TTL cache if read latency matters, KV v2 version pinning, refresh-cadence re-read for long-lived grants. None required for v1 since resolution is already live.

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

    state:triage-neededOpened without agent diagnostics and needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions