GitHub user dosubot[bot] added a comment to the discussion: Best Way to Attach 
Dashboard RBAC Roles Automatically in Superset

<!-- Answer -->
You can't automate dashboard role assignment via `superset_config.py`—it's only 
for configuration, not for programmatic role or permission management. The best 
and most maintainable way to assign roles like "Gamma" to all dashboards is to 
use a backend Python script with the Superset app context and ORM. For example:

```python
from superset import create_app
from superset.models.dashboard import Dashboard
from flask_appbuilder.security.sqla.models import Role
from superset.extensions import db

app = create_app()
with app.app_context():
    gamma_role = db.session.query(Role).filter_by(name="Gamma").first()
    dashboards = db.session.query(Dashboard).all()
    for dash in dashboards:
        if gamma_role not in dash.roles:
            dash.roles.append(gamma_role)
    db.session.commit()
```

To assign a role to only specific dashboards, filter the dashboards in your 
script by slug, title, or owner before appending the role.

For future dashboards, there’s no built-in automatic assignment. You’d need to 
run a scheduled job or write a custom plugin/monkey-patch to hook into 
dashboard creation logic and assign the role programmatically.

If you’re on Superset 5.x+, you can also automate this via the REST API by 
enabling `FAB_ADD_SECURITY_API = True` in `superset_config.py` and using the 
dashboard API endpoints to set the `roles` field when creating or updating 
dashboards.

Direct SQL on the `dashboard_roles` table works but is not recommended—using 
the ORM or API is safer and more maintainable, as it respects application logic 
and future upgrades.

For more details and community examples, see [this 
discussion](https://github.com/apache/superset/discussions/34551) and [this 
thread](https://github.com/apache/superset/discussions/32368).


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/89cb3e8b-07d7-48fc-935d-5648d575318a?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/89cb3e8b-07d7-48fc-935d-5648d575318a?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/89cb3e8b-07d7-48fc-935d-5648d575318a?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/89cb3e8b-07d7-48fc-935d-5648d575318a?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/89cb3e8b-07d7-48fc-935d-5648d575318a?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/89cb3e8b-07d7-48fc-935d-5648d575318a?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/89cb3e8b-07d7-48fc-935d-5648d575318a?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat
 with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&
 nbsp;[![Join 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/35570)

GitHub link: 
https://github.com/apache/superset/discussions/35570#discussioncomment-14625185

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to