Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 63 additions & 4 deletions docs/arch/17-token-exchange-delegation.md
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,12 @@ delegate_clients:
subject_token_audiences: [https://api.example.com]
exchange_refresh_tokens:
id_jag_max_lifetime: 12h
id_jag:
targets:
- issuer: https://as.partner.example.com
client_id: toolhive-broker
resources: [https://mcp.partner.example.com/mcp]
lifetime: 60s
```

Example: a plain access-token delegate. For self-issued subject tokens, it
Expand Down Expand Up @@ -928,6 +934,10 @@ Startup refuses a configuration that breaks any of these rules:
covered by one of the client's `audiences`.
- `audiences` is empty without `exchange_refresh_tokens`, or is empty while
`grant_types` includes a grant other than token exchange.
- `id_jag` is set without token exchange enabled, without
`self_issued_subject_tokens: restricted`, without
`exchange_refresh_tokens.id_jag_max_lifetime`, or with an empty `targets` list.
- An `id_jag` target breaks a rule in [ID-JAG targets](#id-jag-targets).

Policy edits take effect on restart. The policy is built once at startup and
is not stored with the client.
Expand All @@ -938,6 +948,54 @@ secret-authenticated delegate client may omit both `grant_types` and the block.
client that sets `grant_types`, or uses `private_key_jwt`, must declare the block
and the mode.

### ID-JAG targets

A delegate client that holds ID-JAG grants can list the authorization servers it
may later get an ID-JAG for. Set `token_exchange.id_jag.targets` on the client.
Nothing issues an ID-JAG yet. At startup the block only builds the runtime
policy. The policy is keyed by the issuer exactly as configured. At request time
the client's `audience` parameter must equal it exactly. These settings are RunConfig-only: no CRD exposes `id_jag`.

Each target has these fields:

- `issuer`: the other authorization server's issuer. The client sends it as the
request's `audience`, and it becomes the ID-JAG's `aud` exactly as written. The
target server compares `aud` to its issuer as an exact string (RFC 8414,
RFC 7519), so the value must match the target's published issuer byte for byte.
Startup refuses an issuer that is not well-formed. It must be an absolute
`https` URL, or `http` on a loopback host, with a lower-case scheme and host,
no explicit default port (`:443` for `https`, `:80` for `http`), no query,
fragment or userinfo, no dot segments, no empty path segments, no unneeded
percent-encoding and no leading zeros in the port. One trailing slash is
allowed and kept as written. `https://as.example.com` and
`https://as.example.com/` are different issuers. The issuer must be unique
within the client, and the `(issuer, client_id)` pair must not be used by
another delegate client. These two checks ignore one trailing slash. The issuer
must not equal this server's issuer, its token endpoint (issuer plus
`/oauth/token`) or one of its `allowed_audiences`. This check also ignores case
in the scheme and host and a default port, because this server's own values are
not held to the well-formed rule.
- `client_id`: required. This client's `client_id` at the other authorization
server. The `(issuer, client_id)` pair must not be used by another delegate
client.
- `resources`: at least one, each a valid RFC 8707 resource URI, with no
duplicates.
- `lifetime`: a Go duration in whole seconds. It must be above zero and at most
`300s`. The default is `60s`.
- `required_subject_claims`: optional. Values are `upstream_subject` and
`sub_id`, with no duplicates. A config file cannot set it: it is not
serialized to or from JSON or YAML. Only Go callers that build the RunConfig or
Config in code can set it, together with `SubjectIdentifierAudiences` through
the `WithSubjectIdentifierAudiences` runner option. Each entry needs every
`token_exchange.subject_token_audiences` entry to be in
`SubjectIdentifierAudiences`. The runner checks this before upstream
registration.

A client with `exchange_refresh_tokens.id_jag_max_lifetime` and no
`id_jag.targets` logs one DEBUG line at startup. It says the client can hold
ID-JAG grants but cannot mint ID-JAGs. The line is DEBUG until ID-JAG issuance
exists.

### Worked example

This is the scenario the relaxation exists for (issue #5194): an interactive
Expand Down Expand Up @@ -1936,16 +1994,17 @@ internal and is never sent to the client.

## Implementation

- `pkg/authserver/server/tokenexchange/handler.go` — `checkSourcePolicy`, `ConfiguredClientPolicy`, `checkDelegationConsent`, `grantScopes`, `grantAndBoundAudiences`, `externalOrigin`
- `pkg/authserver/server/tokenexchange/handler.go` — `checkSourcePolicy`, `ConfiguredClientPolicy`, `checkDelegationConsent`, `grantScopes`, `grantAndBoundAudiences`, `externalOrigin`, `IDJAGTarget`, `ConfiguredClientPolicy.IDJAGTargets`
- `pkg/authserver/server/tokenexchange/refresh_token_handler.go` — `RefreshTokenHandler`, `isRefreshTokenExchange`, `checkLoginToken`, `checkExchangeGrantSubject`
- `pkg/authserver/server/tokenexchange/exchange_grant.go` — the exchange-grant entry type and its validation
- `pkg/authserver/server/tokenexchange/multi_issuer_validator.go` — `MultiIssuerTokenValidator`, `TrustedIssuer`, `resolveActorAuthorization`, `ValidateJWKSURL`
- `pkg/authserver/server/tokenexchange/validator.go` — `assignClaim`, `buildValidatedClaims`, `validateMayActShape`, `scpToScopeString`
- `pkg/authserver/config.go` — `DelegateClientRunConfig`, delegate-client validation, `validateTrustedIssuerURL`, `validateJWKSEndpointURL`, `validateTrustedIssuers`, `warnTrustedIssuerAudiences`
- `pkg/authserver/config.go` — `DelegateClientRunConfig`, delegate-client validation, `validateTrustedIssuerURL`, `validateJWKSEndpointURL`, `validateTrustedIssuers`, `warnTrustedIssuerAudiences`, `validateIDJAG`, `validateIDJAGTarget`, `claimIDJAGTargets`, `validateIDJAGSubjectClaims`, the exported `ValidateIDJAGSubjectClaimAudiences` (called by the runner before upstream registration), the issuer comparison used by the reserved check
- `cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go` — `DelegateClientConfig`, `TrustedIssuerConfig`, `EmbeddedAuthServerConfig`
- `cmd/thv-operator/pkg/controllerutil/authserver.go` — `buildDelegateClientRunConfigs`, `buildTrustedIssuerRunConfigs`, `BuildAuthServerRunConfig`
- `pkg/authserver/runner/embeddedauthserver.go` — delegate-client secret-reference resolution at startup
- `pkg/authserver/server_impl.go` — static delegate-client registration and precedence over an existing storage registration
- `pkg/authserver/runner/embeddedauthserver.go` — delegate-client secret-reference resolution at startup, and the early `id_jag` check
- `pkg/authserver/server_impl.go` — static delegate-client registration and precedence over an existing storage registration, `idJAGTargetPolicies`, the DEBUG log in `configuredClientPolicies`
- `pkg/authserver/server/endpoints.go` — `TokenEndpointPath`
- `pkg/authserver/server/handlers/discovery.go` — advertised token-exchange and JWT-bearer grants, client-secret authentication methods
- `cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go` — shared `DelegateClientConfig` CRD contract
- `cmd/thv-operator/pkg/controllerutil/authserver.go` — Secret-reference to pod-environment conversion
Expand Down
42 changes: 42 additions & 0 deletions docs/server/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions docs/server/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions docs/server/swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading