fix(mcp): create ApiKey permissions on init and support API keys with JWT auth#39604
fix(mcp): create ApiKey permissions on init and support API keys with JWT auth#39604aminghadersohi wants to merge 4 commits intoapache:masterfrom
Conversation
Code Review Agent Run #a46f3eActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
The CodeQL alert indicates logging of sensitive data (password), but the code logs API key prefixes (e.g., ["sst_"]), which are configuration values, not actual passwords or secrets. This seems like a false positive. The info-level log aids debugging API key authentication setup. superset/mcp_service/mcp_config.py |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #39604 +/- ##
==========================================
- Coverage 64.54% 64.52% -0.02%
==========================================
Files 2565 2566 +1
Lines 133665 133691 +26
Branches 31056 31061 +5
==========================================
Hits 86269 86269
- Misses 45904 45929 +25
- Partials 1492 1493 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Addressed all review comments in the latest commit: CodeQL (clear-text logging): False positive — the log line logs codeant-ai (type annotations): Added explicit type annotations to all new test function parameters and fixture return types across both test files. Fixtures now have return type annotations ( |
1cbd49c to
ed62ca2
Compare
Code Review Agent Run #933d30Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
… JWT auth Two fixes for MCP API key authentication: 1. superset init now creates ApiKey FAB permissions (can_list, can_create, can_get, can_delete) when FAB_API_KEY_ENABLED=True. Previously, because Superset uses AppBuilder(update_perms=False), FAB skipped permission creation during blueprint registration and superset init never picked them up, causing 403 errors on /api/v1/security/api_keys/. 2. CompositeTokenVerifier allows API key tokens (e.g. sst_...) to coexist with JWT auth on the MCP transport layer. Previously, when MCP_AUTH_ENABLED=True, the JWTVerifier rejected all non-JWT Bearer tokens at the transport layer before they could reach the Flask-level _resolve_user_from_api_key() handler. The composite verifier detects API key prefixes and passes them through with a marker claim, letting the existing auth priority chain handle validation.
Wire CompositeTokenVerifier into create_default_mcp_auth_factory, add _api_key_passthrough detection in _resolve_user_from_jwt_context, create ApiKey permissions in create_custom_permissions, and update test_auth_api_key with pass-through and non-matching prefix tests.
Address code review feedback: add explicit type annotations to all new test function parameters and fixture return types.
Remove API key prefixes from log message to avoid CodeQL false positive about clear-text logging of sensitive data.
ed62ca2 to
38828ab
Compare
Code Review Agent Run #257b47Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Review:
|
SUMMARY
Two fixes for MCP API key authentication that were discovered while testing #39437:
1.
superset initnow creates ApiKey FAB permissionsWhen
FAB_API_KEY_ENABLED=True, the/api/v1/security/api_keys/endpoints returned 403 because the required FAB permissions (can_list,can_create,can_get,can_deleteonApiKey) were never created. Superset usesAppBuilder(update_perms=False), so FAB skips permission creation during blueprint registration. The fix adds ApiKey permissions tocreate_custom_permissions()in the SecurityManager, which is called bysync_role_definitions()duringsuperset init.2. CompositeTokenVerifier allows API key tokens to coexist with JWT auth
When
MCP_AUTH_ENABLED=True, theJWTVerifierat the FastMCP transport layer rejected all non-JWT Bearer tokens (includingsst_...API keys) before they could reach the Flask-level_resolve_user_from_api_key()handler. The newCompositeTokenVerifierwraps the JWT verifier and detects API key prefixes — matching tokens pass through with a marker claim so the existing auth priority chain handles validation.Changes:
superset/security/manager.py: Add ApiKey permissions tocreate_custom_permissions()whenFAB_API_KEY_ENABLED=Truesuperset/mcp_service/composite_token_verifier.py: NewCompositeTokenVerifierthat routes tokens by prefixsuperset/mcp_service/mcp_config.py: Wrap JWT verifier withCompositeTokenVerifierwhen API keys enabledsuperset/mcp_service/auth.py: Detect_api_key_passthroughclaim in_resolve_user_from_jwt_context()and fall through to API key authBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — auth infrastructure changes with no UI impact.
TESTING INSTRUCTIONS
FAB_API_KEY_ENABLED = TrueandFEATURE_FLAGS = {"FAB_API_KEY_ENABLED": True}insuperset_config.pysuperset init— should create ApiKey permissions (verify: Admin role now hascan_list,can_create,can_get,can_deleteonApiKey)/profile/— API Keys section should load without errorsMCP_AUTH_ENABLED=True):pytest tests/unit_tests/mcp_service/test_auth_api_key.py tests/unit_tests/mcp_service/test_composite_token_verifier.py -vADDITIONAL INFORMATION
FAB_API_KEY_ENABLED