Skip to content

Support more than one scope type per role #466

Closed as not planned
Closed as not planned

Description

@rodmgwgu

As part of the Custom Roles implementation proposal, a role must support having permissions that apply to different scope types.

Reference: https://docs.google.com/document/d/1L-NBgsUgtj1o6JQswkXeyRbPEcFvZ0kp/edit

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.

Activity

  1. rodmgwgu commented on Sep 25, 2026

    @rodmgwgu
    ContributorAuthor

    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:

    1. YAML role definitions (authz/*.authz.yaml) declare single-element scope lists (scopes: [course-v1] or [lib]) and list permissions from only one namespace.
    2. 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.
    3. 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

    1. Role definition (easy). Declare both namespaces and permissions from both:

      roles:
        - id: general_manager
          display_name: General Manager
          description: 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.

    2. 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^*.

    3. 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.

    4. The real friction — assignment scope + admin/REST layers:

      • Assignment scope is single-namespace. A g assignment row carries one scope.namespaced_key (course-v1^… or lib^…, 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.

  2. rodmgwgu commented on Oct 29, 2026

    @rodmgwgu
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions