Repository navigation
Description
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}andResolver.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, neverinvalid_grant). - The returned user is the canonical user ID that travels as the
serveridentitycanonical-user context key. There is no separate type.
- Never creates a user, and never returns
- Standalone implementation from ToolHive's provider-identity records, without the create path. It lives in its own
pkg/authserver/subjectresolverpackage, not inpkg/authserver/subject: it needsUserStorage, andpkg/authserver/subjectstays a leaf that imports nothing else from ToolHive, so embedders and the vMCP can implement or use the interface without pulling in storage. It mapsstorage.ErrNotFoundtoErrUnknownand any other storage error toErrUnavailable.- It maps
Ref.Issuerto the configured identity-provider upstream with that issuer, checks thatRef.Claimis that upstream's subject claim, then callsUserStorage.GetProviderIdentity(<provider name>, Ref.Value), loads that row's user withGetUser, and returns the user's ID. A row whose user is gone isErrUnknown: Redis deletes the user before it cleans up the user's rows, best effort. It adds no storage method. GetProviderIdentityitself stays keyed by provider name for interactive login. TheResolverinterface is keyed byRef, 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, returnsErrUnknown. 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.
- It maps
- 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
actcounts. Ifacthas noiss, its issuer is the token'siss(Okta'sacthas none). With noact, there is no actor. - One actor source per issuer,
act(default) orclient, with no fallback between them. Entra never emitsactand names the agent as the client. With sourceact, a token withoutactis 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
Policywith 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
Policyerror means it could not decide, for example a directory that is down. Callers answerserver_error, as forErrUnavailable. A denial is aDecision, never an error.
-
Decision.Reasonis 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 onsubfor 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 (nestedact,actwithoutiss, noact, sourceclient), 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
Add subject resolver types
Add standalone subject resolver
Add actor policy package
Validate the binding claim for delegated access
Add mocks for the resolver and actor policy