Repository navigation
Isolate capability cache by identity binding - #7350
Conversation
Key capability views and in-flight discovery by the session binding and platform user ID, not the subject alone, so callers that share a subject across issuers, or across interactive and delegated bindings, cannot be served each other's view. An identity that cannot be bound (for example one with no issuer claim, which introspection responses may omit) now discovers directly on every call instead of sharing a subject-only key. The bypass logs the reason at DEBUG and still returns the context error if the request was cancelled during the sweep. Requests with no identity stay cacheable. The key still does not include the identity's own tokens, so two requests with the same binding can share a view for up to the 30 second TTL. The cache docs now say so and name the aggregators that are unsafe to wrap. The architecture docs describe the cache and the bypass. Co-authored-by: Mecatl <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7350 +/- ##
==========================================
+ Coverage 82.56% 82.57% +0.01%
==========================================
Files 941 941
Lines 96689 96701 +12
==========================================
+ Hits 79829 79852 +23
+ Misses 16855 16844 -11
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.
Approving. Checked against the session-binding design (#6888) and the delegated read in #6407: the cache now splits on the same binding that session ownership uses, so delegated and interactive callers can't share a view.
Verified locally (merged with main, -race on ./pkg/vmcp/...), plus probes against the real middleware:
- An identity from
AnonymousMiddlewarestays cacheable (5 calls, 1 sweep). A nil identity does too. - The same
subunder two issuers gets two sweeps. - An identity with no
issis swept on every call with no dedup (20 concurrent calls, 20 sweeps). Legacy session creation already fails closed for these identities, so the bypass only costs Modern requests. That's fine as the accepted trade-off.
Non-blocking, for the token-keyed follow-up: an interactive token and a sessionless token (no tsid, unspecified route) for the same user still share one key. I confirmed this with a probe. The sessionless caller loads no upstream tokens, so backends that need them can drop out of its sweep. Whichever caller sweeps first then sets the view the other one sees for up to 30s. It doesn't leak anything, but it's the concrete case that follow-up should cover. Keying on whether upstream credentials were loaded might be enough, without hashing tokens.
rdimitrov
left a comment
There was a problem hiding this comment.
LGTM. The new key closes the collisions across issuers and between interactive and delegated callers. A nil identity and an identity with an empty sub no longer share a key: the nil identity binds to the sentinel and the empty-sub identity bypasses the cache. The sentinel can't collide with a real binding, because every real binding contains a NUL. The cancellation and error handling on the bypass path match the shared path. go test -race ./pkg/vmcp/... passes locally.
I also checked the interaction with #7338: git merge-tree reports no conflict, the merged tree compiles, and the two sharedSweep changes work together. The merged tree does fail TestLookupBackendCapabilities_OneAggregation, but #7338 fails it on its own base too. #7338 just needs a rebase over #6903.
The no-cache path is narrower than the description suggests. FromIdentity reads the token's own iss claim, so a JWT validator without a configured issuer still caches as long as the token carries iss. Only tokens without an iss claim bypass the cache. docs/arch/10 already says this correctly. The downstream embedders I checked both set an issuer, so neither takes the bypass.
|
Thanks for the careful review, and for probing the sessionless case with a real probe. I've started a branch for the follow-up locally and will push it once this one is in, so it can sit on main. The plan is to add the names of the upstream providers that have a token loaded to the cache key (never the token values). That separates an interactive token from a sessionless one for the same user, and it doesn't re-key on every token refresh the way hashing would. I'm leaving the 30 second window after a connect or disconnect on stored credentials as it is for now. CI is green, so I'll merge this one. |
Summary
The vMCP capability cache and its shared in-flight discovery sweep were keyed on the caller's
Subjectstring alone. Two callers with the same subject but different issuers, or an interactive caller and a delegated one (different client or actor), got the same key. The second caller could be served the first caller's capability view from the cache, or by joining the first caller's sweep. What a backend returns depends on the credentials presented to it, so those views can differ.sessionbinding.FromIdentity: issuer and subject, plus route, client and optional actor for delegated identities) andIdentity.PlatformUserID, together with the forwarded headers and backend IDs as before. The binding and platform user ID are length-framed so the two fields cannot run into each other.docs/arch/10said Modern discovery is never cached; it now describes the 30 second per-identity cache and the bypass.docs/arch/17notes that the cache uses the same binding as session ownership.Type of change
Test plan
task test)task test-e2e)task lint-fix)New tests cover the key (delegated with and without an actor, empty and set platform user ID, the binding and platform user ID boundary, nil identity, unbindable identity) and cancellation on the bypass path. The final cache-hit assertions in an existing test now run through the bounded helpers, so a regression fails quickly instead of hanging.
Does this introduce a user-facing change?
Yes, for the capability cache:
iss, or with JWT validators that have no issuer configured. Requests with no identity at all are still cached.Special notes for reviewers
DoChanruns it on its own goroutine. The direct path behaves like running without the cache, where a panic unwinds the request goroutine. A comment says so.sharedSweepin the same file, plus the same test anddocs/arch/10. The hunks are in different places, so I expect a clean merge either way.