Repository navigation
Refuse delegated-access tokens in exchanges - #7180
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7180 +/- ##
==========================================
- Coverage 81.57% 81.55% -0.03%
==========================================
Files 895 895
Lines 91356 91415 +59
==========================================
+ Hits 74526 74549 +23
- Misses 16825 16861 +36
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rdimitrov
left a comment
There was a problem hiding this comment.
Approve: the refusals are in the right places, cover every path that validates a token this server issued, and change nothing visible until something starts minting the marker.
Design: The authorization server owns the rule that a delegated-access token is terminal, so enforcing it at the token endpoint (subject token, actor token, exchange-grant opening, and the ID-JAG actor token) is the right layer. The ID-JAG actor check only uses "signed by this server" to refuse, never to accept, which keeps it safe. JWT-bearer and ID-JAG assertions only accept trusted external issuers, so a self-issued marked token cannot arrive there. On upgrade nothing changes, since no token carries the claim yet; only two new error reasons appear.
Optional, not blocking:
- The marker is stripped from
Identity.Claims(pkg/auth/context.go:244), so Cedar policies and audit cannot see it. That matchestsid, but a future gateway check must read the rawjwt.MapClaims, asisSessionlessGrantdoes. A one-line comment inclaimsToIdentitywould save someone a debugging session. RefreshTokenHandlerkeeps bothselfValidatorandselfIssuedfor the same object. A handler built withoutselfIssuedwould nil-panic insignedByThisServer. Only test struct literals can do that today.
🤖 Reviewed with Claude Code
Delegated access to a user's stored upstream credentials needs a way to tell a token from an approved delegated redemption apart from every other token. Add the claim https://toolhive.dev/claims/delegated_access as a presence-only marker, kept out of Identity.Claims like tsid. Make a marked token terminal before anything issues one, so it can never become a longer-lived token or one naming another party. It is refused as subject and actor token in RFC 8693 exchange, as actor token at ID-JAG issuance before the actor validator runs, and as the first case when opening an exchange grant, with the client-visible reason subject_token_delegated_access. This follows "Add a delegated-access marker that gates credential lookup for approved delegated tokens" (#6404). Nothing issues the marker yet. Closes #6404 Co-authored-by: Mecatl <[email protected]>
64129c8 to
ca301f2
Compare
|
Thanks for the review. I took both suggestions and amended them into the commit, so the head is now ca301f2.
Lint and the tests for the touched packages pass on the new head. Since it changed after your approval, could you take another look when you get a chance? |
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of ca301f2: still approve.
The push replaces the duplicate selfIssued field on RefreshTokenHandler with one narrow unexported interface (selfIssuedValidator, which adds the refuse-only signedByThisServer), simplifies the test setup, and adds a comment in pkg/auth/context.go saying a check that needs the delegated-access marker must read the raw validated claims, since Identity.Claims strips it. Refusal behaviour is unchanged, and both actor-token paths (the RFC 8693 handler and ID-JAG) are still covered. The factory always sets a non-nil validator, so there is no nil path.
CI: the only failure is E2E Tests Core, one spec failing with listen tcp 127.0.0.1:50328: bind: address already in use (a port collision between parallel E2E workloads, in code this PR doesn't touch). A re-run should clear it.
🤖 Reviewed with Claude Code
Summary
A gateway that holds a user's stored upstream credentials needs a way to tell a token from an approved delegated redemption apart from every other token. This adds that marker, and makes a marked token terminal before anything issues one, so that it can never become a longer-lived token or a token that names another party.
https://toolhive.dev/claims/delegated_accessas a presence-only marker. Consumers check only that it is there, never its value. It is kept out ofIdentity.Claims, and out of the serializedIdentity, liketsid.subject_tokenand asactor_tokenin RFC 8693 exchange, as the subject token when opening an exchange grant (reasonsubject_token_delegated_access), and as the actor token at ID-JAG issuance, before the client's actor validator runs (reasonactor_token_delegated_access). All useinvalid_request, as RFC 8693 section 2.2.2 requires for a token that policy makes unacceptable.no_upstream_session.Closes #6404 ("Add a delegated-access marker that gates credential lookup for approved delegated tokens")
Type of change
Test plan
task test)task test-e2e)task lint-fix)Unit tests ran on the packages this PR touches (
pkg/auth,pkg/authserver,pkg/authserver/claimnames,pkg/authserver/server/tokenexchange), with the race detector. The end-to-end flow test inpkg/authserversigns a marked login token with the server's own key and checks that grant opening refuses it, since nothing can mint one over HTTP yet.Changes
pkg/authserver/claimnames/claimnames.gopkg/authserver/server/tokenexchange/handler.gopkg/authserver/server/tokenexchange/refresh_token_handler.gosubject_token_delegated_accesspkg/authserver/server/tokenexchange/refresh_token_id_jag.go,validator.gopkg/auth/context.go,pkg/auth/identity.goIdentity.Claimsand of the serialized identitydocs/arch/17-token-exchange-delegation.md*_test.goDoes this introduce a user-facing change?
Nothing changes yet, because nothing issues the marker. Once something does:
400 invalid_requestfor such a token. At grant opening the reason issubject_token_delegated_access. At ID-JAG issuance it isactor_token_delegated_access. In RFC 8693 exchange it is a hint, "The subject token is a delegated-access token and cannot be exchanged." (or "The actor token ..."). A client should not retry with a refreshed delegated token; it needs a user's login access token.docs/arch/17-token-exchange-delegation.mddescribes the behavior and the error tables.Special notes for reviewers
subject_tokenpath accepts trusted external issuers, so only there is an external token with the claim refused as a delegated-access token. The other paths validate against this server's own keys, so an external token fails there as an invalid token.RefreshTokenHandlerkeeps a singleselfValidator, typed as a small interface that adds this signature-and-issuer check to the usualValidate.