Repository navigation
Description
Problem
core.VMCP takes the caller's identity as an explicit parameter and, per its contract (pkg/vmcp/core/core.go), never reads it from ctx. The components below the core still read the caller from ctx through auth.IdentityFromContext:
- the outgoing auth strategies:
pkg/vmcp/auth/strategies/tokenexchange.go,upstream_inject.go,xaa.go,aws_sts.go - backend telemetry (
pkg/vmcp/internal/backendtelemetry) - the backend client's fallback identity (
pkg/vmcp/client/client.go) - the capability cache key (
pkg/vmcp/aggregator/caching_aggregator.go,cacheKey)
The core passes ctx through unchanged on these paths:
- the direct (non-composite) backend branch of
CallTool ReadResource,GetPromptandComplete- capability aggregation in the
List*,Lookup*,DiscoverandListBackendsmethods, which calls backends and uses the cache
So when the identity in ctx differs from the identity parameter (missing, or a different principal), the core authorizes the parameter identity but the backend call authenticates, records telemetry and keys the capability cache as the ctx identity. That is a confused-deputy shape.
Who is affected
Only programs that call the core directly. vmcp's own server passes the same identity in both places (pkg/vmcp/server/modern_dispatch.go), so its behavior is correct today.
Prior work
#7135 fixed this for composite workflows only. executeComposite runs the workflow on a context whose identity is set to the CallTool identity, using context.WithValue(ctx, auth.IdentityContextKey{}, identity) (not auth.WithIdentity, which also writes any auth.IdentityHolder and skips a nil identity). A nil identity stays anonymous. See TestCallTool_CompositeWorkflowAuditCarriesEnricherSubjects for the test pattern.
Options found so far
These are starting points, not a design. The implementer should pick an approach and work out the details.
- Set the explicit identity on
ctxwhen a core method starts. Every core method that takes an identity derives its context the same wayexecuteCompositedoes now, which would absorb that attach. It's small and keeps today's interfaces. The trade-off is more reliance on identity inctx, which.claude/rules/vmcp-anti-patterns.mdfix(typo): corrects readme #1 warns against, and theVMCPcontract comment would need to describe it. - Pass the identity explicitly to the components that need it. Add an identity parameter to the
vmcp.BackendClientmethods, capability aggregation, the outgoing auth strategies and backend telemetry. This removes thectxdependency instead of satisfying it, but it touches many packages, decorators, mocks and tests.
Acceptance criteria
- When a core method's identity parameter differs from the identity in
ctx, its backend calls (outgoing auth, telemetry, fallback identity) and the capability cache use the parameter identity. A nil parameter is treated as anonymous. - Tests cover three cases: identity passed only as a parameter, a conflicting
ctxidentity, and a nil identity. - The PR describes the behavior change for direct callers of the core as a before and after.
Activity
Test workflow enrichment on every event
Let vMCP embedders add audit event subjects (#7135)
01men commentedon Nov 16, 2026
Option 1 is the only one that satisfies the acceptance criteria's nil case, and the reason is not in the issue's description of it. Note also that
pkg/vmcp/core/core.gois already committed to the opposite reading of its own contract.The nil case decides the choice
The acceptance criteria say "A nil parameter is treated as anonymous." With option 2 the components keep calling
auth.IdentityFromContext, so "anonymous" means "whateverctxcarries" — and the criterion only holds if callers are trusted to pass actxwith no identity whenever the parameter is nil. Nothing enforces that, and the existing composite path shows the failure mode.Option 1 derives per call, so the parameter always wins:
context.WithValuestores a typed(*auth.Identity)(nil), andIdentityFromContext(pkg/auth/context.go:116-119) returnsfalsefor that because it checksok && identity != nil. Anonymous is then genuinely anonymous rather than "reuse whatever was there."auth.WithIdentitycannot be the helper for thisexecuteCompositeis called out in the issue as the model to copy, and it usescontext.WithValuerather thanauth.WithIdentity. The comment there explains why (core_calls.go:280-282), and the nil half is the part worth carrying into the other methods:Both branches are wrong for this purpose.
WithIdentity(ctx, nil)returnsctxunchanged, so an anonymous parameter inherits the caller's identity. The holder branch additionally writes toauth.IdentityHolder— a value shared with the request goroutine, which is why the existing comment rejects it ("that write would race").This matters more than it looks for option 1, because
pkg/vmcp/admissionalready callsauth.WithIdentity(ctx, identity)at seven sites (admission.go:155, 190, 205, 241, 267, 277, 298) before authorizing. So thenil→ anonymous mapping has to happen in the core, before admission, or admission will re-introduce the ctx identity for exactly the calls the criterion is about. Every core method listed in the issue's "The core passesctxthrough unchanged" section needs the derive at its own entry point, not once at the top of the request.The cache is affected on the read path too, and the issue scopes it to
List*The issue lists the cache key under "capability aggregation in the
List*,Lookup*,DiscoverandListBackendsmethods". ButCallToolaggregates as well —c.aggregatedView(ctx)at core_calls.go:49, before the composite/backend branch — andcachingAggregator.AggregateCapabilitieskeys oncacheKey(ctx, backends)(caching_aggregator.go:118-123), which readsid.Subjectfromctx.So a direct caller that passes a different identity in
ctxand in the parameter doesn't just get a wrong-keyed cache entry ontools/list: the very firstCallToolon a backend route populates the cache under thectxsubject, and the nextListToolsfor the parameter identity can be served that entry. That widens the acceptance criterion from "the capability cache uses the parameter identity" to "and the aggregationCallToolperforms on its own path must too", otherwise a passingListToolstest can still be fed a poisoned entry by an earlierCallTool.Worth adding to the test matrix: call
CallToolwith a mismatched pair first, thenListToolswith the parameter identity, and assert the second call does not observe the first call's identity-keyed entry.Two smaller things
#7135usedcontext.WithValue(ctx, auth.IdentityContextKey{}, identity), and that a nil identity "stays anonymous". That is correct, and it works only becauseIdentityFromContexttreats typed-nil as absent. If option 1 is adopted, that property deserves a test of its own rather than relying on it incidentally in the composite test.backendtelemetryand the outgoing auth strategies are named in the issue as readingctx, butclient.go:702captures afallbackIdentityfrom the construction context and only injects it when the request context carries none (client.go:420). So option 1's derive at method entry also changes what that fallback captures — in the desired direction, but it is a second behaviour change the PR description should mention.I'd take option 1, use
context.WithValuedirectly with a comment pointing at the typed-nil semantics, and put the derive onCallTool(including its aggregation),ReadResource,GetPromptandComplete— not in a wrapper, sinceCheckToolCalldeliberately must not invoke the tool.Carry explicit identity into vMCP backend calls (#7146)