feat: JWT auth middleware + /.well-known/oauth-protected-resource for supervisor and brain MCP servers (Dex OIDC) #6
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
auth.d-ma.benow runs Dex (OIDC/OAuth 2.0 AS). All MCP servers should accept JWTs issued by Dex or a static bearer token (backward compat). Two MCP servers in this repo need updating:internal/mcp/server.go,checkAuthfunctioningestion/internal/mcp/auth.go,BearerAuthmiddlewareBoth currently do plain static string compares. The new chain adds JWT validation before the static fallback.
Changes required
1. Supervisor —
internal/mcp/server.goCurrent
checkAuth:New behaviour:
Keep the existing
SUPERVISOR_MCP_TOKENenv var path intact — it's the static fallback.2. Brain —
ingestion/internal/mcp/auth.goCurrent
BearerAuthmiddleware does a plain string compare. Apply the same JWT-or-static chain:3. Shared JWT validation package
Create
internal/auth/jwt.go(or equivalent shared location) implementing:Dependency:
github.com/lestrrat-go/jwx/v2New env vars (both binaries):
DEX_ISSUER_URL— e.g.https://auth.d-ma.beJWKS discovery:
{DEX_ISSUER_URL}/.well-known/openid-configuration→jwks_uri.Use
jwk.NewCachewith 1 h refresh interval.Validation requirements:
iss==DEX_ISSUER_URLaudcontains the server's client ID (configurable, e.g.supervisor/brain)expnot expiredIf
DEX_ISSUER_URLis not set, skip JWT validation entirely and fall back to static token only (safe default during rollout).4.
/.well-known/oauth-protected-resourceendpoints (RFC 9728)Register on each server's HTTP mux (outside auth-protected routes):
Supervisor:
Brain:
Values from env vars (
MCP_RESOURCE_URL,DEX_ISSUER_URL).k3s manifest updates (in
mathias/infra)After code merged and images rebuilt:
k3s/apps/supervisor/deployment.yaml: addDEX_ISSUER_URL: https://auth.d-ma.bek3s/apps/infra-mcp/deployment.yaml(brain): addDEX_ISSUER_URL: https://auth.d-ma.beNote:
SUPERVISOR_MCP_TOKENenforcement is currently off in k3s (env var not set). JWT auth can be wired up independently; static token enforcement can be turned on together.Testing
DEX_ISSUER_URLunset → only static token auth appliesGET /.well-known/oauth-protected-resourceon each server returns correct JSONRelated
auth.d-ma.beviak3s/apps/auth/inmathias/inframathias/gitea-mcp(separate issue there)