Skip to content

fix(mcp): recognise guest tokens on FastMCP 4 - #45639

Merged
aminghadersohi merged 5 commits into
apache:masterfrom
aminghadersohi:fix-mcp-guest-client-id-fastmcp4
Oct 24, 2026
Merged

aminghadersohi merged 5 commits into
apache:masterfrom
aminghadersohi:fix-mcp-guest-client-id-fastmcp4

Conversation

@aminghadersohi

@aminghadersohi aminghadersohi commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

FastMCP 4's MultiAuth qualifies AccessToken.client_id, so comparing that field directly with guest or api_key loses 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, and test_default_user_resolver_uses_unqualified_client_id.
  • Raw guest-bearer re-verification, including required expiry, guest type, core structure, and revocation. GuestUser resources/RLS come from the decoded bearer, not mutable AccessToken claims. Regression: test_forged_guest_marker_cannot_pose_as_guest, test_guest_resolution_uses_verified_claims, test_guest_reverification_requires_core_structure, and test_guest_reverification_rejects_non_guest_type.
  • Removal of all three internal identity-routing claims from JWT-verified tokens, and a transport-validated API-key token type rather than trusting externally supplied username claims. Regression: test_idp_api_key_claims_cannot_select_another_user and test_serialized_api_key_token_revalidates_bearer.
  • Rejection of explicit API-key pass-through credentials when API keys are disabled, instead of falling through to another identity. Regression: test_api_key_disabled_rejects_explicit_auth and test_disabled_api_key_assertion_hides_tools.
  • Consistent discovery rejection for invalid guest credentials and revocation-backend errors. Regression: test_guest_reverification_observes_later_dashboard_revocation and test_guest_reverification_backend_failure_is_credential_failure.

Guest verification intentionally remains uncached at resolution time; each dashboard resource can require a metadata lookup. UPDATING.md and the MCP authentication table explain the custom-resolver migration to get_verifier_client_id and the disabled-key behavior.

Siblings checked:

  • superset/mcp_service/auth.py:599 — fixed in 272e4a6
  • superset/mcp_service/server.py:450 — fixed in 272e4a6
  • tests/unit_tests/mcp_service/test_multi_auth_client_id.py:56 — fixed in 272e4a6
  • superset/mcp_service/guest_token_verifier.py:74 — not affected: transport already rejects missing expiry, wrong type, and backend failures
  • superset/mcp_service/middleware.py:1282 — not affected: credential ValueError/PermissionError already hides all tools
  • superset/security/manager.py:6336 — not affected: per-dashboard revocation lookup semantics are reused unchanged
  • superset/mcp_service/mcp_config.py:961 — not affected: default resolver already uses the unqualification helper
  • superset/mcp_service/jwt_verifier.py:613 — not affected: produces client IDs before MultiAuth qualification rather than consuming wrapped IDs
  • superset/mcp_service/query/schemas.py:114 — not affected: query-correlation client_id is unrelated to authentication

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:

# FastMCP 4.1.2: 457 passed; PYTEST_XDIST_AUTO_NUM_WORKERS=2
pytest -n auto --dist loadfile --durations=0 --durations-min=0.5 \
  --cov-report= --cov=superset \
  tests/unit_tests/mcp_service/{test_auth_user_resolution,test_multi_auth_client_id,test_guest_token_auth,test_auth_api_key,test_mcp_multi_issuer_identity_binding,test_tool_search_transform,test_rbac_tool_enforcement,test_middleware}.py \
  --cache-clear --maxfail=10 \
  -m 'not manual and not llm_compliance and not testcontainers'

# FastMCP 4.1.2, exact order-dependence reproduction: 80 passed
pytest tests/unit_tests/mcp_service/test_auth_user_resolution.py \
  tests/unit_tests/mcp_service/test_multi_auth_client_id.py \
  -q -m 'not manual and not llm_compliance'

# FastMCP 3.4.7: 161 passed
pytest tests/unit_tests/mcp_service/{test_auth_user_resolution,test_multi_auth_client_id,test_guest_token_auth,test_auth_api_key,test_mcp_multi_issuer_identity_binding}.py \
  -q -m 'not manual and not llm_compliance'

Before/after proof:

  • On the previous review head, the two-file order gave 1 failed / 70 passed; missing-exp re-verification also failed its new assertion.
  • Removing the guest-type condition in a scratch source copy makes both new type cases fail.
  • Before the sibling discovery changes, the later-revocation search case and all three backend-failure cases failed.
  • Current test_multi_auth_client_id.py against pre-PR source aabddf5b3f gave 42 failed / 3 passed. The changed API-key/guest auth files against that source gave 2 failed / 75 passed.
  • The four documentation checks (upgrade helper, explicit rejection, empty discovery, resolver table) fail against the previous review head and pass with the documentation changes.

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

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (approval process: [SIP-59] Proposal for Database migration standards #13351 )
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

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

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.24%. Comparing base (472c3e4) to head (124b496).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/auth.py 90.47% 0 Missing and 2 partials ⚠️
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           
Flag Coverage Δ
hive 34.83% <13.51%> (-0.01%) ⬇️
mysql 52.86% <13.51%> (-0.01%) ⬇️
postgres 52.86% <13.51%> (-0.02%) ⬇️
presto 36.56% <13.51%> (-0.01%) ⬇️
python 87.41% <94.59%> (+<0.01%) ⬆️
sqlite 52.63% <13.51%> (-0.01%) ⬇️
unit 81.85% <94.59%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Oct 22, 2026
@netlify

netlify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 124b496
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6adbe0227c1ad8363eb1266f
😎 Deploy Preview https://deploy-preview-45639--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@aminghadersohi
aminghadersohi marked this pull request as ready for review October 23, 2026 16:36
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt PR Risk: Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 272e4a61c091

@gabotorresruiz gabotorresruiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread superset/mcp_service/auth.py Resolved
raise ValueError(
"Guest-marked token presented but embedded guest auth is not enabled"
)
guest_claims = _reverify_guest_bearer(access_token)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@aminghadersohi

Copy link
Copy Markdown
Contributor Author

@gabotorresruiz Thanks for the review. I followed up on all four inline asks in 272e4a6, retained at merge head 124b496:

  • Expiry/type coverage: required exp, added its structural parameter, and pinned non-guest types. test_guest_reverification_requires_core_structure[exp] failed before and passes after; removing the type condition makes both new test_guest_reverification_rejects_non_guest_type cases fail.
  • Repeated verification cost: I answered the question with the DAO/context-lifecycle evidence and documented the deliberate uncached freshness policy. test_guest_reverification_observes_later_dashboard_revocation checks a successful resolution followed by revocation across direct resolution and both discovery paths. Remaining: no per-request cache is introduced; I left that question open for your response.
  • Order dependence: moved the middleware import to module scope. The exact two-file order went from 1 failed/70 passed to 80 passed, including the new cases; the original failing regression is test_disabled_api_key_assertion_hides_tools[tool_list].
  • Upgrade guidance: added both behavior changes under UPDATING.md's Next and updated the resolver table. Four documentation assertions fail against the previous head and pass against this head. The runtime contracts are pinned by test_default_user_resolver_uses_unqualified_client_id, test_api_key_disabled_rejects_explicit_auth, and test_disabled_api_key_assertion_hides_tools.

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 test_guest_reverification_backend_failure_is_credential_failure cases failed before and pass after the changes.

Siblings checked:

  • superset/mcp_service/auth.py:599 — fixed in 272e4a6
  • superset/mcp_service/server.py:450 — fixed in 272e4a6
  • tests/unit_tests/mcp_service/test_multi_auth_client_id.py:56 — fixed in 272e4a6
  • UPDATING.md:26 — fixed in 272e4a6
  • docs/admin_docs/configuration/mcp-server.mdx:984 — fixed in 272e4a6
  • superset/mcp_service/guest_token_verifier.py:74 — not affected: transport already rejects missing expiry, wrong type, and verification/backend errors
  • superset/mcp_service/middleware.py:1282 — not affected: credential ValueError/PermissionError already hides all tools
  • superset/mcp_service/composite_token_verifier.py:266 — not affected: delegates guest transport admission; other sources are still checked at resolution
  • superset/security/manager.py:6336 — not affected: per-dashboard lookup semantics are unchanged and intentionally uncached
  • superset/mcp_service/worker.py:366 — not affected: production deferred import and worker-context lifecycle are unchanged
  • superset/mcp_service/mcp_config.py:961 — not affected: default resolver already uses the unqualification helper

@aminghadersohi
aminghadersohi merged commit e165c38 into apache:master Oct 24, 2026
74 checks passed
villebro added a commit that referenced this pull request Nov 2, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Namespace | Anything related to documentation size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants