Skip to content

Delegated access: subject resolver and actor policy packages #7157

Open

Description

@jhrozek

Problem: Mapping a delegated token to a local user, and deciding whether its acting agent is allowed, will be done in several places: ID-JAG redemption at the gateway's authorization server ("Delegated access: subject mapping at ID-JAG redemption", #6887), the vMCP's direct route ("Accept directly presented tokens from configured issuers at the vMCP", to be filed), and later token exchange ("Delegated access: tokens and actors from third-party issuers", #7159). Each must reach the same answer for the same token, and embedders must be able to plug in their own user directory.

Change: two leaf packages under pkg/authserver, next to pkg/authserver/identity, that import nothing else from ToolHive. The authorization server's token-exchange handlers can use them without depending on pkg/auth, and the vMCP and embedders can import them without pulling in the rest of the server. No caller changes in this issue, except tests. Design: delegated-access proposal sections 2.1 (resolver) and 2.2 (actor).

pkg/authserver/subject

  • Ref{Issuer, Claim, Value} and Resolver.Resolve(ctx, Ref) (string, error).
    • Never creates a user, and never returns "" with a nil error. Callers treat an empty user as an error anyway.
    • Errors: ErrUnknown (no local user: refuse; the standalone resolver knows only found or not found), ErrAmbiguous (two local users for one identity: refuse), ErrUnavailable (503 / server_error, never invalid_grant).
    • The returned user is the canonical user ID that travels as the serveridentity canonical-user context key. There is no separate type.
  • Standalone implementation from ToolHive's provider-identity records, without the create path. It lives in its own pkg/authserver/subjectresolver package, not in pkg/authserver/subject: it needs UserStorage, and pkg/authserver/subject stays a leaf that imports nothing else from ToolHive, so embedders and the vMCP can implement or use the interface without pulling in storage. It maps storage.ErrNotFound to ErrUnknown and any other storage error to ErrUnavailable.
    • It maps Ref.Issuer to the configured identity-provider upstream with that issuer, checks that Ref.Claim is that upstream's subject claim, then calls UserStorage.GetProviderIdentity(<provider name>, Ref.Value), loads that row's user with GetUser, and returns the user's ID. A row whose user is gone is ErrUnknown: Redis deletes the user before it cleans up the user's rows, best effort. It adds no storage method.
    • GetProviderIdentity itself stays keyed by provider name for interactive login. The Resolver interface is keyed by Ref, so an embedder can plug in a directory lookup instead.
    • Provider-identity rows are written only on the first sign-in leg, the identity provider (callback.go: later legs carry the user from the first). So only the identity-provider upstream can resolve. An issuer from a later leg, such as GitHub, returns ErrUnknown. Synthetic identities have no row and never resolve.
    • The read is agreed with the storage track, which owns pkg/authserver/storage, before this issue is final.
  • Cross-issuer mapping in configuration (one identity provider using different issuers for sign-in and for access tokens, such as an Okta custom authorization server's uid) moved to "Delegated access: tokens and actors from third-party issuers" (Delegated access: tokens and actors from third-party issuers #7159), its only consumer. The standalone resolver already accepts several issuers for one provider; nothing configures it yet.

pkg/authserver/actor

  • Actor{Source, Issuer, Subject, Claims}, Request{TokenIssuer, ClientID, Actor, User, Resource}, Decision{Allow, Reason, Principal}, Policy.Evaluate.
  • Effective actor: only the outermost act counts. If act has no iss, its issuer is the token's iss (Okta's act has none). With no act, there is no actor.
  • One actor source per issuer, act (default) or client, with no fallback between them. Entra never emits act and names the agent as the client. With source act, a token without act is refused.
  • The client is a separate input and never the actor, except when the issuer's source is client. The source is recorded in the decision, for later audit.
  • Default implementation: one policy per token issuer, which allows an actor whose issuer is the token's own issuer or one of the issuers configured to act through it. Embedders may implement Policy with a directory lookup.
    • A subject allowlist and a CEL expression over the actor are left out until a consumer needs them. Neither the subject mapping nor the third-party issuers work configures them, and a second actor CEL dialect next to the token-exchange actor matcher should come with a consumer.
    • A Policy error means it could not decide, for example a directory that is down. Callers answer server_error, as for ErrUnavailable. A denial is a Decision, never an error.
  • Decision.Reason is a stable string, so callers can map it to a reason code ("Authorization server: reason codes in error_description for ID-JAG redemption refusals", Authorization server: reason codes in error_description for ID-JAG redemption refusals #7030).

Configuration validation

  • The binding claim: rejects known mutable claim names (email, preferred_username, upn, unique_name, name, nickname, given_name, family_name, phone_number, mail, login, username, in any letter case); a claim that passes is not proven stable. Warns on sub for Okta custom authorization servers. Exported so the authorization server's and the vMCP's configuration share it.

Tests

  • subject: a table for the standalone resolver (found; no row; row for another provider; issuer with no upstream; claim not the upstream's subject claim; storage error), and a test that no path returns "" with a nil error.
  • actor: a table for the effective actor (nested act, act without iss, no act, source client), the default policy (actor issuer allowed or not, a request for another token issuer), and the stable reasons.
  • Binding-claim validation: each rejected claim, and the Okta warning.
  • Both packages import nothing else from ToolHive. No import test or depguard rule guards this: the Go compiler refuses an import cycle if one ever forms, and the callers already depend on pkg/authserver, so a guard added little.

Consumers

The first callers are "Delegated access: subject mapping at ID-JAG redemption" (#6887) (ID-JAG redemption) and the direct route. "Delegated access: tokens and actors from third-party issuers" reuses both packages for token exchange and foreign actor tokens.

Activity

  1. added 5 commits that reference this issue on Nov 22, 2026
    5359b64
    a9d9f5e
    0140f96
    f00332e
    24cfd3b
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

    authenticationenhancementNew feature or requestgoPull requests that update go codeneeds-triageIssue needs initial triage by a maintainersecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions