Repository navigation
Description
Summary
defaultMultiSessionFactory.RestoreSession fabricates a partial *auth.Identity (originally only Subject; later refactored to also include Claims[\"iss\"]/Claims[\"sub\"]), but Token and UpstreamTokens are always empty. That partial struct is captured as identityRoundTripper.fallbackIdentity in every backend connector created during restore.
There are two related but distinct failure modes:
1 — Tool calls after cross-pod failover return 401 (original issue)
After RestoreSession runs on a different pod, every backend tool call using upstreamInject / tokenExchange / aws_sts outgoing auth goes out with an empty UpstreamTokens map and returns 401. This is fixed once the round-tripper defers to req.Context() instead of the captured fallback (see #5323 and the sibling fix for mcp_session.go's round-tripper).
2 — Backend MCP Initialize handshake during restore is unauthenticated (new scope)
loadSession — the cache-miss restore path triggered by an incoming authenticated request — uses context.Background() when calling RestoreSession. This means the backend's Initialize handshake (which runs eagerly as part of RestoreSession to negotiate capabilities) carries no identity and therefore no upstream tokens. Backends that require authentication on Initialize will fail, and the restored session silently loses those backends' capabilities.
The root cause is structural: GetMultiSession carries no context, so loadSession cannot receive the incoming request's identity-bearing context.
For deployments with Redis-backed session storage, replicas > 1, and backends requiring upstream auth even on Initialize, this manifests as a capability hole on every cross-pod failover.
Single-replica deployments with the default LocalSessionDataStorage never hit RestoreSession and are unaffected.
Fix (updated scope)
The complete fix requires two layers:
Layer A — stop fabricating partial identity (done in PR #5650)
Pass nil to makeBaseSession instead of &auth.Identity{Subject, Claims} with empty Token/UpstreamTokens. A non-nil *auth.Identity must always be fully populated (field-completeness contract in pkg/auth/identity.go). The round-tripper's fallback-only invariant (from #5323 and its sibling) means live tool calls are unaffected.
Layer B — propagate the incoming request's context through to loadSession / RestoreSession
Add context.Context to:
pkg/cache/validating_cache.go:ValidatingCache.Get,load func, andcheck funcpkg/vmcp/server/session_manager_interface.go:SessionManager.GetMultiSessionpkg/vmcp/server/sessionmanager/session_manager.go:Manager.GetMultiSession,loadSession,checkSessionpkg/vmcp/server/serve_handlers.go:enforceSessionBinding(the sole productionGetMultiSessioncall site)
loadSession uses context.WithoutCancel(ctx) to extract the identity from the caller's context while deliberately NOT propagating the caller's cancellation — the restore must complete even if the triggering request times out or is cancelled, since concurrent singleflight participants depend on the result.
Acceptance criteria
-
RestoreSessionno longer produces a half-populated*auth.Identityand is internally consistent with theToken-required invariant enforced for new sessions. -
MetadataKeyIdentityBinding(encoding bothissandsub) is preserved across restore. -
auth.Identitygodoc states the field-completeness contract. -
ValidatingCache.Getaccepts acontext.Contextand forwards it to theloadandcheckcallbacks. -
SessionManager.GetMultiSessionaccepts acontext.Context. -
loadSessionusescontext.WithoutCancel(ctx)so the incoming identity propagates toRestoreSessionbut the caller's cancellation does not abort an in-progress restore. - Backend
Initializehandshakes duringRestoreSessionare authenticated when a live identity is available on the triggering request's context. - No path in
pkg/vmcp/session/constructs an&auth.Identity{Subject: …}withTokenandUpstreamTokensunset. - E2E test extension in
test/e2e/thv-operator/virtualmcp/virtualmcp_redis_session_test.go: cross-pod restore followed by a tool call against a backend withupstreamInjectoutgoing auth succeeds end-to-end.
Related
- [vMCP] identityPropagatingRoundTripper captures stale identity, bypassing per-request upstream token refresh #5323 — fixes one consumer of this partial identity (
pkg/vmcp/client/client.go'sidentityPropagatingRoundTripper). - Sibling issue for
pkg/vmcp/session/internal/backend/mcp_session.go'sidentityRoundTripper. docs/arch/13-vmcp-scalability.md— multi-replica deployment topology this affects.
Activity
Propagate request context through GetMultiSession to RestoreSession
Stop fabricating partial identity in RestoreSession
Address review feedback: fix stale comment, add E2E TODO
Propagate request context through GetMultiSession to RestoreSession
Add E2E test for upstreamInject identity after cross-pod Redis restore
Stop fabricating partial identity in RestoreSession
Address review feedback: fix stale comment, add E2E TODO
Propagate request context through GetMultiSession to RestoreSession
Add E2E test for upstreamInject identity after cross-pod Redis restore
Stop fabricating partial identity in RestoreSession (#5650)
Add E2E test for upstreamInject identity after cross-pod Redis restore
Add E2E test for upstreamInject identity propagation after cross-pod …