Repository navigation
fix(mcp): recognise guest tokens on FastMCP 4 - #45639
aminghadersohi merged 5 commits into
Conversation
FastMCP 4's MultiAuth replaces AccessToken.client_id with a source-qualified JSON string and keeps the verifier's value in original_client_id. The resolver compared client_id against "guest" and "api_key", so guest and API-key tokens admitted by the CompositeTokenVerifier behind a MultiAuth fell through to username lookup and failed with "user not found". Compare the verifier's own client_id (original_client_id when present, else client_id) and use it for the default user resolver's client_id fallback. Because original_client_id is whatever the wrapped source set, the guest branch also re-verifies the raw bearer as a Superset guest token and builds the GuestUser from the decoded claims, so a guest-marked token from a source that does not strip the marker cannot pose as a guest.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45639 +/- ##
=======================================
Coverage 84.24% 84.24%
=======================================
Files 3057 3057
Lines 201726 201750 +24
Branches 47189 47194 +5
=======================================
+ Hits 169941 169971 +30
+ Misses 28541 28535 -6
Partials 3244 3244
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 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. |
CodeAnt PR Risk: Low Risk
Assessed commit: |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Hey @aminghadersohi, nobody asked me to review this one. I came to it because guest-token identity is an area I own and this changes how a guest token is recognised in the MCP auth path.
The forgeability you volunteered in the description is where I spent most of the time, and the bearer re-verification holds. I could not construct a shape that reaches get_guest_user_from_token with resources or rls_rules the GUEST_TOKEN_JWT_SECRET holder did not sign: foreign signing key, alg=none, foreign audience, expired, revoked by version and by dashboard cutoff, missing user/resources/rls_rules, claims edited on the AccessToken after verification, and original_client_id forced to guest from outside MultiAuth all fail closed. Building the GuestUser from the decoded bearer rather than the AccessToken copy is the right call, and the condition list in _reverify_guest_bearer mirrors the web request loader almost exactly. The isinstance(original, str) guard in get_verifier_client_id also does real work: a non-string original_client_id is correctly ignored rather than compared.
I ran the new file and the surrounding auth suites on fastmcp 4.1.2 and again on 3.4.7, the new tests against the merge base aabddf5b3f, and removed each re-verification condition one at a time to see which tests went red. Approving, four comments inline and none of them blocking. CI is fully green on 96ff69a.
| raise ValueError( | ||
| "Guest-marked token presented but embedded guest auth is not enabled" | ||
| ) | ||
| guest_claims = _reverify_guest_bearer(access_token) |
There was a problem hiding this comment.
Question rather than a finding: this now runs parse_jwt_guest_token and _is_guest_token_revoked on every _resolve_user_from_jwt_context, so once per tool call and once more for tools/list, where previously the revocation lookup ran once per transport verification. _is_guest_token_revoked_by_embedded does an EmbeddedDashboardDAO.find_by_id with a Dashboard.get fallback per dashboard resource in the token, so a guest token carrying several dashboards adds that many lookups per call. Is that a deliberate trade for having the check be authoritative at resolution time, or something you would rather scope to once per request?
There was a problem hiding this comment.
Yes: I am deliberately keeping the check authoritative at every identity resolution, including discovery, rather than trusting transport admission or caching by token/session. Your cost observation is correct: SupersetSecurityManager._is_guest_token_revoked_by_embedded iterates dashboard resources, calling EmbeddedDashboardDAO.find_by_id and potentially Dashboard.get for each.
I considered request-scoped caching, but the resolver does not own a reliable HTTP-request lifecycle: _get_app_context_manager supports request-backed calls, fresh per-call contexts without a Flask request, and worker-owned contexts; worker dispatch also copies context variables. A token/context/session cache is therefore not a cheap substitute for an explicitly bounded request cache, and could retain a result across later expiry/revocation. I documented the cost/freshness tradeoff rather than introducing that lifecycle change here.
Evidence: test_guest_reverification_observes_later_dashboard_revocation accepts the first resolution, advances a dashboard cutoff, and checks rejection on the second resolution (direct, tools/list, and tool search), with exactly two DAO lookups and only one GuestUser construction. The search case failed before 272e4a6; the direct/list cases are freshness controls. The sibling backend-failure regression also failed before that commit. Both discovery paths deny rejected credentials at head 124b496.
Siblings checked:
- superset/mcp_service/auth.py:599 — fixed in 272e4a6
- superset/mcp_service/server.py:450 — fixed in 272e4a6
- docs/admin_docs/configuration/mcp-server.mdx:664 — fixed in 272e4a6
- superset/mcp_service/guest_token_verifier.py:74 — not affected: transport admission is checked independently, never reused as a cached resolution decision
- superset/mcp_service/auth.py:1197 — not affected: retains the per-call/request/worker context selection contract; no cache was introduced
- superset/mcp_service/worker.py:505 — not affected: context copying is unchanged; no cached guest verification result is carried between calls
- superset/security/manager.py:6336 — not affected: per-dashboard revocation lookup semantics are unchanged
Remaining: no per-request cache is introduced; repeated resolution still pays the parse/revocation cost. I am leaving this question open for your response.
|
@gabotorresruiz Thanks for the review. I followed up on all four inline asks in 272e4a6, retained at merge head 124b496:
The sibling search also found discovery treating invalid guest credentials as absent auth and mishandling revocation-backend errors. The tool-search revocation case plus all three Siblings checked:
|
…cess part of #45535) Reduced backport of #45535 for 7.0: generate_dashboard and add_chart_to_existing_dashboard refuse charts the caller can't access (security_manager.can_access_chart), with their tests. Left out because they depend on code that only exists on master: - the layout-chart check in generate_dashboard, which needs superset.daos.dashboard._layout_chart_id from #44028, and its test_generate_dashboard_refuses_unlisted_layout_chart test; - test_chart_access_query_count.py, which calls the tool through inspect.unwrap and needs master's FastMCP 4 tool wrapping (#45639); - the docs change (docs deploy from master). (cherry picked from commit eee2c16, reduced)
SUMMARY
FastMCP 4's
MultiAuthqualifiesAccessToken.client_id, so comparing that field directly withguestorapi_keyloses Superset's identity routing. The default, unwrapped composite path does not have that qualification problem.The implementation at 124b496 includes:
get_verifier_client_id()for guest/API-key routing and the default resolver's fallback, supporting FastMCP 3 and 4. Regression:test_guest_token_resolves_as_guest,test_api_key_fast_path_through_multi_auth,test_api_key_fallback_through_multi_auth, andtest_default_user_resolver_uses_unqualified_client_id.test_forged_guest_marker_cannot_pose_as_guest,test_guest_resolution_uses_verified_claims,test_guest_reverification_requires_core_structure, andtest_guest_reverification_rejects_non_guest_type.test_idp_api_key_claims_cannot_select_another_userandtest_serialized_api_key_token_revalidates_bearer.test_api_key_disabled_rejects_explicit_authandtest_disabled_api_key_assertion_hides_tools.test_guest_reverification_observes_later_dashboard_revocationandtest_guest_reverification_backend_failure_is_credential_failure.Guest verification intentionally remains uncached at resolution time; each dashboard resource can require a metadata lookup.
UPDATING.mdand the MCP authentication table explain the custom-resolver migration toget_verifier_client_idand the disabled-key behavior.Siblings checked:
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (authentication resolution, no UI).
TESTING INSTRUCTIONS
Docker validation at 124b496, Python 3.11.17, with
SUPERSET_TESTENV=true, and manual/real-model checks excluded:Before/after proof:
test_multi_auth_client_id.pyagainst pre-PR sourceaabddf5b3fgave 42 failed / 3 passed. The changed API-key/guest auth files against that source gave 2 failed / 75 passed.Changed-file pre-commit checks passed, including mypy, ruff, and pylint. The earlier broad MCP run was interrupted after 1837 passes for the required master merge; it is not a completed full-suite result. No frontend changes; Jest was not run. Real-LLM checks were not run.
ADDITIONAL INFORMATION