feat(auth): add Dex JWT middleware to supervisor, routing pod, and brain MCP
Closes #6 on gitea.d-ma.be/mathias/hyperguild. Dex is deployed at auth.d-ma.be. All three MCP servers now accept JWTs issued by Dex in addition to static bearer tokens, enabling claude.ai OAuth 2.0 integration without abandoning backward-compat CLI auth. Changes: - internal/auth/: new Validator (JWKS auto-refresh via lestrrat-go/jwx/v2), ProtectedResourceHandler (RFC 9728 /.well-known/oauth-protected-resource) - internal/mcp/Server: adds optional *auth.Validator; checkAuth tries JWT first, then static token fallback; both-nil = auth disabled (unchanged default) - cmd/supervisor, cmd/routing: construct Validator from DEX_ISSUER_URL + MCP_AUDIENCE env vars; register protected-resource handler when set - ingestion/internal/auth/: same Validator + handler (separate module) - ingestion/internal/mcp/BearerAuth: same JWT-or-static chain - ingestion/cmd/server: same wiring pattern New env vars (all optional; absent = static-token-only, same as before): DEX_ISSUER_URL — Dex issuer URL (e.g. https://auth.d-ma.be) MCP_AUDIENCE — expected aud claim (e.g. brain, supervisor) MCP_RESOURCE_URL — resource identifier for RFC 9728 metadata response Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ func jsonBody(t *testing.T, v any) *bytes.Buffer {
|
||||
|
||||
func TestMCPInitialize(t *testing.T) {
|
||||
reg := registry.New()
|
||||
srv := mcp.NewServer(reg, "")
|
||||
srv := mcp.NewServer(reg, "", nil)
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/mcp", jsonBody(t, map[string]any{
|
||||
"jsonrpc": "2.0",
|
||||
@@ -45,7 +45,7 @@ func TestMCPInitialize(t *testing.T) {
|
||||
|
||||
func TestMCPToolsList(t *testing.T) {
|
||||
reg := registry.New()
|
||||
srv := mcp.NewServer(reg, "")
|
||||
srv := mcp.NewServer(reg, "", nil)
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/mcp", jsonBody(t, map[string]any{
|
||||
"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": map[string]any{},
|
||||
@@ -63,7 +63,7 @@ func TestMCPToolsList(t *testing.T) {
|
||||
|
||||
func TestMCPUnknownMethod(t *testing.T) {
|
||||
reg := registry.New()
|
||||
srv := mcp.NewServer(reg, "")
|
||||
srv := mcp.NewServer(reg, "", nil)
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/mcp", jsonBody(t, map[string]any{
|
||||
"jsonrpc": "2.0", "id": 3, "method": "unknown/method", "params": map[string]any{},
|
||||
@@ -80,7 +80,7 @@ func TestMCPUnknownMethod(t *testing.T) {
|
||||
|
||||
func TestMCPNotificationKnownMethodGetsNoResponseBody(t *testing.T) {
|
||||
reg := registry.New()
|
||||
srv := mcp.NewServer(reg, "")
|
||||
srv := mcp.NewServer(reg, "", nil)
|
||||
|
||||
// JSON-RPC 2.0 notification: "id" field absent. Per spec, server MUST NOT
|
||||
// reply. notifications/initialized is part of the standard MCP handshake.
|
||||
@@ -116,7 +116,7 @@ func TestMCPAuth(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
reg := registry.New()
|
||||
srv := mcp.NewServer(reg, tc.token)
|
||||
srv := mcp.NewServer(reg, tc.token, nil)
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/mcp", jsonBody(t, map[string]any{
|
||||
"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": map[string]any{},
|
||||
@@ -142,7 +142,7 @@ func TestMCPAuth(t *testing.T) {
|
||||
|
||||
func TestMCPNotificationUnknownMethodGetsNoResponseBody(t *testing.T) {
|
||||
reg := registry.New()
|
||||
srv := mcp.NewServer(reg, "")
|
||||
srv := mcp.NewServer(reg, "", nil)
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/mcp", jsonBody(t, map[string]any{
|
||||
"jsonrpc": "2.0",
|
||||
|
||||
Reference in New Issue
Block a user