Skip to content

Add upstreamCredentialScope opt-in and enforce its issuer trust #6403

Not planned

Description

@jhrozek

Delegated access (#6406 "Delegated client access to a user's connections") will let a delegated token read a stored upstream OAuth credential when it carries the delegated-access marker (#6404 "Add a delegated-access marker that gates credential lookup for approved delegated tokens"). That marker is trustworthy for credential lookup only when the token carrying it was validated as issued by the embedded ToolHive authserver that owns the credential namespace.

Note: an earlier PR for this issue (#6458) was closed; this needs a new PR.

This issue prepares the configuration and trust-enforcement seams for that capability. It does not implement platform-user storage, a functioning UserTokenReader, or agent credential retrieval.

Compatibility contract

Existing deployments must see zero runtime behavior change on upgrade.

Add upstreamCredentialScope to EmbeddedAuthServerConfig (cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go, alongside PrimaryUpstreamProvider and DisableUpstreamTokenInjection):

  • session (permanent default): today's behavior, unchanged. The existing session-based TokenReader remains wired exactly as it is today. UserTokenReader remains nil, so none of the new issuer checks run.
  • platformUser: explicit opt-in to the future durable-user credential model. In this preparatory issue the value is validated and propagated, but runtime activation must fail explicitly as unsupported until the storage-layer issue supplies and wires a functioning UserTokenReader.

Use +kubebuilder:default=session. An object that omits the field, including every object created before this field existed, behaves identically to one that explicitly sets session. The default is permanent; there is no plan to flip it in a later release.

Only a genuinely absent value maps to session. Reject unknown non-empty values; never silently reinterpret a garbage value as the default.

The effective-default rule must also exist in Go configuration handling. Kubernetes defaulting does not cover old serialized RunConfigs, direct vMCP YAML, or direct Go construction.

Scope: trust plumbing only

Introduce a distinct UserTokenReader capability for future durable platform-user lookup, separate from the existing session-based TokenReader.

This issue must:

  1. Add and propagate upstreamCredentialScope through the shared embedded-authserver RunConfig used by the proxy runner and vMCP.
  2. Preserve all existing TokenReader, WithUpstreamTokenReader, MiddlewareRunner.GetUpstreamTokenReader, and session/tsid behavior without signature or semantic changes.
  3. Add the UserTokenReader interface/option seam needed by the later storage work.
  4. Reuse the existing embedded-authserver issuer option (WithEmbeddedAuthServerIssuer, pkg/auth/token.go ~574) for the issuer precondition instead of adding a new field.
  5. Make NewTokenValidator enforce the strict issuer precondition only when a non-nil UserTokenReader is supplied.
  6. Add scope-gated operator and vMCP configuration validation so the same issuer rule is ready at every entry point.
  7. Reject runtime activation of platformUser as unsupported until the separate storage implementation can construct and wire a real UserTokenReader. Do not silently start in session mode and do not install a no-op reader.

The later storage issue will remove the unsupported activation error when it implements platform-user row semantics and wires the reader.

Trust precondition

When UserTokenReader is non-nil:

  • The embedded-authserver issuer (from WithEmbeddedAuthServerIssuer) must be non-empty.
  • The incoming OIDC issuer validated by the token validator must exactly equal it.
  • Mismatch or absence is a constructor error.
  • There is no fallback to the session reader.

For session scope, UserTokenReader is nil and these checks do not execute.

Example:

scope omitted/session
incoming issuer: https://login.corp.example
embedded AS:     https://auth.example
    -> preserve existing runtime behavior

scope platformUser
incoming issuer: https://login.corp.example
embedded AS:     https://auth.example
    -> reject the new capability configuration

scope platformUser
incoming issuer: https://auth.example
embedded AS:     https://auth.example
    -> trust validation succeeds, then runtime reports that
       platform-user storage is not yet implemented by this issue

Operator validation

Update validateOIDCConfigForEmbeddedAuthServer in cmd/thv-operator/pkg/controllerutil/authserver.go carefully:

  • Preserve all existing session-mode validation behavior.
  • Apply the new issuer-presence and exact-equality checks only when the effective scope is platformUser.
  • Do not gate or otherwise change existing audience/resource checks that already apply to session mode.

The operator should surface invalid platformUser trust configuration before rollout. Session-mode resources, including legacy resources with absent, empty, or mismatched issuers that were previously accepted, must not acquire a new failure solely because of this issue.

vMCP CLI validation

pkg/vmcp/cli/serve.go currently does not call ValidateAuthServerIntegration after side-loading the embedded authserver configuration.

Call it, but gate the newly introduced issuer-presence/equality requirements inside ValidateAuthServerIntegration on effective scope platformUser. Calling the validator must not make existing session-mode vMCP configuration fail after upgrade.

Runtime configuration

Add the scope to the shared authserver.RunConfig, because both proxy runner and vMCP consume that configuration.

Runtime rules:

  • omitted/empty -> effective session;
  • session -> existing runtime behavior;
  • platformUser -> validate trust configuration, then return an explicit unsupported-capability error until the storage implementation lands;
  • any other non-empty value -> configuration error.

An older runtime must not silently ignore an explicitly configured platformUser capability. If current RunConfig version handling cannot guarantee that, add an explicit required-capability/version check rather than relying on unknown-field behavior.

Existing runner behavior

The existing reader in pkg/runner/runner.go is not discarded: it is stored on the runner and obtained by the auth middleware through GetUpstreamTokenReader. Leave that path unchanged.

This issue adds a separate future UserTokenReader seam. It must not convert, wrap, or reinterpret the existing session reader as proof of platform-user trust.

Acceptance tests

Compatibility

  • Omitted scope behaves identically to explicit session.
  • Session mode preserves the existing session TokenReader wiring.
  • Session mode never constructs or attaches UserTokenReader.
  • Session mode does not run the new issuer-presence/equality checks.
  • Existing session-mode operator and vMCP configurations with mismatched issuers retain their previous result.
  • Existing public session-reader APIs and generated mocks remain source-compatible.

Enum/config propagation

  • CRD schema accepts session and platformUser and defaults omission to session.
  • Direct RunConfig handling maps only empty to session.
  • Unknown non-empty values fail validation.
  • CRD-to-RunConfig conversion preserves the selected value for MCPServer and VirtualMCPServer paths.

Trust boundary

Using a mock UserTokenReader supplied directly to NewTokenValidator:

  • matching incoming and authserver issuers succeeds;
  • empty incoming issuer fails;
  • empty authserver issuer fails;
  • mismatched issuers fail;
  • a trailing-slash/string mismatch fails exactly rather than being normalized;
  • no UserTokenReader preserves legacy constructor behavior.

Dormant platform-user activation

  • platformUser with invalid issuer configuration fails with the actionable trust error.
  • platformUser with valid issuer configuration fails explicitly as unsupported until storage support lands.
  • It never falls back to session lookup and never installs a no-op reader.

Explicitly out of scope

  • Platform-user storage keys or authoritative row/pointer design.
  • A functioning UserTokenReader implementation.
  • Construction or runtime wiring of a real UserTokenReader.
  • Reading credentials by the delegated-access marker or canonical user ID (Ownership-checked credential read for delegated tokens, keyed by user and routed provider #6407).
  • One-row-per-(platformUser, provider) write semantics.
  • Account replacement, refresh compare-and-swap, rollback, logout, and revocation semantics.
  • Storage migration or mode-switch tooling.
  • Per-agent/act.sub credential binding.

Those behaviors belong to the dependent storage and agent-credential issues. This issue only establishes a backward-compatible configuration surface and a fail-closed trust seam that those later changes must use.

Files

Expected areas include:

  • cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go — enum and field.
  • Generated CRDs/deepcopy/operator API documentation.
  • pkg/authserver/config.go — serialized scope, effective default, and validation.
  • cmd/thv-operator/pkg/controllerutil/authserver.go — CRD-to-RunConfig propagation and scope-gated cross-config validation.
  • pkg/auth/token.go — separate UserTokenReader option and conditional issuer validation.
  • pkg/runner/runner.go — preserve existing session reader; reject unsupported platformUser activation until storage wiring exists.
  • pkg/vmcp/config/validator.go and pkg/vmcp/cli/serve.go — scope-gated validation with no session-mode behavior change.
  • Unit and operator integration tests for compatibility, propagation, and dormant activation.

Activity

  1. added
    bug
    on Aug 20, 2026
  2. added
    needs-triage
    on Aug 20, 2026
  3. changed the title [-]Enforce token-validator trust precondition for the AS issuer everywhere it's wired[/-] [+]Add upstreamCredentialScope opt-in and enforce its issuer trust[/+] on Aug 21, 2026
  4. jhrozek commented on Nov 24, 2026

    @jhrozek
    ContributorAuthor

    Closing as superseded. There's no keying setting any more: Go embedders
    opt in with a typed option ("User-keyed upstream storage behind the
    embedder option" (#7263)), and runner-built deployments move to per-user storage
    in "Re-authorization walks the full upstream chain instead of evaluating existing credentials" (#6831). Two leftovers: the missing ValidateAuthServerIntegration call
    in pkg/vmcp/cli/serve.go moved to the new issue. Refusing user keying
    with a synthetic first upstream is not carried over: a synthetic user has
    rows of its own and nothing else reads them.

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

    authenticationbugneeds-triagesecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions