ADR 0003: Composable HTTP authentication and key pass-through

Why HTTP serve acts as a stateless OAuth 2.1 Resource Server alongside static bearer tokens and same-origin caller key pass-through.

Context

what-if runs primarily over local stdio and trusted tailnet proxies, where a static server_token suffices. However, hosted and GUI MCP clients require OAuth 2.1 discovery and bearer token verification, and multi-caller gateways often need per-caller upstream API keys without embedding an identity provider or token database inside a minimal static Go binary.

Decision

  1. External IdP as a stateless Resource Server: what-if serve delegates user login and client registration to an external Authorization Server, serving RFC 9728 Protected Resource Metadata (/.well-known/oauth-protected-resource and /.well-known/oauth-protected-resource/_/mcp) and verifying bearer tokens via asymmetric JWKS (RS*, PS*, ES*, EdDSA) and/or RFC 7662 introspection using Go stdlib crypto and go-sdk/auth. alg:none, symmetric HS*, and fallback from invalid JWT signatures to introspection are strictly rejected.
  2. Preserve static bearer compatibility: server_token remains verified in constant time alongside OAuth when both are configured so headless CI and cron scripts keep working without OAuth client credentials.
  3. Header-scoped caller pass-through: Because go-sdk's Streamable HTTP transport dispatches tool handlers on session goroutines, pass-through reads caller keys from req.Extra.Header (X-Upstream-API-Key when combined with static or OAuth inbound auth; Authorization: Bearer when standalone) rather than HTTP middleware context. Passed-through keys override target.APIKey only when target.BaseURL matches the default base_url, bind Streamable HTTP sessions via a SHA-256 UserID, and are scrubbed from errors before reaching MCP callers.

Consequences

  • go.mod adds zero new external dependencies and < 11 MB scratch container images stay untouched.
  • Multi-tenant and remote OAuth MCP clients work without an embedded login UI or database.
  • Backends configured on distinct tiers.<name>.base_url hosts never receive caller pass-through credentials from another origin.

Connections

Local graph

Linked from

  • “ADR 0003: Composable HTTP authentication and key pass-through”