Skip to content

Commit 36fcdff

Browse files
authored
feat: implement OIDC authentication for admin users (#316)
## Summary This PR implements OIDC authentication support for admin users, specifically configured for Google Cloud Identity. The implementation includes: - Configurable OIDC authentication endpoints and validation - Google Cloud Identity integration for admin access - JWT token validation and user session management - Deployment configuration updates for OIDC provider settings Fixes #283
1 parent 4dd295a commit 36fcdff

11 files changed

Lines changed: 704 additions & 6 deletions

File tree

‎.env.example‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@ MCP_REGISTRY_JWT_PRIVATE_KEY=bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb
2929
# Anonymous authentication for development/testing only
3030
# When enabled, allows anyone to get tokens for publishing to io.modelcontextprotocol.anonymous/* namespace
3131
# This should be disabled in prod
32-
MCP_REGISTRY_ENABLE_ANONYMOUS_AUTH=false
32+
MCP_REGISTRY_ENABLE_ANONYMOUS_AUTH=false
33+
34+
# Google Cloud Identity OIDC configuration for admin access
35+
# Enable OIDC authentication for @modelcontextprotocol.io admin accounts
36+
MCP_REGISTRY_OIDC_ENABLED=false
37+
# Example for Google Cloud Identity issuer
38+
MCP_REGISTRY_OIDC_ISSUER=https://accounts.google.com
39+
MCP_REGISTRY_OIDC_CLIENT_ID=1234.apps.googleusercontent.com
40+
# Require @modelcontextprotocol.io Google Workspace domain
41+
MCP_REGISTRY_OIDC_EXTRA_CLAIMS=[{"hd":"modelcontextprotocol.io"}]
42+
# Grant admin permissions to OIDC-authenticated users
43+
MCP_REGISTRY_OIDC_EDIT_PERMISSIONS=*
44+
MCP_REGISTRY_OIDC_PUBLISH_PERMISSIONS=*

‎deploy/pkg/k8s/registry.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env
128128
},
129129
},
130130
},
131+
// Google Cloud Identity OIDC for admin access
132+
&corev1.EnvVarArgs{
133+
Name: pulumi.String("MCP_REGISTRY_OIDC_ENABLED"),
134+
Value: pulumi.String("true"),
135+
},
136+
&corev1.EnvVarArgs{
137+
Name: pulumi.String("MCP_REGISTRY_OIDC_ISSUER"),
138+
Value: pulumi.String("https://accounts.google.com"),
139+
},
140+
&corev1.EnvVarArgs{
141+
Name: pulumi.String("MCP_REGISTRY_OIDC_CLIENT_ID"),
142+
Value: pulumi.String("32555940559.apps.googleusercontent.com"),
143+
},
144+
&corev1.EnvVarArgs{
145+
Name: pulumi.String("MCP_REGISTRY_OIDC_EXTRA_CLAIMS"),
146+
Value: pulumi.String(`[{"hd":"modelcontextprotocol.io"}]`),
147+
},
148+
&corev1.EnvVarArgs{
149+
Name: pulumi.String("MCP_REGISTRY_OIDC_EDIT_PERMISSIONS"),
150+
Value: pulumi.String("*"),
151+
},
152+
&corev1.EnvVarArgs{
153+
Name: pulumi.String("MCP_REGISTRY_OIDC_PUBLISH_PERMISSIONS"),
154+
Value: pulumi.String("*"),
155+
},
131156
},
132157
LivenessProbe: &corev1.ProbeArgs{
133158
HttpGet: &corev1.HTTPGetActionArgs{

‎docker-compose.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ services:
1616
- MCP_REGISTRY_JWT_PRIVATE_KEY=${MCP_REGISTRY_JWT_PRIVATE_KEY:-8103179d8ef955f6d3de6d6217224a909ec4060529dfeb1d4ca5a994537658cd}
1717
- MCP_REGISTRY_ENABLE_ANONYMOUS_AUTH=${MCP_REGISTRY_ENABLE_ANONYMOUS_AUTH:-true}
1818
- MCP_REGISTRY_SEED_FROM=${MCP_REGISTRY_SEED_FROM:-data/seed.json}
19+
- MCP_REGISTRY_OIDC_ENABLED=${MCP_REGISTRY_OIDC_ENABLED:-true}
20+
- MCP_REGISTRY_OIDC_ISSUER=${MCP_REGISTRY_OIDC_ISSUER:-https://accounts.google.com}
21+
- MCP_REGISTRY_OIDC_CLIENT_ID=${MCP_REGISTRY_OIDC_CLIENT_ID:-32555940559.apps.googleusercontent.com}
22+
- MCP_REGISTRY_OIDC_EXTRA_CLAIMS=${MCP_REGISTRY_OIDC_EXTRA_CLAIMS:-[{"hd":"modelcontextprotocol.io"}]}
23+
- MCP_REGISTRY_OIDC_EDIT_PERMISSIONS=${MCP_REGISTRY_OIDC_EDIT_PERMISSIONS:-*}
24+
- MCP_REGISTRY_OIDC_PUBLISH_PERMISSIONS=${MCP_REGISTRY_OIDC_PUBLISH_PERMISSIONS:-*}
1925
ports:
2026
- 8080:8080
2127
restart: "unless-stopped"

‎docs/architecture.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ graph TB
4444
MKT --> MC
4545
AGG --> MC
4646
API -.-> |Auth| GH
47+
API -.-> |Admin Auth| GCP[Google Cloud Identity]
4748
API -.-> |Verify| DNS
4849
API -.-> |Reference| NPM
4950
API -.-> |Reference| PYPI
@@ -206,4 +207,42 @@ sequenceDiagram
206207
API->>DB: Store verification
207208
API-->>CLI: Domain verified
208209
CLI-->>User: Success!
210+
```
211+
212+
### 4. Admin OIDC Authentication Flow
213+
214+
For registry administration, users with @modelcontextprotocol.io Google Cloud Identity accounts can authenticate using OIDC:
215+
216+
```mermaid
217+
sequenceDiagram
218+
participant Admin as Admin User
219+
participant CLI as Admin CLI
220+
participant GCP as Google Cloud Identity
221+
participant API as Registry API
222+
223+
Admin->>CLI: Request admin token
224+
CLI->>GCP: gcloud auth print-identity-token --audiences=mcp-registry
225+
GCP-->>CLI: ID Token (with hd: "modelcontextprotocol.io")
226+
CLI->>API: POST /v0/auth/oidc {"oidc_token": "eyJ..."}
227+
API->>GCP: Verify token signature (JWKS)
228+
API->>API: Validate claims (issuer, audience, hd)
229+
API->>API: Grant admin permissions (edit: *, publish: *)
230+
API-->>CLI: Registry JWT Token
231+
CLI->>API: POST /admin/* (with Registry JWT)
232+
API->>API: Validate JWT + permissions
233+
API-->>CLI: Admin operation success
234+
```
235+
236+
**Usage:**
237+
```bash
238+
# Get Google Cloud Identity token
239+
ID_TOKEN=$(gcloud auth print-identity-token)
240+
241+
# Exchange for Registry JWT token
242+
REGISTRY_TOKEN=$(curl -X POST /v0/auth/oidc \
243+
-H "Content-Type: application/json" \
244+
-d '{"oidc_token": "'$ID_TOKEN'"}' | jq -r .registry_token)
245+
246+
# Use for admin operations
247+
curl -H "Authorization: Bearer $REGISTRY_TOKEN" /v0/...
209248
```

‎go.mod‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.24.0
44

55
require (
66
github.com/caarlos0/env/v11 v11.3.1
7+
github.com/coreos/go-oidc/v3 v3.15.0
78
github.com/danielgtaylor/huma/v2 v2.34.1
89
github.com/golang-jwt/jwt/v5 v5.3.0
910
github.com/google/uuid v1.6.0
@@ -17,12 +18,15 @@ require (
1718
go.opentelemetry.io/otel/metric v1.37.0
1819
go.opentelemetry.io/otel/sdk v1.37.0
1920
go.opentelemetry.io/otel/sdk/metric v1.37.0
21+
golang.org/x/mod v0.27.0
22+
golang.org/x/oauth2 v0.30.0
2023
)
2124

2225
require (
2326
github.com/beorn7/perks v1.0.1 // indirect
2427
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2528
github.com/davecgh/go-spew v1.1.1 // indirect
29+
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
2630
github.com/go-logr/logr v1.4.3 // indirect
2731
github.com/go-logr/stdr v1.2.2 // indirect
2832
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
@@ -38,7 +42,6 @@ require (
3842
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
3943
go.opentelemetry.io/otel/trace v1.37.0 // indirect
4044
golang.org/x/crypto v0.41.0 // indirect
41-
golang.org/x/mod v0.27.0 // indirect
4245
golang.org/x/sys v0.35.0 // indirect
4346
golang.org/x/text v0.28.0 // indirect
4447
google.golang.org/protobuf v1.36.6 // indirect

‎go.sum‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5m
44
github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U=
55
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
66
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
7+
github.com/coreos/go-oidc/v3 v3.15.0 h1:R6Oz8Z4bqWR7VFQ+sPSvZPQv4x8M+sJkDO5ojgwlyAg=
8+
github.com/coreos/go-oidc/v3 v3.15.0/go.mod h1:HaZ3szPaZ0e4r6ebqvsLWlk2Tn+aejfmrfah6hnSYEU=
79
github.com/danielgtaylor/huma/v2 v2.34.1 h1:EmOJAbzEGfy0wAq/QMQ1YKfEMBEfE94xdBRLPBP0gwQ=
810
github.com/danielgtaylor/huma/v2 v2.34.1/go.mod h1:ynwJgLk8iGVgoaipi5tgwIQ5yoFNmiu+QdhU7CEEmhk=
911
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1012
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1113
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14+
github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE=
15+
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
1216
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
1317
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
1418
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
@@ -85,6 +89,8 @@ golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
8589
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
8690
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
8791
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
92+
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
93+
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
8894
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
8995
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
9096
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=

‎internal/api/handlers/v0/auth/main.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ func RegisterAuthEndpoints(api huma.API, cfg *config.Config) {
1313
// Register GitHub OIDC authentication endpoint
1414
RegisterGitHubOIDCEndpoint(api, cfg)
1515

16+
// Register configurable OIDC authentication endpoints
17+
RegisterOIDCEndpoints(api, cfg)
18+
1619
// Register DNS-based authentication endpoint
1720
RegisterDNSEndpoint(api, cfg)
1821

@@ -21,8 +24,4 @@ func RegisterAuthEndpoints(api huma.API, cfg *config.Config) {
2124

2225
// Register anonymous authentication endpoint
2326
RegisterNoneEndpoint(api, cfg)
24-
25-
// Future auth providers can be registered here:
26-
// RegisterGitLabEndpoint(api, cfg)
27-
// RegisterOIDCEndpoint(api, cfg)
2827
}

0 commit comments

Comments
 (0)