Repository navigation
Description
Summary
Make Microsoft Entra On-Behalf-Of (OBO) a working, built-in backend auth strategy in OSS ToolHive. It should cover all resources that can reference an MCPExternalAuthConfig: MCPServer, MCPRemoteProxy, VirtualMCPServer, and MCPServerEntry, which reaches OBO as a vMCP backend.
Why
The CRD surface for OBO is already in OSS: the obo enum value, a full OBOConfig with admission patterns, and authtypes.OBOConfig for vMCP. Every runtime dispatch point, though, is a stub that returns ErrEnterpriseRequired, or a 503 at the proxy. The real implementation lives in a private enterprise overlay that registers through four function-pointer hooks.
The decision has been made to make OBO a community feature. Today an OSS user who applies an obo config gets Valid=False / Reason: EnterpriseRequired. They should get a working Entra OBO exchange instead.
Current state (stubs to replace)
| Layer | Stub / hook |
|---|---|
| Operator: validate, RunConfig, secret env vars | controllerutil.OBOHandler / RegisterOBOHandler (cmd/thv-operator/pkg/controllerutil/tokenexchange.go) |
| Proxy runtime middleware | obo.CreateMiddleware 503 stub / obo.RegisterFactory (pkg/auth/obo/middleware.go) |
| vMCP converter | converters.OBOConverter (pkg/vmcp/auth/converters/obo.go) |
| vMCP outgoing strategy | oboStrategyStub / auth.RegisterOBOStrategy (pkg/vmcp/auth/obo.go) |
Proposed implementation (single PR)
Port the enterprise overlay's implementation into OSS under Apache-2.0, without //go:build enterprise, and make it the default at every dispatch point. All OSS changes land in one PR. That deliberately goes over the 400-line / 10-file guideline, because splitting it would leave OBO half-working across releases. Unit tests are ported alongside.
Protocol (no Kubernetes imports)
pkg/auth/obo/:- Add the shared contract (
MiddlewareParameterswithValidate/ExchangeTarget,Exchanger,TokenExchanger,Token). KeepValidationError. - Add a dependency-guard test that fails if
pkg/auth/obo/...linksk8s.io/orsigs.k8s.io/, so the proxyrunner image stays free of Kubernetes code.
- Add the shared contract (
pkg/auth/obo/entra/: the Entra exchanger.- RFC 7523
jwt-bearergrant withrequested_token_use=on_behalf_of. - Error classification:
interaction_required/ claims challenge / AADSTS50076 and 50079,invalid_grant,invalid_client, transient. - Tenant (GUID or domain) and authority validation, building
TokenURL. - Redirects refused, 1 MiB response cap.
- RFC 7523
pkg/auth/obo/cache/: a per-(user token hash, exchange target) token cache with expiry skew. Concurrent identical exchanges share one request, and the cache recovers from a panicking delegate.
Proxy runtime (MCPServer, MCPRemoteProxy)
- The real middleware becomes the default
obo.CreateMiddleware. It:- takes the subject token from
auth.Identity.Token, or fromIdentity.UpstreamTokens[subjectTokenProviderName]when that is set; - exchanges it and replaces the
Authorization: Bearerheader.
- takes the subject token from
- Error mapping: 401 (missing token or
invalid_grant), 403 plus an audit event (interaction required), 502 (other failures).
Operator
- Implement OBO validation, RunConfig, and secret-env-var generation directly in
controllerutil, called from the existingExternalAuthTypeswitches likeaddAWSStsConfig. TheRegisterOBOHandlerindirection goes away. - New check: an
oboconfig on anMCPServerorMCPRemoteProxywithout incomingoidcConfigis rejected at reconcile withValid=False / Reason=InvalidConfig. OBO needs an authenticated user identity, and without this check every request would fail with 401 at runtime. - In
MCPExternalAuthConfigreconcile:ValidationErrormaps toInvalidConfigwith no requeue, and other errors requeue.EnterpriseRequiredis no longer emitted. - The referenced client Secret is verified before the RunConfig is emitted.
vMCP (VirtualMCPServer, MCPServerEntry backends)
- Real
OBOConverter: CRD →authtypes.OBOConfig(tenant/authority → token URL, cacheSkew → seconds).ResolveSecretsreads the client secret. - Real OBO strategy in
pkg/vmcp/auth/strategies/obo.go. It keeps one cached exchanger per (token URL, client, skew, secret fingerprint), skips health checks, and writes an audit event on interaction required.factory.NewOutgoingAuthRegistryregisters it directly. - Fix during the port: the enterprise handler uses a fixed env var,
TOOLHIVE_OBO_CLIENT_SECRET, for the vMCP pod. Two OBO backends in one vMCP would then produce two env vars with the same name. Use a unique per-config name (GenerateUniqueOBOSecretEnvVarName(configName)), as XAA and tokenExchange already do.
Backward compatibility with the enterprise overlay
- Keep
RegisterOBOHandler,obo.RegisterFactory,auth.RegisterOBOStrategy,ErrEnterpriseRequired, andConditionReasonEnterpriseRequiredexported and marked// Deprecated:. The enterprise overlay keeps compiling until it is deleted. Removal is tracked separately (see related issues).
Docs and generated files
- Remove "requires an enterprise build" wording from the CRD Go doc comments, then run
task operator-manifests,task gen, andtask docs, and bump the CRD chart version. - Update
docs/arch/(core concepts, operator, vMCP) anddocs/remote-mcp-authentication.md.
Acceptance criteria
- A valid
oboMCPExternalAuthConfigreconciles toValid=True. Missing tenant, client ID or secret ref, or both audience and scopes, givesValid=False / Reason=InvalidConfig. - An
MCPServerorMCPRemoteProxyreferencing anoboconfig:- gets the OBO middleware in its RunConfig;
- gets the client secret as a pod env var;
- exchanges the incoming user token at the Entra token endpoint and forwards the exchanged token to the backend.
- An
MCPServerorMCPRemoteProxywith anoboconfig but nooidcConfiggetsInvalidConfigwith a clear message. - A
VirtualMCPServerwith OBO backends works in both inline (outgoingAuth) and discovered modes, including backends defined byMCPServerEntry. Two OBO backends in one vMCP get distinct secret env vars. - No code path in an OSS build returns
ErrEnterpriseRequiredor the 503 stub forobo. - The
pkg/auth/obo/...packages do not link Kubernetes (guard test). - Tests:
- unit tests ported (exchanger, cache, middleware, converter, strategy, operator);
- envtest integration tests for
Valid=True/InvalidConfig; - a vMCP integration test against a mock Entra token endpoint;
- existing tests that asserted
EnterpriseRequiredupdated.
- CRDs, the CRD API doc, the chart, and architecture docs regenerated and updated.
User-facing change
- Before: an
obo-typedMCPExternalAuthConfigshowsValid=False / Reason: EnterpriseRequired. Proxies return 503, and vMCP backends fail to authenticate. - After: OBO works for MCPServer, MCPRemoteProxy, VirtualMCPServer, and MCPServerEntry backends. Bad configs, including no incoming OIDC on MCPServer or MCPRemoteProxy, show
Reason: InvalidConfig.
Out of scope
thv runCLI flags for OBO (a follow-up). The middleware is in the runner factory map, so a RunConfig JSON already works.- Certificate or workload-identity client authentication for Entra (the CRD already leaves room for it).
Related
- Remove deprecated OBO enterprise hooks and sentinels #7200: remove the deprecated hooks after the overlay is deleted
- stacklok/stacklok-enterprise-platform#6946: delete the enterprise OBO overlay
- Document Entra OBO backend auth for community ToolHive docs-website#1360: user docs
Activity
Support Entra on-behalf-of backend auth in OSS (#7201)