Repository navigation
RBAC-only with a non-empty scope for the MCP server #45673
Replies: 4 comments 2 replies
|
for context, here is my current fix implementing the first method (limiting the scopes to valid superset scopes) : def _get_token_scopes() -> set[str] | None:
"""Return the set of scopes on the current JWT access token, or None.
Returns None when there is no JWT context or the token carries no scopes,
so callers can fall back to RBAC-only behavior (back-compat for API-key and
scope-less JWT deployments). Returns a (possibly populated) set only when
the token explicitly advertises scopes.
"""
try:
from fastmcp.server.dependencies import get_access_token
except ImportError:
return None
try:
access_token = get_access_token()
except Exception: # noqa: BLE001 - fail closed on token-context errors
logger.exception("Unable to resolve MCP access-token scopes")
# ``None`` means that no scoped credential was presented and enables
# legacy RBAC-only behavior. An empty set instead makes every scope
# check fail, so an unexpected context error cannot erase restrictions
# carried by a credential.
return set()
if access_token is None:
return None
#--------------------------------
# MY MODIFICATIONS START HERE
#--------------------------------
scopes = getattr(access_token, "scopes", None)
# keep only scopes used by superset
valid_scopes = set(_METHOD_TO_REQUIRED_SCOPE.values())
valid_scopes_from_token = {str(s) for s in scopes if s in valid_scopes}
if not valid_scopes_from_token:
# Token present but no valid scopes advertised: do NOT enforce scope checks.
return None
return valid_scopes_from_token |
|
This is the scope check layered on top of RBAC in So there is a way to get this working without changing Superset: have the IdP put Which of the two PR shapes is preferred isn't stated in the code or docs, so that is a call for the maintainers. One consequence of the filtering approach worth noting: a token whose scopes are all unrecognised (or a mistyped |
|
The issue happens because Between the two PR approaches you suggested, filtering out non-Superset scopes by returning A cleaner, maintainer-aligned architecture consists of two parts:
# superset_config.py
MCP_IGNORED_SCOPES = {"openid", "profile", "email", "offline_access"}In
If your IdP allows custom scope mappings, the immediate solution without modifying Superset core is to configure the client scope mapping in your IdP to append |
|
Hello. |
Uh oh!
There was an error while loading. Please reload this page.
Bug description
Hello,
I Have set up RBAC for the MCP server, but I get errors on tools which declare no permissions (attached bellow).
I understand the problem comes from my Identity provider which does not accept an empty scope and that a token with a non-empty scope enable scope checks.
I'm able to bypass that problem by modifying the
_get_token_scopes()function insuperset/mcp_service/auth.pyand would like to propose a PR, but I'm not sure what would be preferred:The idea being that if the only scopes present in the token are discarded by the chosen criteria above, then _get_token_scopes() function return None disabling scope checks.
Would that be acceptable and if yes, what is the preferred solution ?
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.12
Node version
18 or greater
Browser
Firefox
Additional context
superset_config.pyerror in logs:
Checklist
All reactions