Skip to content

Support Entra on-behalf-of (OBO) backend auth in OSS #7199

Done

Description

@tgrunnagle

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 (MiddlewareParameters with Validate / ExchangeTarget, Exchanger, TokenExchanger, Token). Keep ValidationError.
    • Add a dependency-guard test that fails if pkg/auth/obo/... links k8s.io/ or sigs.k8s.io/, so the proxyrunner image stays free of Kubernetes code.
  • pkg/auth/obo/entra/: the Entra exchanger.
    • RFC 7523 jwt-bearer grant with requested_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.
  • 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 from Identity.UpstreamTokens[subjectTokenProviderName] when that is set;
    • exchanges it and replaces the Authorization: Bearer header.
  • 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 existing ExternalAuthType switches like addAWSStsConfig. The RegisterOBOHandler indirection goes away.
  • New check: an obo config on an MCPServer or MCPRemoteProxy without incoming oidcConfig is rejected at reconcile with Valid=False / Reason=InvalidConfig. OBO needs an authenticated user identity, and without this check every request would fail with 401 at runtime.
  • In MCPExternalAuthConfig reconcile: ValidationError maps to InvalidConfig with no requeue, and other errors requeue. EnterpriseRequired is 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). ResolveSecrets reads 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.NewOutgoingAuthRegistry registers 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, and ConditionReasonEnterpriseRequired exported 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, and task docs, and bump the CRD chart version.
  • Update docs/arch/ (core concepts, operator, vMCP) and docs/remote-mcp-authentication.md.

Acceptance criteria

  • A valid obo MCPExternalAuthConfig reconciles to Valid=True. Missing tenant, client ID or secret ref, or both audience and scopes, gives Valid=False / Reason=InvalidConfig.
  • An MCPServer or MCPRemoteProxy referencing an obo config:
    • 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 MCPServer or MCPRemoteProxy with an obo config but no oidcConfig gets InvalidConfig with a clear message.
  • A VirtualMCPServer with OBO backends works in both inline (outgoingAuth) and discovered modes, including backends defined by MCPServerEntry. Two OBO backends in one vMCP get distinct secret env vars.
  • No code path in an OSS build returns ErrEnterpriseRequired or the 503 stub for obo.
  • 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 EnterpriseRequired updated.
  • CRDs, the CRD API doc, the chart, and architecture docs regenerated and updated.

User-facing change

  • Before: an obo-typed MCPExternalAuthConfig shows Valid=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 run CLI 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

Activity

  1. added
    enhancement
    size/XL
    vmcp
    on Nov 19, 2026
  2. added
    needs-triage
    on Nov 19, 2026
  3. self-assigned this
    on Nov 19, 2026
  4. removed
    needs-triage
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

authenhancementoperatorsize/XLvmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions