Skip to content

vMCP core backend calls use ctx identity instead of the explicit identity #7143

Done

Description

@tgrunnagle

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, GetPrompt and Complete
  • capability aggregation in the List*, Lookup*, Discover and ListBackends methods, 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.

  1. Set the explicit identity on ctx when a core method starts. Every core method that takes an identity derives its context the same way executeComposite does now, which would absorb that attach. It's small and keeps today's interfaces. The trade-off is more reliance on identity in ctx, which .claude/rules/vmcp-anti-patterns.md fix(typo): corrects readme #1 warns against, and the VMCP contract comment would need to describe it.
  2. Pass the identity explicitly to the components that need it. Add an identity parameter to the vmcp.BackendClient methods, capability aggregation, the outgoing auth strategies and backend telemetry. This removes the ctx dependency 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 ctx identity, and a nil identity.
  • The PR describes the behavior change for direct callers of the core as a before and after.

Activity

  1. added
    vmcp
    on Nov 14, 2026
  2. added
    needs-triage
    on Nov 14, 2026
  3. 01men commented on Nov 16, 2026

    @01men

    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.go is 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 "whatever ctx carries" — and the criterion only holds if callers are trusted to pass a ctx with 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:

    ctx = context.WithValue(ctx, auth.IdentityContextKey{}, identity) // typed nil is fine

    context.WithValue stores a typed (*auth.Identity)(nil), and IdentityFromContext (pkg/auth/context.go:116-119) returns false for that because it checks ok && identity != nil. Anonymous is then genuinely anonymous rather than "reuse whatever was there."

    auth.WithIdentity cannot be the helper for this

    executeComposite is called out in the issue as the model to copy, and it uses context.WithValue rather than auth.WithIdentity. The comment there explains why (core_calls.go:280-282), and the nil half is the part worth carrying into the other methods:

    func WithIdentity(ctx context.Context, identity *Identity) context.Context {
    	if identity == nil {
    		return ctx          // <-- leaves the stale identity in place
    	}
    	if holder, ok := IdentityHolderFromContext(ctx); ok {
    		holder.Identity = identity   // <-- and mutates a shared holder
    	}
    	return context.WithValue(ctx, IdentityContextKey{}, identity)
    }

    Both branches are wrong for this purpose. WithIdentity(ctx, nil) returns ctx unchanged, so an anonymous parameter inherits the caller's identity. The holder branch additionally writes to auth.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/admission already calls auth.WithIdentity(ctx, identity) at seven sites (admission.go:155, 190, 205, 241, 267, 277, 298) before authorizing. So the nil → 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 passes ctx through 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*, Discover and ListBackends methods". But CallTool aggregates as well — c.aggregatedView(ctx) at core_calls.go:49, before the composite/backend branch — and cachingAggregator.AggregateCapabilities keys on cacheKey(ctx, backends) (caching_aggregator.go:118-123), which reads id.Subject from ctx.

    So a direct caller that passes a different identity in ctx and in the parameter doesn't just get a wrong-keyed cache entry on tools/list: the very first CallTool on a backend route populates the cache under the ctx subject, and the next ListTools for the parameter identity can be served that entry. That widens the acceptance criterion from "the capability cache uses the parameter identity" to "and the aggregation CallTool performs on its own path must too", otherwise a passing ListTools test can still be fed a poisoned entry by an earlier CallTool.

    Worth adding to the test matrix: call CallTool with a mismatched pair first, then ListTools with the parameter identity, and assert the second call does not observe the first call's identity-keyed entry.

    Two smaller things

    • The issue says #7135 used context.WithValue(ctx, auth.IdentityContextKey{}, identity), and that a nil identity "stays anonymous". That is correct, and it works only because IdentityFromContext treats 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.
    • backendtelemetry and the outgoing auth strategies are named in the issue as reading ctx, but client.go:702 captures a fallbackIdentity from 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.WithValue directly with a comment pointing at the typed-nil semantics, and put the derive on CallTool (including its aggregation), ReadResource, GetPrompt and Complete — not in a wrapper, since CheckToolCall deliberately must not invoke the tool.

  4. removed
    needs-triage
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authtech-debtvmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions