-
Notifications
You must be signed in to change notification settings - Fork 615
[BUG]: JWT token creation divergence between CLI and API #2261
Copy link
Copy link
Labels
SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releaseP2: Important but not vital; high-value items that are not crucial for the immediate releasebugSomething isn't workingSomething isn't working
Milestone
Description
🐞 Bug Summary
There are two different JWT token creation paths that produce incompatible token formats:
CLI Tokens (create_jwt_token.py)
- Minimal claims:
sub,iat,iss,aud,jti,exp,env - Missing:
user,teams,namespaces,scopes - Usage: README.md, api-usage.md examples
API Tokens (/tokens endpoint via token_catalog_service.py)
- Rich claims:
sub,iat,iss,aud,jti,exp,user,teams,namespaces,scopes - Created via:
/tokensAPI endpoint with full validation
Impact
- CLI tokens lack admin support - No
user.is_adminflag → admins can't use CLI tokens for admin operations - CLI tokens are public-only - No
teamsfield → non-admins always get public-only access - Documentation misleads users - Suggests using CLI tokens for API testing but they have limited capabilities
- Code duplication - Token creation logic duplicated between CLI and API paths
Expected Behavior
- CLI and API should produce identical token formats when given the same parameters
- CLI tokens should support admin, team, and scope claims for development/testing
- Token creation logic should be unified in a single location
- Documentation should clearly explain security implications of CLI token generation
Proposed Solution
- Enhance
_create_jwt_token()to accept optional rich claims (user_data,teams,namespaces,scopes) - Update
token_catalog_service._generate_token()to delegate to enhanced utility - Add CLI flags:
--admin,--teams,--scopes,--full-name - Display security warnings when creating tokens with elevated claims
- Update documentation with clear security guidance
Security Considerations
The CLI tool has access to JWT_SECRET_KEY and can create tokens with any claims, bypassing all API security controls:
- User authentication/authorization
- Team membership validation
- Permission scope containment
- Audit logging
This is by design for development/testing. Production token management should use the /tokens API endpoint which enforces all security controls.
🧩 Affected Component
Select the area of the project impacted:
-
mcpgateway- API -
mcpgateway- UI (admin panel) -
mcpgateway.wrapper- stdio wrapper - Federation or Transports
- CLI, Makefiles, or shell scripts
- Container setup (Docker/Podman/Compose)
- Other (explain below)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releaseP2: Important but not vital; high-value items that are not crucial for the immediate releasebugSomething isn't workingSomething isn't working