Skip to content

Commit 7e6b25a

Browse files
sadpandajoerusackasclaude
authored
fix(row-level-security): allow roles as RLS rule subjects (apache#43948)
Co-authored-by: rusackas <evan@rusackas.com> Co-authored-by: Evan Rusackas <evan@preset.io> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent f7784b6 commit 7e6b25a

4 files changed

Lines changed: 58 additions & 23 deletions

File tree

‎UPDATING.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -958,14 +958,16 @@ become active dashboard Viewers after migration.
958958
API clients and automation should send and read `editors`, `viewers`, and `subjects` instead
959959
of the legacy fields.
960960

961-
Subject pickers support users, groups, and roles, but only users and groups are selectable by
962-
default. Roles remain supported as Subject types for backwards compatibility with RLS role
961+
Subject pickers support users, groups, and roles. Dashboard, chart, and alert/report pickers show
962+
only users and groups by default, while the RLS picker also shows roles to preserve role-based RLS
963+
workflows. Roles remain supported as Subject types for backwards compatibility with RLS role
963964
assignments and the previous `DASHBOARD_RBAC` model, but they are not recommended for new
964965
resource-specific assignments. Prefer groups for membership-based access and keep roles focused
965966
on capability grants. Existing Role subject assignments remain effective after migration even when
966-
Roles are hidden from the default dropdown values; configure the relevant `SUBJECTS_RELATED_TYPES_*`
967-
setting to make Roles selectable when editing subject lists. See the [Security documentation](docs/admin_docs/security/security.mdx#subjects)
968-
for the full Subject model and picker configuration guidance.
967+
Roles are hidden from a picker's dropdown values; configure the relevant
968+
`SUBJECTS_RELATED_TYPES_*` setting to make Roles selectable in non-RLS subject lists. See the
969+
[Security documentation](docs/admin_docs/security/security.mdx#subjects) for the full Subject model
970+
and picker configuration guidance.
969971

970972
To make roles selectable everywhere:
971973

@@ -979,15 +981,13 @@ SUBJECTS_RELATED_TYPES = [
979981
]
980982
```
981983

982-
To make roles selectable for RLS while other pickers keep the user and group default, use the
983-
RLS-specific override:
984+
The RLS picker includes users, roles, and groups by default. To customize it, use the RLS-specific
985+
override. For example, to show only roles:
984986

985987
```python
986988
from superset.subjects.types import SubjectType
987989

988990
SUBJECTS_RELATED_TYPES_RLS = [
989-
SubjectType.USER,
990-
SubjectType.GROUP,
991991
SubjectType.ROLE,
992992
]
993993
```

‎docs/admin_docs/security/security.mdx‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,19 @@ dashboards, charts, and datasets. Subjects come in three types:
143143

144144
Subjects are used throughout Superset to assign **editors** (who can modify a resource) and
145145
**viewers** (who can view it). For new resource-specific assignments, Superset defaults to
146-
**Users** and **Groups** in subject pickers. Groups are the recommended way to grant access to a
147-
set of people because they represent organizational membership, while roles remain focused on
148-
capability grants such as "can read dashboards" or "can write charts".
146+
**Users** and **Groups** in dashboard, chart, and alert/report subject pickers. The Row Level
147+
Security picker also includes **Roles** by default to preserve role-based RLS workflows. Groups
148+
are the recommended way to grant access to a set of people because they represent organizational
149+
membership, while roles remain focused on capability grants such as "can read dashboards" or
150+
"can write charts".
149151

150152
Role subjects are still supported for backwards compatibility with features that previously used
151153
roles directly, including Row Level Security role assignments and `DASHBOARD_RBAC`. Existing role
152154
subject assignments continue to be enforced even when roles are not exposed in the default picker
153-
configuration. However, when an administrator edits a subject list, roles are not available as new
154-
dropdown values unless that picker has been configured to expose role subjects. Roles are not
155-
recommended for new subject assignments, because using roles for both permissions and resource
156-
membership couples two separate concerns.
155+
configuration. The RLS picker exposes roles by default; other subject pickers do not expose roles
156+
as new dropdown values unless configured to do so. Roles are not recommended for new
157+
resource-specific assignments, because using roles for both permissions and resource membership
158+
couples two separate concerns.
157159

158160
Administrators can control which subject types are available in pickers with
159161
`SUBJECTS_RELATED_TYPES`. By default, this setting exposes only users and groups:
@@ -167,8 +169,10 @@ SUBJECTS_RELATED_TYPES = [
167169
]
168170
```
169171

170-
Set `SUBJECTS_RELATED_TYPES = None` to expose all subject types, including roles. To expose roles
171-
only for a specific entity, set that entity's override:
172+
Set `SUBJECTS_RELATED_TYPES = None` to expose all subject types globally, including roles.
173+
174+
The RLS picker has the following entity-specific default so role-based RLS rules remain
175+
selectable:
172176

173177
```python
174178
from superset.subjects.types import SubjectType
@@ -178,16 +182,16 @@ SUBJECTS_RELATED_TYPES = [
178182
SubjectType.GROUP,
179183
]
180184

181-
# Leave dashboard, chart, and alert/report overrides unset so they inherit
182-
# the users + groups default. Expose roles only in the RLS subject picker for
183-
# compatibility with existing role-based RLS workflows.
184185
SUBJECTS_RELATED_TYPES_RLS = [
185186
SubjectType.USER,
186-
SubjectType.GROUP,
187187
SubjectType.ROLE,
188+
SubjectType.GROUP,
188189
]
189190
```
190191

192+
Dashboard, chart, and alert/report overrides remain `None` by default and inherit the global
193+
users-and-groups setting. Set an entity-specific override explicitly to customize its picker.
194+
191195
Available per-entity overrides are:
192196

193197
- `SUBJECTS_RELATED_TYPES_DASHBOARDS` for dashboard editor/viewer pickers

‎superset/config.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3231,7 +3231,13 @@ class ExtraRelatedQueryFilters(TypedDict, total=False):
32313231
# None = inherit global behavior.
32323232
SUBJECTS_RELATED_TYPES_DASHBOARDS: list[SubjectType] | None = None
32333233
SUBJECTS_RELATED_TYPES_CHARTS: list[SubjectType] | None = None
3234-
SUBJECTS_RELATED_TYPES_RLS: list[SubjectType] | None = None
3234+
# Row level security rules are commonly scoped to a role, so the RLS rule
3235+
# editor's Subjects picker exposes roles in addition to the global default.
3236+
SUBJECTS_RELATED_TYPES_RLS: list[SubjectType] | None = [
3237+
SubjectType.USER,
3238+
SubjectType.ROLE,
3239+
SubjectType.GROUP,
3240+
]
32353241
SUBJECTS_RELATED_TYPES_ALERT_REPORTS: list[SubjectType] | None = None
32363242
SUBJECTS_RELATED_TYPES_THEMES: list[SubjectType] | None = None
32373243

‎tests/unit_tests/subjects/test_filters.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,31 @@ def test_subject_type_filter_config_default_user_and_group():
243243
assert SUBJECTS_RELATED_TYPES == [SubjectType.USER, SubjectType.GROUP]
244244

245245

246+
def test_subject_type_filter_rls_config_default_includes_role():
247+
"""The RLS rule editor's Subjects picker must offer roles by default.
248+
249+
Row level security rules are commonly scoped to a role rather than an
250+
individual user, so RLS should not silently inherit the global picker's
251+
exclusion of ROLE.
252+
"""
253+
from superset.config import SUBJECTS_RELATED_TYPES, SUBJECTS_RELATED_TYPES_RLS
254+
255+
assert SUBJECTS_RELATED_TYPES_RLS == [
256+
SubjectType.USER,
257+
SubjectType.ROLE,
258+
SubjectType.GROUP,
259+
]
260+
261+
query, result = _apply_subject_type_filter(
262+
global_types=SUBJECTS_RELATED_TYPES,
263+
entity_types=SUBJECTS_RELATED_TYPES_RLS,
264+
entity_key="SUBJECTS_RELATED_TYPES_RLS",
265+
)
266+
query.filter.assert_called_once()
267+
_assert_subject_type_filter_values(query, SUBJECTS_RELATED_TYPES_RLS)
268+
assert result is query.filter.return_value
269+
270+
246271
def test_subject_type_filter_global_only():
247272
"""Global set, entity None -> filters by global types."""
248273
query, result = _apply_subject_type_filter(

0 commit comments

Comments
 (0)