Skip to content

Define exchange grant authorization details type - #6990

Merged
jhrozek merged 1 commit into
mainfrom
exchange-authdetails
Oct 30, 2026
Merged

jhrozek merged 1 commit into
mainfrom
exchange-authdetails

Conversation

@jhrozek

@jhrozek jhrozek commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Why: an operator-run confidential client, such as an agent broker, must keep acting for a user after that user's login has ended, for example in scheduled background work. Its access token is short-lived and tied to the login, so it cannot do this alone. The planned mechanism exchanges the user's access token, through RFC 8693, for a client-bound refresh token. The exchange request has to say what the grant may produce and for how long.

What:

  • Adds the RFC 9396 authorization_details type https://toolhive.dev/exchange_grant and a private registry that holds only this type.
  • Adds the rules for a request of this type: strict decoding, exactly one entry, the operator's per-token-type lifetime cap, and expires_at filled in or capped (RFC 9396 §7.1). A child grant derived from an existing grant cannot be a refresh token and cannot outlive its parent.
  • The repeated-parameter error now comes from one constructor shared with the existing handler.

Nothing calls these rules yet. The handler that uses them arrives in a later change.

Refs #6897

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other: groundwork for exchange refresh tokens, no behavior change

Test plan

  • Unit tests (task test): not run. I ran go test -race ./pkg/authserver/server/tokenexchange/ on the package, plus go vet and gofmt, all clean.
  • E2E tests (task test-e2e)
  • Linting (task lint-fix): not run; left to CI.
  • Manual testing

Does this introduce a user-facing change?

No. Nothing calls this code yet, so requests behave as they do today.

Special notes for reviewers

  • Stacked PR. The base is exchange-client-config-restack (Add exchange refresh token client config #6989). Merge order: Limit delegate token exchange to source clients #6988, then Add exchange refresh token client config #6989, then this PR. The diff shows only this commit.
  • Deliberate gaps, to close in the handler PR or as follow-ups:
    • No audience or resource binding on the grant. RFC 9700 §4.14.2 asks for refresh tokens to be bound to the consented scope and resource servers. This is deferred with locations, and it is a known deviation from that MUST.
    • No inactivity expiry (RFC 9700 §4.14.2 SHOULD). Only the hard cap applies.
    • The grant is not bounded by the subject access token's exp. This is deliberate for offline use (RFC 8693 §2.2.1). The subject's expiry only sets how long its replay marker is kept.
    • No consent check yet. The handler will require offline_access in the subject token.
  • Missing parameter. An absent or empty authorization_details returns invalid_request (RFC 6749 §5.2), not invalid_authorization_details.
  • Open point. The Mecatl consumer design sends its own authorization_details type on session open. The single-type registry refuses that. This needs a decision before the handler lands.
  • Cap under one second is refused in the validator as a backstop. Config validation should catch it first.
  • The type URI in the code is https://toolhive.dev/exchange_grant. Some design docs still show older URIs.

@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.16514% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.32%. Comparing base (3224ee1) to head (e5fb419).

Files with missing lines Patch % Lines
.../authserver/server/tokenexchange/exchange_grant.go 98.07% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6990    +/-   ##
========================================
  Coverage   80.32%   80.32%            
========================================
  Files         848      849     +1     
  Lines       86492    86597   +105     
========================================
+ Hits        69472    69557    +85     
- Misses      17015    17035    +20     
  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.

@jhrozek
jhrozek marked this pull request as ready for review October 29, 2026 11:03
ChrisJBurns
ChrisJBurns previously approved these changes Oct 29, 2026
@jhrozek
jhrozek force-pushed the exchange-client-config-restack branch from de1d0da to cc7f5fb Compare October 29, 2026 20:53
@jhrozek
jhrozek force-pushed the exchange-authdetails branch from bb2b6ef to 0de8cc1 Compare October 29, 2026 20:53
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Oct 29, 2026
Base automatically changed from exchange-client-config-restack to main October 29, 2026 22:35
@jhrozek
jhrozek dismissed ChrisJBurns’s stale review October 29, 2026 22:35

The base branch was changed.

@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Oct 29, 2026
A confidential client run by an operator, such as an agent broker,
must keep acting for a user after that user's login has ended, for
example in scheduled background work. Its access token is short-lived
and tied to the login, so it cannot do this alone. The planned
mechanism exchanges the user's access token, through RFC 8693, for a
client-bound refresh token. The exchange request has to say what the
grant may produce and for how long, so this defines that request as an
RFC 9396 authorization_details type and the rules applied to it.

The type, https://toolhive.dev/exchange_grant, has three members:
type, issuable_token_types (one ID-JAG or refresh-token URN), and an
optional integer expires_at. Unknown members are refused, and a request
carries exactly one such entry. The lifetime comes from the operator's
policy per client and token type, not from the user's access-token
expiry, because the grant must outlive that token (RFC 8693 section
2.2.1). A missing expires_at takes the cap, and a larger one is cut
down to it (RFC 9396 section 7.1). A child grant cannot be a refresh
token and cannot outlive its parent.

The repeated-parameter error now comes from one constructor shared with
the existing handler, with no change in behaviour. Nothing calls these
rules yet; the handler arrives in a later change.

Known limits: the grant is not yet bound to an audience or resource
(RFC 9700 section 4.14.2, deferred). There is no inactivity expiry,
so only the hard cap applies. Consent is not checked yet; the handler
will require offline_access.

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek force-pushed the exchange-authdetails branch from 332b53c to e5fb419 Compare October 30, 2026 06:25
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Oct 30, 2026
@jhrozek
jhrozek merged commit a10b2ce into main Oct 30, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants