Skip to content

Add a per-client access token lifespan for ID-JAG redemption - #7284

Merged
rdimitrov merged 3 commits into
mainfrom
as2-call-binding-2-client-lifespan
Nov 25, 2026
Merged

rdimitrov merged 3 commits into
mainfrom
as2-call-binding-2-client-lifespan

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

A client that redeems ID-JAGs to make one MCP call wants a token that lives for seconds, while every other client keeps the server's access-token lifespan. Today there is one lifespan for the whole server, so a narrow per-call token lives as long as any other token. "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (#7061) asks for a per-client lifetime. This PR adds it; it is opt-in and changes nothing for a server that does not set it.

  • Delegate clients in the RunConfig get an optional access_token_lifespan, a Go duration string. Omitted means the server lifespan. A set value must be at least 2s and at most 24h, checked when the configuration is loaded: smaller (including zero and negative) and larger values fail at startup, so a zero never means unlimited and a token is never dead on arrival.
  • The lifespans reach the ID-JAG handler through a new FactoryOption, WithClientAccessTokenLifespans, now accepted by IDJAGIssuanceFactory. The map stays on the ID-JAG handler and is copied into the redemption.
  • redeemer.assertionBoundedExpiry (was assertionBoundedLifetime) computes the token's expiry once, from one clock reading: the earliest of now plus the client's lifespan (the server lifespan when the client sets none), the ID-JAG's own exp, and, for a marked token, now plus the marker cap. exp and expires_in both follow it, so a token never outlives its ID-JAG.
  • Plain JWT-bearer has no authenticated client and keeps the server lifespan. Token exchange, refresh and authorization code are unchanged.
  • A lifespan that ID-JAG redemption could never apply (no trusted issuer accepts ID-JAG assertions, or the client's grant_types omit the JWT-bearer grant) fails startup instead of being ignored.
  • Each factory now refuses, with an error, a FactoryOption it does not apply (the token-exchange factories refuse client lifespans; the ID-JAG factory refuses an authorization-details registry), so an option is never silently ignored.
  • RunConfig only, no CRD field, so no migration.

Part of #7061

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Also ran: go test -race ./pkg/authserver/..., golangci-lint run ./pkg/authserver/..., task docs, task docs-verify, task sdk-test, task sdk-lint.

New tests:

  • Config: 0, negative, 100ms and 1999ms refused, 2s and exactly 24h accepted, 24h + 1s refused, unset falls back to the server lifespan. Checked on the RunConfig (TestDelegateClientRunConfigValidate), on a resolved Config (TestValidateResolvedDelegateClients_AccessTokenLifespan), in resolveDelegateClients and at the ID-JAG factory; an unparsable value is refused too. A lifespan is refused when no trusted issuer accepts ID-JAG assertions (including a Config.Validate case whose only issuer accepts plain assertions) or the client's grant_types omit the grant. TestRedeemer_ExpiryIsTheAssertionExpiry pins that the expiry is the assertion's exp exactly when that is the tighter bound.
  • Redemption (TestRedeemer_ClientAccessTokenLifespan): client lifespan shorter than the assertion, longer than the assertion (silently shortened), longer than the server lifespan, a client without a value gets the server lifespan, the plain grant ignores it. Each checks both exp and expires_in.
  • Marker cap: TestRedeemer_DelegatedAccessLifetime rows with a client lifespan above and below the five-minute cap; TestIDJAGResolve_ClientLifespanUnderMarkerCap shows a resolved (marked) redemption carries the client lifespan and the cap still wins.
  • Wiring: the factory option reaches the handler and is copied; factories refuse options they do not apply and out-of-range values; a two-server integration test sets access_token_lifespan: 20s on AS-2's RunConfig and gets a token with expires_in and exp of about 20 seconds from a real AS-1 ID-JAG.

Changes

File Change
pkg/authserver/config.go DelegateClientRunConfig.AccessTokenLifespan, AccessTokenLifespanDuration, bounds check in both validators, DelegateClient.AccessTokenLifespan
pkg/authserver/runner/embeddedauthserver.go resolveDelegateClients parses the lifespan
pkg/authserver/server_impl.go delegateAccessTokenLifespans; passes the option to the ID-JAG factory
pkg/authserver/server/tokenexchange/factory.go WithClientAccessTokenLifespans; token-exchange factories refuse it
pkg/authserver/server/tokenexchange/id_jag_handler.go options ...FactoryOption on IDJAGIssuanceFactory, clientLifespans, bounds check
pkg/authserver/server/tokenexchange/id_jag_resolve.go copies the client's lifespan into the redemption
pkg/authserver/server/tokenexchange/redeemer.go redemption.clientLifespan; lifetime order in assertionBoundedLifetime
docs/arch/17-token-exchange-delegation.md client metadata row; "Lifetime of a redeemed token" section
docs/server/*, sdk/go/* regenerated

Does this introduce a user-facing change?

Yes, for operators who opt in.

  • Before: a token from ID-JAG redemption lives for the shortest of the server's access_token_lifespan, the ID-JAG's remaining time, and (for a marked token) five minutes. There is no per-client setting.
  • After: a delegate client may set access_token_lifespan (for example 30s). For that client's ID-JAG redemptions it replaces the server lifespan in that list; it can be shorter or longer than the server lifespan. The ID-JAG's remaining time and the marker cap still apply, so a longer client lifespan is shortened silently, with no error. Clients without it, plain JWT-bearer and every other grant behave as before. Startup fails for a value of 0, a negative value or one above 24h, and for a lifespan the client could never use (JWT-bearer grant not enabled, or the client's grant_types omit it).

Operator note: to get the lifespan you configure, set the AS-1 target's ID-JAG lifetime to at least that lifespan plus the expected redemption delay. A ToolHive AS-1 issues ID-JAGs for 60 seconds by default and at most 300 seconds, so a client lifespan above 300 seconds is never reached.

Special notes for reviewers

  • The release-safety rule for this work: this PR is opt-in. With no access_token_lifespan set, delegateAccessTokenLifespans returns nil and the redeemer takes the server lifespan exactly as before.
  • fosite's IssueAccessToken takes expires_in from the session expiry, not from the lifespan argument populate passes, so a client lifespan longer than the server lifespan is honored; the unit and integration tests pin this.
  • IDJAGIssuanceFactory now refuses WithAuthorizationDetailsRegistry. Nothing passes it today. The branch that adds the authorization_details claim to ID-JAG redemption replaces that refusal with real handling, so the registry cannot be wired in early and ignored.
  • A lifespan that could never apply fails startup, following the token_exchange.id_jag precedent (errIDJAGRequiresTokenExchange): no trusted issuer accepts ID-JAG assertions (idJAGRedeemable; an enabled JWT-bearer grant whose issuers accept only plain assertions is not enough), or the client sets grant_types without the JWT-bearer grant. This check runs on the resolved Config (validateDelegationConfig), because both are decided from the resolved trusted issuers; the bounds are also checked at RunConfig validation.
  • fosite takes exp and expires_in from the session expiry whenever it is set, so the server lifespan that populate passes to issueBoundedAccessToken is only the fallback for a session with no expiry. That function's comment now says so; before this change the redeemer could not reach the case where the session expiry is later than that argument.
  • WithClientAccessTokenLifespans does not refuse a key that names no configured client. The ID-JAG handler also serves DCR, CIMD and SPIFFE clients, so the factory has no client list to check against; the production map comes only from delegate_clients.
  • Only delegate clients in delegate_clients can set a lifespan; DCR, CIMD and SPIFFE-association clients that redeem ID-JAGs keep the server's.
  • exp is signed in whole seconds, rounded down, and expires_in is truncated, so it is usually one second less than a whole-second lifespan. That is why a set value must be at least 2s (server.MinClientAccessTokenLifespan): below that a token could be expired on arrival after its single-use ID-JAG was consumed.
  • The redeemer treats only a zero client lifespan as "use the server's". A negative value, which the factory already refuses, would issue an expired token rather than fall back.

Confirmed in the issue discussion

The lifespan rule is confirmed in the issue discussion on #7061, item 7: at most 24h, checked when the configuration is loaded so a bad value fails at startup. Review raised the lower bound from greater than 0 to at least 2s, for the rounding reason above. The tests cover each case.

🤖 Generated with Claude Code

A client that redeems ID-JAGs to call one MCP tool wants tokens that
live seconds, while other clients keep the server default. The issue
"Authorization server: narrow a JWT-bearer access token to one MCP
call with authorization_details" (#7061) asks for a per-client
lifetime for this.

Delegate clients get an optional access_token_lifespan, a Go duration
string like the server's own. Omitted means the server lifespan. A set
value must be greater than 0 and at most 24h, checked when the
configuration is loaded, so a bad value fails at startup and a zero
never means unlimited. Startup also fails for a lifespan ID-JAG
redemption could never apply: the JWT-bearer grant is off, or the
client's grant_types omit it.

The lifespans reach the ID-JAG handler through a new FactoryOption,
WithClientAccessTokenLifespans. On ID-JAG redemption the token lives
for the client's lifespan (or the server's), capped by the ID-JAG's
remaining time and then by the delegated-access marker cap. A longer
client lifespan is shortened silently. Plain JWT-bearer has no
authenticated client and keeps the server lifespan; other grants are
unchanged. Each factory now refuses an option it does not apply, so
an option is never silently ignored.

RunConfig only, no CRD field.

Refs #7061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.90%. Comparing base (65cc86f) to head (0fa674f).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7284      +/-   ##
==========================================
+ Coverage   81.85%   81.90%   +0.05%     
==========================================
  Files         915      919       +4     
  Lines       92853    93172     +319     
==========================================
+ Hits        76001    76315     +314     
- Misses      16847    16852       +5     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The grant check for access_token_lifespan had a direct unit test, but
no test went through Config.Validate, so dropping the call there would
have passed. Add a Validate row for a delegate client that sets a
lifespan while the JWT-bearer grant is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 24, 2026

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this reads well and the lifetime order looks right to me. I couldn't find a way for a token to outlive the ID-JAG or the marker cap because of this change, and the fosite exp/expires_in/storage TTL all following the session expiry checks out.

A few things inline. The startup check one and the sub-second lifespan one are the ones I'd like to see fixed here; the rest are small.

Two questions that aren't tied to a line:

  • A client lifespan can now be longer than the server access_token_lifespan, so the server value stops being a ceiling for ID-JAG tokens. I think that's intended given the PR body, just want to confirm that's what we want for #7061.
  • The longer-than-server case only works because fosite takes exp and expires_in from the session expiry rather than the lifespan argument. The tests pin it, which is probably fine, but a fosite bump that changes this would quietly cap those tokens at the server lifespan. Worth a sentence in the issueBoundedAccessToken comment pointing at the test that guards it?

Comment thread pkg/authserver/config.go Resolved
Comment thread pkg/authserver/config.go Resolved
Refuse a per-client lifespan unless a trusted issuer accepts ID-JAG
assertions. An enabled JWT-bearer grant whose issuers accept only plain
assertions can never apply the lifespan, so startup now fails for it.

Require a client lifespan of at least 2s. exp is signed in whole
seconds, rounded down, so a sub-second lifespan could issue a token
that is already expired after its single-use ID-JAG was consumed.

Compute the token expiry once, from one clock reading, as the earliest
of now plus the lifespan, the assertion's exp, and now plus the marker
cap. Before, the remaining time was re-added to a later clock reading,
so the token could outlive the ID-JAG by that gap.

Also fix the expires_in rounding note in the docs, note the fosite
behaviour the longer-than-server case relies on, and tidy test names
and comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 24, 2026
@rdimitrov

Copy link
Copy Markdown
Member Author

Thanks. On the two questions not tied to a line:

  • Client lifespan above the server lifespan: yes, intended. Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061 lists "the per-client lifetime (or the server's access-token lifespan when none is set)" as the first bound, so the client value replaces the server one rather than sitting under it. It is still capped by the ID-JAG's remaining time, the marker cap, and the new 2s–24h bounds.

  • fosite dependency: added a sentence to the issueBoundedAccessToken comment saying this is fosite behaviour and that the "client lifespan longer than the server lifespan" case in TestRedeemer_ClientAccessTokenLifespan guards it (0fa674f). The other nine items are fixed in the same commit, including the exact-deadline one.

🤖 Addressed by Claude Code

@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 24, 2026
@rdimitrov
rdimitrov merged commit 4505dbb into main Nov 25, 2026
66 checks passed
@rdimitrov
rdimitrov deleted the as2-call-binding-2-client-lifespan branch November 25, 2026 08:38
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants