feat: introduce Subject model and entity editors/viewers#38831
Draft
villebro wants to merge 3 commits intoapache:masterfrom
Draft
feat: introduce Subject model and entity editors/viewers#38831villebro wants to merge 3 commits intoapache:masterfrom
villebro wants to merge 3 commits intoapache:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #38831 +/- ##
==========================================
+ Coverage 64.42% 64.50% +0.08%
==========================================
Files 2553 2558 +5
Lines 132588 132810 +222
Branches 30758 30638 -120
==========================================
+ Hits 85416 85668 +252
+ Misses 45686 45660 -26
+ Partials 1486 1482 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 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. |
9f26ac3 to
5ddcf81
Compare
5ddcf81 to
bd3f3e1
Compare
bd3f3e1 to
139eda3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
This PR introduces a new Subject model, which can represent either a User, Group or Role, and replaces the
ownersproperty on models with a neweditorsproperty. In addition, a new feature flagENABLE_VIEWERSis introduced, which makes it possible to expose dashboards or charts to explicit subjects, similarly to how theDASHBOARD_RBACfeature works. To complement this, a new config flagVIEWER_PROMISCUOUS_MODEis introduced (disabled by default), which makes it possible to bypass regular datasource RBAC, similar to howDASHBOARD_RBACpreviously worked.As the new
ENABLE_VIEWERSFF andVIEWER_PROMISCUOUS_MODEconfig flags are a superset ofDASHBOARD_RBAC,DASHBOARD_RBACis deprecated and set for removal in the next major version.To avoid introducing a breaking change, the
ownersproperty will be present on APIs, and will function as a partial and deprecated representation of theeditorsproperty. In the next major version, the owners property is completely removed.Motivation
The current access model ties ownership and edit permissions directly to individual users via the
ownersrelationship. TheDASHBOARD_RBACfeature flag added role-based dashboard access but as a separate, parallel system. This PR unifies both into a single model where editors (who can modify) and viewers (who can see) are expressed as subjects — any combination of users, roles, and groups.Data Model
A new
subjectstable stores unified references to FAB users, roles, and groups:labelsecondary_labeltypeuser_id/role_id/group_idJunction tables (
dashboard_editors,dashboard_viewers,chart_editors,chart_viewers,sqlatable_editors,report_schedule_editors) link subjects to resources.An explicit table is introduced to ensure maximum performance/minimal latency on related model queries, as they would otherwise need to query over a triple union covering user, role and group tables.
Legacy Table Removal
The migration drops the following legacy junction tables after seeding the new editor/viewer tables:
dashboard_userdashboard_editors(user-type)slice_userchart_editors(user-type)sqlatable_usersqlatable_editors(user-type)report_schedule_userreport_schedule_editors(user-type)dashboard_rolesdashboard_viewers(role-type)rls_filter_rolesrls_filter_subjects(role-type)On downgrade, all tables are recreated and repopulated from the editor/viewer/subject tables.
The
ownersandrolesproperties on models are now computed@propertymethods that derive their values fromeditorsandviewers/subjectsrespectively.Backwards Compatibility
ownersstill works: Settingownersin API payloads propagates intoeditors— existing integrations and scripts continue to function without changesDASHBOARD_RBACauto-migrates: When enabled, it setsENABLE_VIEWERS+VIEWER_PROMISCUOUS_MODEfor backwards compatibility. The flag is no longer referenced in frontend code.ownersare converted to user-type editor subjects;dashboard_rolesentries become viewer subjectsownersandeditors: Consumers can migrate at their own paceFeature Flags
ENABLE_VIEWERSNew config flags
VIEWER_PROMISCUOUS_MODEDASHBOARD_RBACbehavior)SUBJECTS_RELATED_TYPESSUBJECTS_RELATED_TYPES_DASHBOARDSSUBJECTS_RELATED_TYPES_CHARTSSUBJECTS_RELATED_TYPES_RLSSUBJECTS_RELATED_TYPES_ALERT_REPORTSEXTRA_RELATED_QUERY_FILTERSgroupkey alongside existinguserandrolekeys for custom group filtering, especially in multi-tenant deploymentsDocumentation
ExecutorType.OWNERrenders as the primary user-type editor (Role/Group editors aren't valid executors). This should also be renamed in the next major version.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
With this change, the dashboard, chart and dataset list views have Editors instead of Owners (notice the new
SubjectPilecomponent, that has a square avatar for Roles and hexagon for Groups):When the feature flag
ENABLE_VIEWERSis enabled, a Viewers column appears on Dashboard and Chart list views:The Editors and Viewers sections on the Access tab on the Properties modal. Notice the description for the optional Viewers section, which is similar to that which DASHBOARD_RBAC had:
The Subject dropdown features Users, Groups and Roles:
When a user has been granted access to a dashboard, either directly or indirectly via a Role or Group, and
VIEWER_PROMISCUOUS_MODEis not enabled, and they don't have dataset access, they will see this error:However, when
VIEWER_PROMISCUOUS_MODE = True, the dashboard renders correctly:As Row Level Security also now uses Subjects, you can now also assign filters to Users or Groups:
Similarly, Alerts & Reports also uses Subjects:
TESTING INSTRUCTIONS
superset db upgradeSELECT type, COUNT(*) FROM subjects GROUP BY type(should show users, roles, and groups)ENABLE_VIEWERSis on)ENABLE_VIEWERS→ Viewers dropdown appears; viewer-only users can see published dashboards but not editroles: [1, 2]→ verify the rule is created with role-type subjects; GET the rule → bothrolesandsubjectsappear in responseSUBJECTS_RELATED_TYPES = [1, 3]andSUBJECTS_RELATED_TYPES_RLS = [3]ADDITIONAL INFORMATION