-
Notifications
You must be signed in to change notification settings - Fork 188
Description
Part of https://github.com/stacklok/stacklok-epics/issues/251
Depends on #3924
Summary
Implement the embeddedAuthServer outgoing auth strategy in vMCP so that backends requiring interactive upstream OAuth can trigger step-up authentication via 403 + insufficient_scope.
What needs to change
-
Return 403 with
insufficient_scope: When vMCP routes a request to a backend configured withembeddedAuthServerand no upstream token exists for the authenticated user, return HTTP 403 withWWW-Authenticate: Bearer error="insufficient_scope", scope="upstream:<provider_name>". The MCP SDK handles this natively and re-authenticates with the same authserver. -
New outgoing auth strategy: Create an
embedded_auth_serverstrategy type and register it in the outgoing auth factory (pkg/vmcp/auth/factory/outgoing.go). The strategy needs access to the authserver'sUpstreamTokenStorageto look up upstream tokens by user and provider. -
Strategy type and config: Add
embedded_auth_serverto the strategy type constants and config structs (pkg/vmcp/auth/types/types.go). Add a CRD converter forExternalAuthTypeEmbeddedAuthServerin the converter registry (pkg/vmcp/auth/converters/). -
Upstream token injection: When an upstream token exists for the user and provider, the strategy injects it into the outgoing request to the backend (similar to how
header_injectionworks, but the token comes from authserver storage rather than static config). -
Authserver integration: vMCP needs access to the authserver's
UpstreamTokenStorageinterface. Currently theEmbeddedAuthServerexposesIDPTokenStorage()— wire this into the outgoing auth strategy.
Testing
- Unit tests for the new strategy (mock UpstreamTokenStorage)
- Test 403 response generation with correct WWW-Authenticate header
- Test token injection when upstream token exists
- Test that non-embeddedAuthServer backends are unaffected