Skip to content

feat: implement OIDC authentication for admin users - #316

Merged
domdomegg merged 3 commits into
mainfrom
adamj/oidc-login
Aug 27, 2025
Merged

domdomegg merged 3 commits into
mainfrom
adamj/oidc-login

Conversation

@domdomegg

Copy link
Copy Markdown
Member

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

@domdomegg

Copy link
Copy Markdown
Member Author

@claude please review

@claude

claude Bot commented Aug 27, 2025 •

Copy link
Copy Markdown
Contributor

Claude finished @domdomegg's task —— View job


Code Review: OIDC Authentication Implementation ✅

Comprehensive review of the OIDC authentication implementation for admin users.

Review Summary:

✅ Overall Quality: Excellent implementation with proper security practices
✅ Architecture: Well-structured with clear separation of concerns
✅ Testing: Good test coverage with meaningful test cases
✅ Configuration: Proper environment variable setup for all environments

Detailed Security & Code Review

🛡️ Security Analysis - APPROVED

Token Validation (internal/api/handlers/v0/auth/oidc.go:93-140)

  • ✅ Proper OIDC token verification using go-oidc library
  • ✅ Signature verification against provider's JWKS endpoint
  • ✅ Standard claims validation (iss, sub, aud, exp, nbf, iat)
  • ✅ Extra claims validation for domain restriction (hd: modelcontextprotocol.io)

State Management (internal/api/handlers/v0/auth/oidc.go:318-372)

  • ✅ CSRF protection with cryptographically secure state/nonce generation
  • ✅ Session timeout (5 minutes) to prevent replay attacks
  • ✅ Proper session cleanup after callback processing
  • ✅ Uses crypto/rand for secure random string generation

Authorization Flow (internal/api/handlers/v0/auth/oidc.go:349-372)

  • ✅ Standard OAuth2 authorization code flow implementation
  • ✅ Proper redirect URI validation
  • ✅ ID token extraction and validation from token response

🏗️ Architecture Review - APPROVED

Interface Design (internal/api/handlers/v0/auth/oidc.go:48-53)

  • ✅ Clean GenericOIDCValidator interface allows for testing and extensibility
  • ✅ Proper separation between validation logic and HTTP handlers
  • ✅ Testable design with dependency injection support

Error Handling

  • ✅ Consistent error wrapping with descriptive messages
  • ✅ Proper HTTP status codes (401 for auth failures, 400 for bad requests)
  • ✅ No sensitive information leakage in error messages

Permission System (internal/api/handlers/v0/auth/oidc.go:404-434)

  • ✅ Configurable permissions via environment variables
  • ✅ Wildcard support for admin access patterns
  • ✅ Integration with existing JWT claims structure

🧪 Test Coverage Review - APPROVED

Test Structure (internal/api/handlers/v0/auth/oidc_test.go)

  • ✅ Well-structured mock implementation for testing
  • ✅ Tests cover both success and failure scenarios
  • ✅ Domain validation testing (correct vs incorrect hosted domain)
  • ✅ Authorization URL generation testing

Test Cases Coverage:

  • ✅ Token exchange with valid Google Workspace domain
  • ✅ Token validation failure with wrong domain
  • ✅ Authorization flow initiation
  • ✅ Mock validator properly implements interface

⚙️ Configuration Review - APPROVED

Environment Variables (.env.example:34-44, internal/config/config.go:30-37)

  • ✅ Comprehensive OIDC configuration options
  • ✅ Proper defaults and documentation
  • ✅ Secure handling of client secrets
  • ✅ Flexible permission configuration

Deployment Integration (deploy/pkg/k8s/registry.go:131-155)

  • ✅ Production-ready Kubernetes configuration
  • ✅ Proper secret management for sensitive values
  • ✅ Environment-specific configuration
  • ✅ Health checks and probes configured

📚 Documentation Review - APPROVED

Architecture Documentation (docs/architecture.md:212-248)

  • ✅ Clear sequence diagram showing OIDC flow
  • ✅ Practical usage examples with gcloud CLI
  • ✅ Integration with overall system architecture
Minor Suggestions for Future Enhancement

🔍 Potential Improvements

  1. Session Storage (internal/api/handlers/v0/auth/oidc.go:179)

    • Current in-memory session storage works for single instance
    • Consider Redis/database for multi-replica deployments
    • Not blocking for current deployment model
  2. Rate Limiting

    • Consider adding rate limiting on OIDC endpoints
    • Prevent brute force attacks on state parameters
    • Low priority given admin-only usage
  3. Audit Logging

    • Consider structured logging for OIDC auth events
    • Helpful for security monitoring and compliance
    • Enhancement for future iterations
  4. Token Refresh

    • Current implementation uses ID tokens (short-lived)
    • Could consider refresh token support for longer sessions
    • Not critical for CLI-based admin usage

✅ Final Recommendation: APPROVE

This is a high-quality, security-conscious implementation of OIDC authentication. The code follows best practices, has good test coverage, and properly integrates with the existing authentication system. Ready for merge.


Comment on lines +234 to +237
response, err := handler.ExchangeToken(ctx, input.Body.OIDCToken)
if err != nil {
return nil, huma.Error401Unauthorized("Token exchange failed", err)
}

@crondinini-ant crondinini-ant Aug 27, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have separate codes depending on the error at some point for the endpoints? At first glance, without all the context, 401 seems too generic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair - I think at some point we might want to look at improving the status codes and API ergonomics generally. I also think the way we send back errors to the client is a bit weird and undersanitized. But I think both of these are probably a bigger separate task.

@domdomegg
domdomegg merged commit 36fcdff into main Aug 27, 2025
@domdomegg
domdomegg deleted the adamj/oidc-login branch August 27, 2025 17:59
domdomegg added a commit that referenced this pull request Aug 28, 2025
…ement (#323)

## Summary
- Added comprehensive admin operations documentation
- Included scripts for common server management tasks

Together with #315, #316, this fixes #182
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth: Configurable OIDC authentication method

3 participants