Repository navigation
Bind delegated sessions to client and actor - #7315
Conversation
rdimitrov
left a comment
There was a problem hiding this comment.
Approve: the binding change is made at the right owner and fails closed.
Design: sessionbinding.FromIdentity/Validate are the single place every proxy and vMCP path (streamable, transparent, SSE, vMCP ownership middleware, create/restore/per-call checks) derives and compares the session owner, so extending the owner string there covers all entry points; the Modern stateless vMCP path ignores Mcp-Session-Id and has nothing to bind. Delegated tokens now get an arity-tagged owner (client and actor included) while interactive and unspecified bindings stay byte-identical, and a marked token the validator cannot classify gets a 401 instead of silently falling back to a user-only binding. The act/client_id edge cases and the audience requirement for bound validators trace through cleanly.
Upgrade effect to put in the release notes: sessions a delegated-route caller created before the upgrade carry the old 2-field owner, so they return 404 until the client re-initializes, and old replicas reject the new 4/6-field values during a rolling upgrade. Accepting the legacy form would defeat the fix, so this is the right trade-off. It only affects deployments that mint the delegated marker, which is off by default today.
🤖 Reviewed with Claude Code
Extend pkg/auth/sessionbinding so delegated identities bind sessions to issuer, user subject, the delegated route tag, client_id, and the outermost actor (act.iss and act.sub) when present, while keeping interactive and unspecified bindings byte-identical to the two-field form and failing closed on unknown routes or malformed actor claims. Parse preserves its exported signature and validates both standard and delegated bindings while Validate compares the full binding string in constant time. Frozen v0.69.0 tests confirm older replicas reject the extended format during rolling upgrades. Co-authored-by: Mecatl <[email protected]>
Route vMCP session binding extraction through pkg/auth/sessionbinding so delegated sessions carry client_id, actor, and route metadata on creation and restore, matching the shared ownership middleware. Harden ShouldAllowAnonymous and anonymous-session upgrade checks against synthetic tokenless delegated identities, extract security.ResolveBinding so makeSession fails fast before dialing backends on unbindable identities, and omit raw binding values from RestoreSession errors. Co-authored-by: Mecatl <[email protected]>
Add end-to-end ownership tests verifying delegated session binding across Legacy vMCP HTTP routes, direct enforceSessionBinding calls, streamable and transparent MCPServer proxies, and local/Redis session storage. Cover wrong client_id, wrong actor issuer or subject, cross-route interactive and delegated mismatches, renewed delegated tokens with different jti/exp/authorization_details, rejection log reasons without PII, and multi-NUL exact matching versus prefix rejection in storage. Co-authored-by: Mecatl <[email protected]>
Document the four- and six-field delegated session binding format, fail-closed rules, two-way rolling-upgrade behavior, and admission-route trust boundaries across the architecture docs and user-facing authorization guide. Co-authored-by: Mecatl <[email protected]>
A validator bound to the embedded authorization server admitted a token carrying the delegated-access marker on the unspecified route when it could not classify it as delegated: when the key came from the HTTP JWKS fallback or the claims from introspection, when no audience was set, or when the token also carried a token session ID. Such a token got the two-field session binding and could reuse the user's interactive MCP session, silently undoing the cross-route isolation of delegated sessions. Return 401 invalid_token for these tokens instead, before upstream credentials are loaded, and log the cause at WARN. Unmarked tokens and validators not bound to the embedded issuer behave as before. Only the ID-JAG redeemer mints the marker, under subject resolution, which is not yet enabled. Co-authored-by: Mecatl <[email protected]>
dff98ab to
d199ee7
Compare
|
@rdimitrov the force-push dismissed your approval, sorry about that. Main picked up "Enforce call-bound access tokens at the vMCP" (#7302), which edits the same paragraph of I kept main's call-binding text exactly as it is and put my paragraph on delegated session binding after it. The ownership sentence says "Legacy vMCP", as it did in my version, since the Modern path ignores session IDs. I rebased onto current main and pushed. There are no other functional changes: Could you take another look when you get a chance? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7315 +/- ##
==========================================
+ Coverage 82.11% 82.13% +0.02%
==========================================
Files 931 931
Lines 94390 94451 +61
==========================================
+ Hits 77507 77578 +71
+ Misses 16878 16868 -10
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.
Re-review of d199ee7: still approve. The push rebased the branch onto the current main, and the one commit that changed is the docs commit.
The PR's own change is byte-identical to the previously approved one, except for the docs/authz.md paragraph. That paragraph was merged with the newer call-binding and loopback Host guard text on main, and now says "Legacy vMCP", which matches docs/arch/10. The rebased code composes with the call-bound token middleware on main: it only reads the session ID and runs before the ownership check. The doc links and version claims resolve, and CI is green.
Design: unchanged. Delegated sessions are bound to the issuer and user, the delegated route, the OAuth client and the actor, and the check lives in the shared sessionbinding package that the proxies and vMCP all use.
🤖 Reviewed with Claude Code
Summary
An MCP session is bound to whoever created it, and today that binding is only the issuer and subject (
iss\x00sub). With delegated access, one user can have several agents and clients acting for them, each holding its own delegated access token. Under the current binding, any of those agents, another client of the same user, or the user's own interactive login can pick up a delegated session by presenting its session ID. A delegated session should belong to the client and the agent that opened it.client_id, and, when present, the immediate actor (act.iss,act.sub).jti,expandauthorization_detailsare not part of the binding, so a renewed token keeps its session. Interactive and unspecified sessions keep the two-field binding byte for byte, so existing sessions and stored records are unaffected.iss\0sub\0delegated\0client_idwithout an actor, and…\0act_iss\0act_subwith one. Every component must be non-empty and free of NUL. A token on a route the code does not recognise cannot open or use a session.client_id, a malformed or incompleteact, or an explicitact: null. It never falls back to the user-only binding.sessionbindingpackage; the storage layer already compares bindings as opaque strings.Fixes #6888
Type of change
Test plan
task test)task test-e2e)task lint-fix)The tests cover the binding format and its fuzz targets, compatibility with the v0.69.0 parser (frozen in a test), a real token validator bound and unbound, vMCP session creation, restore and per-call checks, the vMCP HTTP ownership check, the streamable and transparent proxies, and Redis and in-memory session storage with multi-NUL bindings.
Changes
pkg/auth/sessionbindingFromIdentityswitches on the admission routepkg/vmcp/sessionResolveBindingstep before backends are dialled; anonymous sessions limited to unspecified and interactive routes; no stored binding in errorspkg/auth/token.gopkg/vmcp/server,pkg/transport/**docs/arch/03,10,13,16,17,docs/authz.md,docs/middleware.mdDoes this introduce a user-facing change?
Yes, for deployments that issue delegated access tokens (ID-JAG redemption with subject resolution, a Go-only setting).
Session terminated; MCP server proxies: 404 not found), and the owner's session is untouched.client_id, or with a malformedact, got a user-only session. After: it cannot open or use a session. On the proxies this shows up through refusals that already existed: HTTP+SSE 401, transparent SSE 502, streamable and transparentinitialize404. On Legacy vMCP theinitializereply carries a session ID for a session that is already terminated, so the next request gets 404.invalid_token.sessionbinding.Parseandbinding.Parsekeep their signatures and accept the delegated forms, but return only the issuer and subject prefix. Compare full bindings withValidate, never withFormat(Parse(s)).Formaterrors now wrapErrInvalidBinding, so useerrors.Is.Implementation plan
Approved implementation plan
pkg/auth/sessionbinding: route-tagged, arity-discriminated binding. Two fields for interactive and unspecified routes, four for delegated without an actor, six with one. An unknown route fails closed. A presentactneeds a non-emptyact.issandact.sub; only the immediate actor is bound. Parse with chainedstrings.Cut. Test against a frozen copy of the v0.69.0 parser.sessionbindingthroughout. Keep the existing rejection log reasons. Leave the Modern (stateless) path alone, since it ignoresMcp-Session-Id.enforceSessionBinding, the streamable and transparent proxies, and Redis and local storage.Special notes for reviewers
Mcp-Session-Id, so there is no session binding to enforce there.act.actis informational per RFC 8693 §4.1. Without an actor, agents are isolated only if each uses its ownclient_id.pkg/auth, not session code. It is separate so it can be reviewed on its own. Nothing mints the marker in a released configuration yet, because subject resolution is still Go-only and off.tools/callterminates the owner's session throughenforceSessionBinding.Serverefuses first, so the default setup is unaffected.initializerefused after forwarding leaves the backend session to time out on its own.