From 008f3ae03f3a3fd08e58a699bb8b764f3522ef4c Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 13 Nov 2026 15:48:28 +0100 Subject: [PATCH 1/2] Require the actor token for actor profiles A client with an actor profile is configured to have every ID-JAG it obtains checked by an actor-token validator. Add the request-side half of that check: the client must send exactly one non-empty actor_token and exactly one actor_token_type equal to its profile's type, else invalid_request. The check runs with the other request-shape checks, before the target lookup and before any grant is read. Clients without a profile keep refusing both parameters. Main refuses a profiled client with server_error before reading any parameter. That guard stays, moved after the actor and target checks, so a malformed request now gets its own error while a well-formed one still gets no ID-JAG until issuance calls the validator. The change that adds the call replaces the guard. The presented actor token is carried in the request shape for that call. The token type is not carried, since it always equals the profile's. Co-authored-by: Mecatl --- docs/arch/17-token-exchange-delegation.md | 69 ++++++---- .../server/tokenexchange/id_jag_mint.go | 88 ++++++++---- .../server/tokenexchange/id_jag_mint_test.go | 126 +++++++++++++++--- .../tokenexchange/refresh_token_id_jag.go | 2 +- .../refresh_token_id_jag_test.go | 52 ++++++++ 5 files changed, 266 insertions(+), 71 deletions(-) diff --git a/docs/arch/17-token-exchange-delegation.md b/docs/arch/17-token-exchange-delegation.md index 5efc094162..5c62cb1e78 100644 --- a/docs/arch/17-token-exchange-delegation.md +++ b/docs/arch/17-token-exchange-delegation.md @@ -2080,9 +2080,11 @@ grant_type=urn:ietf:params:oauth:grant-type:token-exchange ``` `audience` must be exactly one target `issuer` and `resource` exactly one of -that target's `resources`, both as written. `scope`, `authorization_details` -and `actor_token` are refused. Unknown parameters, including `sub`, are -ignored. The response is `200` with `Cache-Control: no-store`: +that target's `resources`, both as written. `scope` and `authorization_details` +are refused. `actor_token` and `actor_token_type` are refused too, unless the +client has an actor profile, which must send both (see [Required actor +parameters](#required-actor-parameters)). Unknown parameters, including `sub`, +are ignored. The response is `200` with `Cache-Control: no-store`: ```json { @@ -2102,11 +2104,15 @@ are listed in "Claims and subject". The server stops at the first check that fails: 1. The client: confidential, with the token-exchange grant, and with both - `exchange_refresh_tokens` and `id_jag.targets`. A client with an actor - profile then gets `400 unauthorized_client` before anything else is - checked (see [Fail-closed guard](#fail-closed-guard)). -2. The request shape, then a target of this client that lists the `resource`. - Nothing is read from the store yet. + `exchange_refresh_tokens` and `id_jag.targets`. +2. The request shape: `subject_token`, `audience`, `resource`, then `scope` and + `authorization_details` (refused). Then the actor parameters: a client + without an actor profile has `actor_token` and `actor_token_type` refused, + and a client with one must send them (see [Required actor + parameters](#required-actor-parameters)). Then a target of this client that + lists the `resource`. A client with an actor profile is then refused with + `400 unauthorized_client`, because the validator call is not built yet. Nothing is read + from the store yet. 3. The grant: an unknown, forged, foreign, login or expired token all get `grant_invalid`. Then revoked, parent revoked, and `not_issuable` when the grant does not list the ID-JAG output. @@ -2190,7 +2196,8 @@ broker's `subject_token_audiences` is missing there, a target that requires | `https://toolhive.dev/upstream_subject` | object | Only if the target requires it: `{"iss", "claim", "value"}`. The config calls it `upstream_subject` | There is no `nbf`, `scope`, `cnf`, `authorization_details` or `act` claim. The -client in `client_id` acts for the user. +client in `client_id` acts for the user. A client with an actor profile gets no +ID-JAG yet (see [Required actor parameters](#required-actor-parameters)). `sub` is the same for every audience. AS-1 draws it as a random UUID at the user's first login. With memory storage a restart gives every user a new `sub`, @@ -2255,14 +2262,15 @@ An ID-JAG can name the acting agent in its `act` claim (ID-JAG draft -06, Extensions"). The issuing server cannot see the client's agent registry, so it cannot check an actor token or find the agent it names. An embedder that holds such a registry registers an in-process **validator**. For a client with an -actor profile, ID-JAG issuance from an exchange grant will then require an -`actor_token` (RFC 8693 §2.1), pass it to the validator, and build `act` from -the answer. +actor profile, ID-JAG issuance from an exchange grant requires an +`actor_token` (RFC 8693 §2.1), and will pass it to the validator and build `act` +from the answer. -**Status.** Only the configuration and the startup checks exist. Nothing calls -the validator yet. Until the call is added, ID-JAG issuance refuses every -request from a client that has an actor profile (see -[Fail-closed guard](#fail-closed-guard)). +**Status.** The configuration, the startup checks and the request check exist. +Calling the validator and setting `act` are not built yet, so a client with an +actor profile gets no ID-JAG: a request that passes every request check is +refused with `400 unauthorized_client` (see [Required actor +parameters](#required-actor-parameters)). The validator contract (the request, the result, the refusal reasons and the rules ToolHive applies when it calls the validator) is in the Go doc comments of @@ -2370,26 +2378,37 @@ server builds its per-client policies, it binds each profile to its registered validator. It does not check the registration again, because `Config.Validate` has already done so. -#### Fail-closed guard - -`checkIDJAGRequest` returns `400 unauthorized_client` ("Actor-token validation -is not available.") for a client that has an actor profile, before it reads any -request parameter. A client the operator configured to require an actor check therefore gets no -ID-JAG until the check is wired in. The change that adds the validator call to issuance -replaces this guard. - **Open.** ToolHive does not check that a SPIFFE agent ID belongs to the trust domain named by a `spiffe://` `ActIssuer`. A validator that accepts JWT-SVIDs must verify each SVID against the bundle of the trust domain in its `sub`. That check is the binding, and it belongs in the embedder's validator. +#### Required actor parameters + +A client with an actor profile must send exactly one non-empty `actor_token` and +exactly one `actor_token_type` that equals the profile's token type. The type is +compared exactly, with no case folding. Otherwise the request fails with +`invalid_request` and one of these hints: + +- `The 'actor_token' parameter is required, once, for this client.` +- `The 'actor_token_type' parameter must name the token type configured for this client, once.` + +`checkIDJAGRequest` makes this check before it looks up the target and before +any grant is read. + +The actor token is not validated yet. A request that passes this check and the +target check is refused with `400 unauthorized_client` and the hint `Actor-token +validation is not available.`, so a client the operator configured to require an actor +check gets no ID-JAG until the validator call is built. That call replaces this +refusal. + ## Implementation - `pkg/authserver/server/tokenexchange/actor_validator.go` — `ActorTokenValidator` and its contract, `ActorValidatorRegistration`, `ActIssuerProblem`, `ActorProfile` - `pkg/authserver/server/tokenexchange/handler.go` — `checkSourcePolicy`, `ConfiguredClientPolicy`, `checkDelegationConsent`, `grantScopes`, `grantAndBoundAudiences`, `externalOrigin`, `IDJAGTarget`, `ConfiguredClientPolicy.IDJAGTargets`, `ConfiguredClientPolicy.ActorProfile` - `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/id_jag_mint.go` — the ID-JAG minting core: `checkIDJAGRequest` (including the fail-closed guard for a client with an actor profile), `selectSubjectClaims`, `respondWithIDJAG`, `mintIDJAG` +- `pkg/authserver/server/tokenexchange/id_jag_mint.go` — the ID-JAG minting core: `checkIDJAGRequest` (including the required actor parameters for a client with an actor profile), `selectSubjectClaims`, `respondWithIDJAG`, `mintIDJAG` - `pkg/authserver/server/tokenexchange/refresh_token_id_jag.go` — `decideIDJAG`, `issueIDJAG`: the grant checks and the Debug line for an ID-JAG - `pkg/authserver/server/id_jag_seam.go` — `OwnsResourceParameter`, `ReasonDPoPNotSupported`; the token endpoint calls them from `pkg/authserver/server/handlers/token.go` - `pkg/authserver/server/tokenexchange/multi_issuer_validator.go` — `MultiIssuerTokenValidator`, `TrustedIssuer`, `resolveActorAuthorization`, `ValidateJWKSURL` diff --git a/pkg/authserver/server/tokenexchange/id_jag_mint.go b/pkg/authserver/server/tokenexchange/id_jag_mint.go index 7cf698e458..7cfda5e7bd 100644 --- a/pkg/authserver/server/tokenexchange/id_jag_mint.go +++ b/pkg/authserver/server/tokenexchange/id_jag_mint.go @@ -75,11 +75,21 @@ var idJAGReservedClaims = map[string]struct{}{ // a request. The client gets invalid_request with reasonPolicyDenied. var errIDJAGPolicyDenied = errors.New("ID-JAG request denied by policy") +// errActorValidationUnavailable marks the refusal of a client with an actor +// profile until issuance calls the validator, so the caller can log it with its +// own reason and not as a malformed request. +var errActorValidationUnavailable = errors.New("actor-token validation is not available") + // idJAGRequestShape is the target and resource of a request that passed -// checkIDJAGRequest. +// checkIDJAGRequest, and, for a client with an actor profile, the presented +// actor token. checkIDJAGRequest checks only that the token is present once; +// it does not validate it. The token type is not carried: checkActorParameters +// forces it to equal the profile's. The actor token is empty for a client +// without a profile. type idJAGRequestShape struct { - Target IDJAGTarget - Resource string + Target IDJAGTarget + Resource string + ActorToken string } // idJAGSubject is the user an ID-JAG is minted for: the sub claim and the @@ -167,21 +177,16 @@ func allowAllIDJAGPolicy(context.Context, idJAGPolicyInput) error { return nil } // and a resource the target does not list all get the same invalid_target // error. Unknown parameters are ignored. // -// A client with an actor profile is refused with unauthorized_client before -// any parameter is read, because ID-JAG issuance does not check actor tokens -// yet and must not mint for a client the operator configured to require that -// check. Checking first means no request shape, valid or not, gets past it. +// A client with an actor profile must send actor_token and actor_token_type +// instead of having them refused; see checkIDJAGExtraParameters. The target +// check comes after them. Such a client is then refused with +// unauthorized_client, because issuance does not call the actor validator yet and must not mint for +// a client the operator configured to require that check. A malformed request +// from it still gets invalid_request or invalid_target first. // // Every refusal here carries a hint, never a stable reason, so it returns only // the error to send. func checkIDJAGRequest(form url.Values, policy ConfiguredClientPolicy) (idJAGRequestShape, error) { - // The change that adds the validateActor call replaces this guard. It - // answers unauthorized_client (400), not server_error, so these refusals - // are not logged as server faults. - if policy.ActorProfile != nil { - return idJAGRequestShape{}, errorsx.WithStack(fosite.ErrUnauthorizedClient.WithHint( - "Actor-token validation is not available.")) - } if form.Get("subject_token") == "" { return idJAGRequestShape{}, errorsx.WithStack(fosite.ErrInvalidRequest.WithHint( "The 'subject_token' parameter is required for token exchange.")) @@ -200,7 +205,8 @@ func checkIDJAGRequest(form url.Values, policy ConfiguredClientPolicy) (idJAGReq return idJAGRequestShape{}, errorsx.WithStack(server.ErrInvalidTarget.WithHint( "The 'resource' parameter must have exactly one value when requesting an ID-JAG.")) } - if err := refuseIDJAGParameters(form); err != nil { + actorToken, err := checkIDJAGExtraParameters(form, policy.ActorProfile) + if err != nil { return idJAGRequestShape{}, err } target, ok := policy.IDJAGTargets[audiences[0]] @@ -208,31 +214,65 @@ func checkIDJAGRequest(form url.Values, policy ConfiguredClientPolicy) (idJAGReq return idJAGRequestShape{}, errorsx.WithStack(server.ErrInvalidTarget.WithHint( "The 'audience' and 'resource' parameters do not name a target this client may request an ID-JAG for.")) } - return idJAGRequestShape{Target: target, Resource: resources[0]}, nil + // The change that adds the validateActor call replaces this guard. It + // answers unauthorized_client (400), not server_error, so these refusals + // are not logged as server faults. + if policy.ActorProfile != nil { + return idJAGRequestShape{}, errorsx.WithStack(fosite.ErrUnauthorizedClient.WithHint( + "Actor-token validation is not available.").WithWrap(errActorValidationUnavailable)) + } + return idJAGRequestShape{Target: target, Resource: resources[0], ActorToken: actorToken}, nil } -// refuseIDJAGParameters refuses the parameters an ID-JAG request may not carry -// yet, checking every value of each. -func refuseIDJAGParameters(form url.Values) error { +// checkIDJAGExtraParameters checks the parameters beyond subject_token, audience +// and resource, checking every value of each. scope and authorization_details +// are refused for every client. +// +// Without a profile, actor_token and actor_token_type are refused too, and the +// returned actor token is empty. With a profile they are required instead, by +// checkActorParameters, and the actor token is returned. +func checkIDJAGExtraParameters(form url.Values, profile *ActorProfile) (string, error) { if len(nonEmptyValues(form["scope"])) > 0 { - return errorsx.WithStack(fosite.ErrInvalidScope.WithHint( + return "", errorsx.WithStack(fosite.ErrInvalidScope.WithHint( "The 'scope' parameter is not supported when requesting an ID-JAG.")) } if len(nonEmptyValues(form["authorization_details"])) > 0 { - return errorsx.WithStack(invalidAuthorizationDetailsError().WithHint( + return "", errorsx.WithStack(invalidAuthorizationDetailsError().WithHint( "The 'authorization_details' parameter is not supported when requesting an ID-JAG.")) } + if profile != nil { + return checkActorParameters(form, profile) + } if len(nonEmptyValues(form["actor_token"])) > 0 { - return errorsx.WithStack(fosite.ErrInvalidRequest.WithHint( + return "", errorsx.WithStack(fosite.ErrInvalidRequest.WithHint( "The 'actor_token' parameter is not supported when requesting an ID-JAG.")) } // actor_token has no non-empty value here, so any actor_token_type is alone // (RFC 8693 section 2.1). if len(nonEmptyValues(form["actor_token_type"])) > 0 { - return errorsx.WithStack(fosite.ErrInvalidRequest.WithHint( + return "", errorsx.WithStack(fosite.ErrInvalidRequest.WithHint( "The 'actor_token_type' parameter must not be given without 'actor_token'.")) } - return nil + return "", nil +} + +// checkActorParameters requires the actor token and its type for a client with +// a profile. "Exactly one" counts every value, empty ones included: the +// parameter must appear once, and that value must be non-empty. A repeated +// parameter is refused even when only one of its values is non-empty, since +// fosite reads only the first. actor_token_type must also equal the profile's +// type exactly. Nothing from the request is echoed. +func checkActorParameters(form url.Values, profile *ActorProfile) (string, error) { + tokens := form["actor_token"] + if len(tokens) != 1 || tokens[0] == "" { + return "", errorsx.WithStack(fosite.ErrInvalidRequest.WithHint( + "The 'actor_token' parameter is required, once, for this client.")) + } + if types := form["actor_token_type"]; len(types) != 1 || types[0] != profile.ActorTokenType { + return "", errorsx.WithStack(fosite.ErrInvalidRequest.WithHint( + "The 'actor_token_type' parameter must name the token type configured for this client, once.")) + } + return tokens[0], nil } // selectSubjectClaims picks the subject claims the target requires from the diff --git a/pkg/authserver/server/tokenexchange/id_jag_mint_test.go b/pkg/authserver/server/tokenexchange/id_jag_mint_test.go index 49c4319aae..40bfac6e52 100644 --- a/pkg/authserver/server/tokenexchange/id_jag_mint_test.go +++ b/pkg/authserver/server/tokenexchange/id_jag_mint_test.go @@ -288,29 +288,13 @@ func TestCheckIDJAGRequest(t *testing.T) { } wantShape := idJAGRequestShape{Target: target, Resource: mintTestResource} - profiled := policy - profiled.ActorProfile = &ActorProfile{Name: "broker", ActorTokenType: oauthproto.TokenTypeJWT} - tests := []struct { name string mutate func(url.Values) - profiled bool // the client has an actor profile wantCode string // empty for success wantParam string // a substring of the hint naming the parameter }{ {name: "valid request", mutate: func(url.Values) {}}, - {name: "valid request from a client with an actor profile fails closed", - mutate: func(url.Values) {}, profiled: true, - wantCode: "unauthorized_client", wantParam: "Actor-token validation is not available"}, - {name: "actor profile is refused even when an actor token is sent", - mutate: func(f url.Values) { - f.Set("actor_token", "agent-token") - f.Set("actor_token_type", oauthproto.TokenTypeJWT) - }, profiled: true, - wantCode: "unauthorized_client", wantParam: "Actor-token validation is not available"}, - {name: "actor profile is refused before the request is read", - mutate: func(f url.Values) { f.Del("subject_token") }, profiled: true, - wantCode: "unauthorized_client", wantParam: "Actor-token validation is not available"}, {name: "empty first audience is a single audience", mutate: func(f url.Values) { f[mintTestAudienceParam] = []string{"", mintTestTargetIssuer} }}, {name: "empty first resource is a single resource", @@ -439,11 +423,7 @@ func TestCheckIDJAGRequest(t *testing.T) { form := validForm() tt.mutate(form) - p := policy - if tt.profiled { - p = profiled - } - shape, err := checkIDJAGRequest(form, p) + shape, err := checkIDJAGRequest(form, policy) if tt.wantCode == "" { require.NoError(t, err) assert.Equal(t, wantShape, shape) @@ -456,6 +436,110 @@ func TestCheckIDJAGRequest(t *testing.T) { } } +// TestCheckIDJAGRequestActorProfile pins the actor-token checks for a client +// with an actor profile. "Exactly one" counts every value, empty ones +// included: the parameter appears once and that value is non-empty. A request +// that passes every check is refused with unauthorized_client, because issuance does +// not call the actor validator yet. +func TestCheckIDJAGRequestActorProfile(t *testing.T) { + t.Parallel() + + target := mintTestTarget() + policy := ConfiguredClientPolicy{ + IDJAGTargets: map[string]IDJAGTarget{target.Issuer: target}, + ActorProfile: &ActorProfile{Name: "broker", ActorTokenType: oauthproto.TokenTypeJWT}, + } + validForm := func() url.Values { + return url.Values{ + "subject_token": {"subject"}, + mintTestAudienceParam: {mintTestTargetIssuer}, + "resource": {mintTestResource}, + "actor_token": {"actor"}, + "actor_token_type": {oauthproto.TokenTypeJWT}, + } + } + const ( + tokenHint = "The 'actor_token' parameter is required, once, for this client." + typeHint = "The 'actor_token_type' parameter must name the token type configured for this client, once." + targetHint = "The 'audience' and 'resource' parameters do not name a target this client may request an ID-JAG for." + guardHint = "Actor-token validation is not available." + ) + + tests := []struct { + name string + mutate func(url.Values) + wantCode string + wantHint string + }{ + {name: "a valid request fails closed", mutate: func(url.Values) {}, + wantCode: "unauthorized_client", wantHint: guardHint}, + {name: "actor_token missing", mutate: func(f url.Values) { f.Del("actor_token") }, + wantCode: "invalid_request", wantHint: tokenHint}, + {name: "actor_token empty", mutate: func(f url.Values) { f.Set("actor_token", "") }, + wantCode: "invalid_request", wantHint: tokenHint}, + {name: "two actor_tokens", mutate: func(f url.Values) { f["actor_token"] = []string{"a", "b"} }, + wantCode: "invalid_request", wantHint: tokenHint}, + {name: "two identical actor_tokens", mutate: func(f url.Values) { f["actor_token"] = []string{"a", "a"} }, + wantCode: "invalid_request", wantHint: tokenHint}, + {name: "empty first and then a token", mutate: func(f url.Values) { f["actor_token"] = []string{"", "a"} }, + wantCode: "invalid_request", wantHint: tokenHint}, + {name: "a token and then empty", mutate: func(f url.Values) { f["actor_token"] = []string{"a", ""} }, + wantCode: "invalid_request", wantHint: tokenHint}, + {name: "actor_token_type missing", mutate: func(f url.Values) { f.Del("actor_token_type") }, + wantCode: "invalid_request", wantHint: typeHint}, + {name: "actor_token_type empty", mutate: func(f url.Values) { f.Set("actor_token_type", "") }, + wantCode: "invalid_request", wantHint: typeHint}, + {name: "actor_token_type wrong", + mutate: func(f url.Values) { f.Set("actor_token_type", oauthproto.TokenTypeAccessToken) }, + wantCode: "invalid_request", wantHint: typeHint}, + {name: "actor_token_type differs only in case", + mutate: func(f url.Values) { f.Set("actor_token_type", strings.ToUpper(oauthproto.TokenTypeJWT)) }, + wantCode: "invalid_request", wantHint: typeHint}, + {name: "two actor_token_types, both valid", + mutate: func(f url.Values) { + f["actor_token_type"] = []string{oauthproto.TokenTypeJWT, oauthproto.TokenTypeJWT} + }, + wantCode: "invalid_request", wantHint: typeHint}, + {name: "empty first actor_token_type", + mutate: func(f url.Values) { f["actor_token_type"] = []string{"", oauthproto.TokenTypeJWT} }, + wantCode: "invalid_request", wantHint: typeHint}, + {name: "both missing reports the token first", + mutate: func(f url.Values) { f.Del("actor_token"); f.Del("actor_token_type") }, + wantCode: "invalid_request", wantHint: tokenHint}, + {name: "missing subject_token is reported before the actor token", + mutate: func(f url.Values) { f.Del("subject_token"); f.Del("actor_token") }, + wantCode: "invalid_request", wantHint: "The 'subject_token' parameter is required for token exchange."}, + {name: "scope is reported before the actor token", + mutate: func(f url.Values) { f.Set("scope", "read"); f.Del("actor_token") }, + wantCode: "invalid_scope", wantHint: "The 'scope' parameter is not supported when requesting an ID-JAG."}, + {name: "authorization_details is reported before the actor token", + mutate: func(f url.Values) { f.Set("authorization_details", "[]"); f.Del("actor_token") }, + wantCode: "invalid_authorization_details", + wantHint: "The 'authorization_details' parameter is not supported when requesting an ID-JAG."}, + {name: "unknown target is reported before the guard", + mutate: func(f url.Values) { f.Set(mintTestAudienceParam, "https://unknown.example.com") }, + wantCode: "invalid_target", wantHint: targetHint}, + {name: "a bad actor token is reported before a bad target", + mutate: func(f url.Values) { + f.Set(mintTestAudienceParam, "https://unknown.example.com") + f.Del("actor_token") + }, + wantCode: "invalid_request", wantHint: tokenHint}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + form := validForm() + tt.mutate(form) + + shape, err := checkIDJAGRequest(form, policy) + rfc := requireMintOAuthError(t, err, tt.wantCode) + assert.Equal(t, tt.wantHint, rfc.HintField) + assert.Equal(t, idJAGRequestShape{}, shape) + }) + } +} + // TestCheckIDJAGRequestOtherClientTarget pins that a target configured only for // another client is refused exactly like an unknown target. func TestCheckIDJAGRequestOtherClientTarget(t *testing.T) { diff --git a/pkg/authserver/server/tokenexchange/refresh_token_id_jag.go b/pkg/authserver/server/tokenexchange/refresh_token_id_jag.go index 3b3aad68b3..debe9cfbb0 100644 --- a/pkg/authserver/server/tokenexchange/refresh_token_id_jag.go +++ b/pkg/authserver/server/tokenexchange/refresh_token_id_jag.go @@ -50,7 +50,7 @@ func (h *RefreshTokenHandler) decideIDJAG( shape, err := checkIDJAGRequest(form, policy) if err != nil { reason := refuseRequestParam - if policy.ActorProfile != nil { + if errors.Is(err, errActorValidationUnavailable) { reason = refuseActorUnavailable } return nil, refuse(ctx, log, reason, err) diff --git a/pkg/authserver/server/tokenexchange/refresh_token_id_jag_test.go b/pkg/authserver/server/tokenexchange/refresh_token_id_jag_test.go index 174c5a4ac3..d1bf312885 100644 --- a/pkg/authserver/server/tokenexchange/refresh_token_id_jag_test.go +++ b/pkg/authserver/server/tokenexchange/refresh_token_id_jag_test.go @@ -204,6 +204,52 @@ func TestIDJAGMintsFromTheGrantSnapshot(t *testing.T) { } } +// TestIDJAGRequiresActorTokenForActorProfileClients shows the mint path holds a +// client with an actor profile to the actor parameters, and refuses it with +// server_error once they pass, because issuance does not call the actor +// validator yet. Both refusals come before any grant is read. +func TestIDJAGRequiresActorTokenForActorProfileClients(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + form url.Values + wantCode string + wantHint string + }{ + {name: "without actor parameters", + wantCode: "invalid_request", wantHint: "The 'actor_token' parameter is required, once, for this client."}, + {name: "with matching actor parameters fails closed", + form: url.Values{"actor_token": {"agent-token"}, "actor_token_type": {oauthproto.TokenTypeJWT}}, + wantCode: "unauthorized_client", wantHint: "Actor-token validation is not available."}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + records := idJAGRecords(idJAGRecord("ok", testRefreshClient, "", time.Now().Add(time.Hour), oauthproto.TokenTypeIDJAG)) + store := &fakeGrantStoreWithRecords{recordStore: recordStore{grants: records}} + h := idJAGHandler(t, store) + policy := h.clientPolicies[testRefreshClient] + policy.ActorProfile = &ActorProfile{Name: "agents", ActorTokenType: oauthproto.TokenTypeJWT} + h.clientPolicies[testRefreshClient] = policy + + req := idJAGRequest("x.ok") + for k, v := range tt.form { + req.Form[k] = v + } + handleErr := h.HandleTokenEndpointRequest(t.Context(), req) + requireOAuthError(t, handleErr, tt.wantCode, "") + assert.Equal(t, tt.wantHint, unwrapOAuth(t, handleErr).HintField) + + resp := fosite.NewAccessResponse() + require.Error(t, h.PopulateTokenEndpointResponse(t.Context(), req, resp)) + assert.Empty(t, resp.GetAccessToken()) + assert.Zero(t, store.reads, "the request check comes before any grant is read") + assert.Empty(t, store.created) + }) + } +} + // TestIDJAGInternalFailuresAreGeneric covers internal failures on the ID-JAG // path that the derive tests do not: each is a server_error whose description // carries no cause. @@ -483,6 +529,12 @@ func TestIDJAGLogs(t *testing.T) { h.signer = tt.signer } req := idJAGRequest(token) + if tt.profiled { + // A well-formed request, so it reaches the refusal that stands in + // for the validator call. + req.Form.Set("actor_token", "agent-token") + req.Form.Set("actor_token_type", oauthproto.TokenTypeJWT) + } req.Client = &fosite.DefaultClient{ID: tt.clientID, GrantTypes: fosite.Arguments{oauthproto.GrantTypeTokenExchange}} resp := fosite.NewAccessResponse() From ed0fcf18e9eb833671e13b3582e0f0f78360f518 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 13 Nov 2026 15:42:45 +0100 Subject: [PATCH 2/2] Drop "once it issues ID-JAGs" from middleware docs The embedded auth server now mints ID-JAGs from exchange grants, so the typ check on oauth-id-jag+jwt covers its tokens today, not in future. Co-authored-by: Mecatl --- docs/middleware.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/middleware.md b/docs/middleware.md index 9e3c2a534a..8355f55893 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -167,7 +167,7 @@ sequenceDiagram **Responsibilities**: - Validate JWT token signature and expiration -- Return 401 Unauthorized for a token whose JOSE `typ` header is `oauth-id-jag+jwt` (compared case-insensitively, with or without the `application/` prefix), even when its signature and claims are valid. This applies to tokens from every configured issuer, including external identity providers, and to vMCP incoming authentication. An ID-JAG is not an access token. An issuer that signs ID-JAGs with the same key as its access tokens (an external identity provider today, and the embedded auth server once it issues ID-JAGs) would otherwise have them accepted in place of access tokens (RFC 8725 Section 3.12). Configuring an expected audience is the main defence against one token type being used in place of another; this check is a backup for deployments without one. +- Return 401 Unauthorized for a token whose JOSE `typ` header is `oauth-id-jag+jwt` (compared case-insensitively, with or without the `application/` prefix), even when its signature and claims are valid. This applies to tokens from every configured issuer, including external identity providers, and to vMCP incoming authentication. An ID-JAG is not an access token. An issuer that signs ID-JAGs with the same key as its access tokens (an external identity provider, or the embedded auth server) would otherwise have them accepted in place of access tokens (RFC 8725 Section 3.12). Configuring an expected audience is the main defence against one token type being used in place of another; this check is a backup for deployments without one. - Extract JWT claims (sub, name, roles, etc.) - Add claims to request context for downstream middleware - With the embedded auth server, load the token session's upstream provider credentials (the `tsid` claim) into `Identity.UpstreamTokens` and `Identity.UpstreamIDTokens`, refreshing expired access tokens