How Restrict Access to Embedded Dashboards on a Role-By-Role Basis #30420
Replies: 1 comment
-
I found a similar solved discussion that might help you: Is it possible to programmatically add users and roles in superset? [1]. Additionally, there are some related unsolved discussions and closed issues that might provide further insights:
To authorize embedded dashboards based on the role associated with the user logged into your app, you can modify the def request_loader(self, request: Request) -> Optional[User]:
# pylint: disable=import-outside-toplevel
from superset.extensions import feature_flag_manager
if feature_flag_manager.is_feature_enabled("EMBEDDED_SUPERSET"):
# Replace this with your app's user retrieval logic
user = self.get_user_from_app(request)
if user:
return user
return self.get_guest_user_from_request(request)
return None
def get_user_from_app(self, request: Request) -> Optional[User]:
# Implement your logic to retrieve the user based on your app's authentication
# For example, you might use a token in the request headers to identify the user
token = request.headers.get("Authorization")
if token:
# Validate the token and retrieve the user
user = validate_token_and_get_user(token)
return user
return None
def validate_token_and_get_user(token: str) -> Optional[User]:
# Implement your token validation and user retrieval logic here
# This is just a placeholder example
user_id = decode_token(token)
if user_id:
user = get_user_by_id(user_id)
return user
return None
def decode_token(token: str) -> Optional[int]:
# Decode the token and return the user ID
# This is just a placeholder example
try:
payload = jwt.decode(token, "your_secret_key", algorithms=["HS256"])
return payload.get("user_id")
except jwt.ExpiredSignatureError:
return None
except jwt.InvalidTokenError:
return None
def get_user_by_id(user_id: int) -> Optional[User]:
# Retrieve the user from the database by ID
# This is just a placeholder example
user = db.session.query(User).get(user_id)
return user In this example, the The default behavior of the |
Beta Was this translation helpful? Give feedback.
-
If I configure GUEST_ROLE_NAME = "Gamma" then Superset creates an anonymous user with the Gamma role for viewing embedded dashboards. But if I create a new user in Superset and assign it the Gamma role, this user can't see any dashboards. It seems the anonymous user can actually see any dashboard in the system that has been enabled for embedding (at least in the example database). Is this true?
There is a fundamental difference between anonymous Gamma users and logged-in Gamma users. This is confusing to me. It would be wonderful is someone could explain this.
I want to authorize embedded dashboards based on the Superset role associated to the user logged into my app where the dashboard is embedded. For example, every user in my app also has a corresponding user in Superset. A user can have one of three roles in Superset. Each role in Superset has access to a unique set of dashboards.
Then when I create an iframe in my app, I want to use the Superset role associated to the logged-in user in my app to embed the dashboard (not the GUEST_ROLE_NAME role every time). This way I can be certain users won't see data that doesn't belong to them.
How can I achieve this? Thank you!
Beta Was this translation helpful? Give feedback.
All reactions