You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, openedx-authz only supports roles that apply to a single scope type (can only have permissions that apply to the same scope type).
This is not a restriction of Casbin, as Casbin itself is only aware of scope type associations at the permission level, not at the role level.
The restriction currently lives on higher levels, on the open-edx internal assumptions, the API layer, the frontend and the frontend interface flows design, as they were all designed with a single scope type per role in mind.
As part of the user research done for the Custom Roles feature, it was found that restricting a role to a single scope type is confusing for end users, as administrators may want to assign a single role to a user over an extended set of scopes, for example, a "Platform Manager" role may span permissions across both courses and libraries.
Preliminary research (needs confirmation and update with latest openedx-changes):
What it would take: roles that span more than one scope type
Research into whether openedx-authz can support a role that combines multiple scope types — e.g. a "General Manager" that can edit both courses and libraries within an org (or platform-wide).
TL;DR
There is no single "one role = one scope type" rule to remove. The constraint is emergent across a few cooperating layers. Supporting a multi-scope-type role is mostly additive: give the role permissions from both namespaces and have the compiler emit policy rows in both scope namespaces. Enforcement already handles it. The real friction is in the assignment model and the admin/REST layers, which assume one scope type per role/request.
Where the single-scope-type assumption actually lives
The data model already allows multi-scope roles — RoleDefinition.scopes is a tuple[str, ...] (engine/schema/types.py), and RoleData (api/data.py) has no scope field at all. What binds a role to one scope type today is:
YAML role definitions (authz/*.authz.yaml) declare single-element scope lists (scopes: [course-v1] or [lib]) and list permissions from only one namespace.
Casbin policy rows (engine/config/authz.policy) pin each role's permissions to a single namespace glob (lib^* vs course-v1^*). The matcher runs keyMatch(r.scope, p.scope), so a course-v1:… request can never match a lib^* row — that mismatch is why a role only works for its own scope type.
The compiler (engine/compiler.py) renders one p row per (role, permission, supported scope) by walking the role's scopes list.
Note: assign_role_to_subject_in_scope (api/roles.py) does not validate that a role matches the scope it's assigned into — assign a mismatch today and the row is created but silently grants nothing (the keyMatch fails). So nothing actively blocks a multi-scope role; the single-type behavior is purely emergent from the policy rows.
What would need to change
Role definition (easy). Declare both namespaces and permissions from both:
roles:
- id: general_managerdisplay_name: General Managerdescription: Manage both courses and libraries within a scope.scopes: [course-v1, lib]permissions:
- courses.edit_course_content
- courses.manage_course_updates
- content_libraries.edit_library_content
- content_libraries.manage_library_team
Mirror in constants/roles.py. RoleData needs no structural change.
Compiler / policy rendering. Verify PolicyRenderer.render iterates every entry in scopes and emits p rows per namespace (course rows in course-v1^*, library rows in lib^*), pairing each permission only with its own namespace — don't emit content_libraries.* against course-v1^*.
Enforcement — already works. The Casbin model (r = sub, act, scope, matcher with keyMatch) needs no changes. Once rows exist in both namespaces, a course request matches course rows and a library request matches library rows.
The real friction — assignment scope + admin/REST layers:
Assignment scope is single-namespace. A g assignment row carries one scope.namespaced_key (course-v1^…orlib^…, never both). So "General Manager on org DemoX for both" is either two assignments (one per namespace glob) or a new cross-cutting scope type.
Admin-console visibility is per-scope-type.ScopeData.get_admin_view_permission / get_admin_manage_permission are implemented per scope type; get_all_role_assignments_per_scope_type and filter_role_assignments_visible_to_subject filter via isinstance(scope, scope_types). This works because assignments stay per-type, but any UI grouping "roles available for this scope type" would now list general_manager under both.
engine/matcher.py has a hard-coded SCOPES_WITH_ADMIN_OR_SUPERUSER_CHECK set, and the REST layer (rest_api/v1/permissions.py — CoursePermission / ContentLibraryPermission — and ScopesTypeField in rest_api/data.py) assumes one scope type per request. These would need to recognize a role appearing across scope types.
The design decision
Two genuinely different readings of "General Manager on org DemoX":
Option A — one role, two assignments (per-namespace globs). Minimal change: role definition + compiler expansion only. Enforcement, assignment API, and audit all work unchanged. One role name grants both, but you assign it once per namespace.
Option B — one role, one cross-cutting assignment. Requires a new org/platform scope type whose namespace and keyMatch pattern match multiple resource namespaces at once (e.g. an org^DemoX scope matching both course-v1:DemoX+… and lib:DemoX:…). This is a much deeper change to the scope model, keyMatch semantics, and every per-scope-type filter.
Recommendation: Option A. It delivers the "General Manager" role with the least disruption and stays inside the existing Casbin model. Option B is only worth it if the product needs a single org-level grant that inherently covers all resource types — and that's a scope-model change, not a role change.
After community discussions, the team decided not to pursue multi-resource-type scopes at this point, further discussion is being done on a Groups feature that would solve the same problem in a potentially better way.
Activity
rodmgwgu commentedon Sep 25, 2026
Preliminary research (needs confirmation and update with latest openedx-changes):
What it would take: roles that span more than one scope type
Research into whether openedx-authz can support a role that combines multiple scope types — e.g. a "General Manager" that can edit both courses and libraries within an org (or platform-wide).
TL;DR
There is no single "one role = one scope type" rule to remove. The constraint is emergent across a few cooperating layers. Supporting a multi-scope-type role is mostly additive: give the role permissions from both namespaces and have the compiler emit policy rows in both scope namespaces. Enforcement already handles it. The real friction is in the assignment model and the admin/REST layers, which assume one scope type per role/request.
Where the single-scope-type assumption actually lives
The data model already allows multi-scope roles —
RoleDefinition.scopesis atuple[str, ...](engine/schema/types.py), andRoleData(api/data.py) has no scope field at all. What binds a role to one scope type today is:authz/*.authz.yaml) declare single-element scope lists (scopes: [course-v1]or[lib]) and list permissions from only one namespace.engine/config/authz.policy) pin each role's permissions to a single namespace glob (lib^*vscourse-v1^*). The matcher runskeyMatch(r.scope, p.scope), so acourse-v1:…request can never match alib^*row — that mismatch is why a role only works for its own scope type.engine/compiler.py) renders oneprow per (role, permission, supported scope) by walking the role'sscopeslist.Note:
assign_role_to_subject_in_scope(api/roles.py) does not validate that a role matches the scope it's assigned into — assign a mismatch today and the row is created but silently grants nothing (thekeyMatchfails). So nothing actively blocks a multi-scope role; the single-type behavior is purely emergent from the policy rows.What would need to change
Role definition (easy). Declare both namespaces and permissions from both:
Mirror in
constants/roles.py.RoleDataneeds no structural change.Compiler / policy rendering. Verify
PolicyRenderer.renderiterates every entry inscopesand emitsprows per namespace (course rows incourse-v1^*, library rows inlib^*), pairing each permission only with its own namespace — don't emitcontent_libraries.*againstcourse-v1^*.Enforcement — already works. The Casbin model (
r = sub, act, scope, matcher withkeyMatch) needs no changes. Once rows exist in both namespaces, a course request matches course rows and a library request matches library rows.The real friction — assignment scope + admin/REST layers:
gassignment row carries onescope.namespaced_key(course-v1^…orlib^…, never both). So "General Manager on org DemoX for both" is either two assignments (one per namespace glob) or a new cross-cutting scope type.ScopeData.get_admin_view_permission/get_admin_manage_permissionare implemented per scope type;get_all_role_assignments_per_scope_typeandfilter_role_assignments_visible_to_subjectfilter viaisinstance(scope, scope_types). This works because assignments stay per-type, but any UI grouping "roles available for this scope type" would now listgeneral_managerunder both.engine/matcher.pyhas a hard-codedSCOPES_WITH_ADMIN_OR_SUPERUSER_CHECKset, and the REST layer (rest_api/v1/permissions.py—CoursePermission/ContentLibraryPermission— andScopesTypeFieldinrest_api/data.py) assumes one scope type per request. These would need to recognize a role appearing across scope types.The design decision
Two genuinely different readings of "General Manager on org DemoX":
keyMatchpattern match multiple resource namespaces at once (e.g. anorg^DemoXscope matching bothcourse-v1:DemoX+…andlib:DemoX:…). This is a much deeper change to the scope model,keyMatchsemantics, and every per-scope-type filter.Recommendation: Option A. It delivers the "General Manager" role with the least disruption and stays inside the existing Casbin model. Option B is only worth it if the product needs a single org-level grant that inherently covers all resource types — and that's a scope-model change, not a role change.
rodmgwgu commentedon Oct 29, 2026
After community discussions, the team decided not to pursue multi-resource-type scopes at this point, further discussion is being done on a Groups feature that would solve the same problem in a potentially better way.