ADR 0008: oauth as a resource server, not an authorization server
Context
REDMINE_AUTH_MODE=oauth needs an MCP client to authenticate its user against
Redmine’s Doorkeeper OAuth2 provider and present the resulting access token to
this server. The design space has three shapes: (1) hand-roll bearer
validation inside the existing per-request choke point (RedmineMcp::scoped,
the shape legacy-per-user uses), (2) mint our own tokens as a second
authorization server (oauth-proxy, explicitly out of scope for v1.0), or (3)
be a pure OAuth resource server: validate a token someone else issued, by
asking its issuer.
Two findings, verified against the vendored dependencies (rmcp 3.1.1,
reqwest 0.13.4), decided this ADR:
- rmcp ships no server-side OAuth support. Its
authfeature andtransport::authmodule are an OAuth client (this process authenticating to another MCP server) —AuthClient/OAuthState/AuthorizationManager. Nothing instreamable_http_server/ever emits aWWW-Authenticateheader. Enabling that feature would pull inoauth2for zero server-side benefit. - Doorkeeper issues opaque tokens with no published JWKS. There is nothing to validate offline as a JWT. RFC 7662 introspection — a network call to Redmine per (uncached) token — is the only validation Redmine supports.
Decisions
- O1 — an axum middleware in front of the MCP route, not a check inside
scoped(). An MCP client discovers that it needs a token, and where to get one, from an HTTP401carryingWWW-Authenticate: Bearer resource_metadata="…". A JSON-RPC-level error inside a200response (thelegacy-per-usershape) is invisible to that machinery — the client never starts the OAuth flow. This means every MCP request,initializeincluded, needs a token in this mode;legacy-per-user’s decision to leaveinitialize/tools/listopen does not carry over. - O2 — fail closed on a missing
AuthContext. The middleware inserts a validatedAuthContextinto the request extensions;scoped()’s OAuth arm reads it back out and returnsclient.as_user_owned(Credential::Bearer(..)), or an internal error — never a fallback — if the extension is absent. A future refactor that mounts the route without the middleware breaks loudly on every tool call instead of running unauthenticated. - O3 — introspection and revocation reuse
RedmineClient, scoped toCredential::Basic, not a secondreqwest::Client. Doorkeeper is part of the Redmine deployment: same origin, same TLS/custom-CA/mTLS configuration, same timeouts, same connection pool. A second client would silently ignoreREDMINE_SSL_VERIFYand the CA settings — the classic way a TLS bypass sneaks in. - O4 — the introspection cache is keyed by SHA-256 of the token, never the
token itself, with a positive TTL capped by the token’s own
expand a short fixed TTL for a negative (active:false) result. A digest key means the cache cannot leak a plaintext token in a core dump or a strayDebug. A fingerprint collision in a log line (the shapelegacy-per-user’sKeyFingerprintuses) is a cosmetic annoyance; a collision in this cache would serve one user’s session to another, which is why that fingerprint is not reused here. - O7 — introspection unavailability is
503, never401.401tells the client “your token is bad, re-authorize”; sending it when this server (or Redmine) is broken would send every connected client through a pointless browser flow and hide an outage as a fleet-wide auth failure.
Consequences
- No audience binding. Doorkeeper introspection returns no
aud, so this server cannot verify a presented token was issued for it rather than for another OAuth client of the same Redmine. Any holder of any valid Redmine access token can drive this server as that user — the confused-deputy shape the MCP authorization spec warns about. Accepted: it is also the reference server’s behaviour, unfixable without upstream Redmine changes, and bounded by the token granting no more than it already grants directly against Redmine’s own REST API. Documented indocs/oauth-setup.md. - Cache staleness on revocation. A token revoked at Redmine stays usable
here for up to the cache’s positive TTL (default 60s, capped further by the
token’s own
exp). Mitigated by the low default and byPOST /revokepurging the cache entry it revokes. - A new dependency,
sha2, on the auth path, for the sake of a cache key. Small, audited, RustCrypto-maintained; the alternative (no cache) doubles Redmine traffic per tool call, and a 64-bit keyed hash (as used forlegacy-per-user’s audit fingerprint) is the wrong trade-off for a cache key rather than a log breadcrumb. legacyandlegacy-per-userare untouched. The middleware is mounted only whenRedmineMcp::verifier()returnsSome(i.e. only inoauthmode), so neither existing mode’s request shape, error shape, or tests change.