-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add authz supporting subdomain module and ADR-0018 #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mariajgrimaldi
wants to merge
5
commits into
main
Choose a base branch
from
MJG/authz-audit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6796260
feat: add authz supporting subdomain module and ADR-0018
mariajgrimaldi b173f81
feat: add authz supporting subdomain module and ADR-0018
mariajgrimaldi f5a3cc4
feat: refine RoleAssignmentData with constrained operations and actor…
mariajgrimaldi 9887ef6
fix: simplify RoleAssignmentData and generate Avro schemas for authz …
mariajgrimaldi 5fdff5f
refactor: fix D213 docstring formatting in authz module
mariajgrimaldi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| .. _ADR-18: | ||
|
|
||
| 0018: Supporting Subdomain Modules for Cross-Domain Events | ||
| ########################################################## | ||
|
|
||
| Status | ||
| ****** | ||
|
|
||
| **Proposed** | ||
|
|
||
| Context | ||
| ******* | ||
|
|
||
| Events in ``openedx-events`` are organized into domain modules (e.g., ``learning``, | ||
| ``course_authoring``) following the Open edX architecture subdomains in | ||
| :ref:`Architecture Subdomains Reference`. This works well when an event belongs | ||
| to a single subdomain. | ||
|
|
||
| The `edX DDD Bounded Contexts`_ documentation classifies subdomains as core, | ||
| supporting, or generic. Supporting subdomains provide capabilities that multiple | ||
| core subdomains depend on, without belonging to any of them. ``analytics`` is the | ||
| existing example in ``openedx-events``. | ||
|
|
||
| Authorization has the same character: role assignment events originate from | ||
| ``openedx-authz`` and are consumed across learning, content authoring, enterprise, | ||
| and other areas. Its domain definition is independent of any single application, | ||
| so the ``authz`` module introduced in this ADR is classified as supporting. | ||
|
|
||
| Prior to this decision, there was no explicit guidance for supporting subdomain | ||
| events, leaving contributors to make ad-hoc placement choices. | ||
|
|
||
| Decision | ||
| ******** | ||
|
|
||
| We introduce dedicated top-level modules in ``openedx-events`` for supporting | ||
| subdomains when their events cannot be meaningfully attributed to a single | ||
| existing domain module. | ||
|
|
||
| A supporting subdomain module is warranted when: | ||
|
|
||
| * The subdomain provides a capability that multiple core subdomains depend on. | ||
| * The events are meaningful to consumers across existing domain modules without | ||
| a clear primary owner among them. | ||
| * Placing the events in any single existing domain module would reflect a | ||
| current implementation detail rather than a stable domain boundary. | ||
|
|
||
| The ``authz`` module introduced in this branch applies this pattern to | ||
| authorization events. The existing ``analytics`` module is recognized as a prior | ||
| instance of the same concept. | ||
|
|
||
| Consequences | ||
| ************ | ||
|
|
||
| 1. Supporting subdomain events have a principled home grounded in the Open edX | ||
| DDD taxonomy, rather than an arbitrary placement. | ||
| 2. The pattern is consistent with how ``analytics`` is already organized, and | ||
| both are now explicitly grounded in the same classification. | ||
| 3. Supporting subdomain modules can evolve independently of any single | ||
| application's release cycle. | ||
| 4. Deciding whether a concern qualifies as a supporting subdomain requires | ||
| judgment. Without discipline, this can lead to module proliferation. | ||
|
|
||
| Rejected Alternatives | ||
| ********************* | ||
|
|
||
| * **Place authorization events under ``course_authoring``**: role assignment is | ||
| currently performed through an admin console accessed via Studio, but that is | ||
| a transitional implementation detail. The admin console is planned to evolve | ||
| into its own application, and role assignment is semantically an authorization | ||
| concern, not a content authoring one. | ||
| * **Create a generic ``admin`` module**: authorization has a self-contained domain | ||
| definition that stands independently of any UI surface. "Admin" describes a user | ||
| role and an interface where tasks from multiple domains are aggregated - the | ||
| tasks themselves belong to their respective domains. | ||
| * **Extend an existing module with a subdirectory**: this would misrepresent the | ||
| domain ownership of the events and contradict the existing top-level module | ||
| structure. | ||
|
|
||
| References | ||
| ********** | ||
|
|
||
| - `edX DDD Bounded Contexts`_ | ||
| - :ref:`Architecture Subdomains Reference` | ||
|
|
||
| .. _edX DDD Bounded Contexts: https://openedx.atlassian.net/wiki/spaces/AC/pages/663224968/edX+DDD+Bounded+Contexts |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| """ | ||
| Package for events related to the Open edX authorization framework. | ||
|
|
||
| This package is not attached to a specific subdomain, as the events defined | ||
| here are used across multiple subdomains. | ||
| """ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """Data attributes for events related to the authorization framework.""" | ||
|
|
||
| import attr | ||
|
|
||
|
|
||
| @attr.s(frozen=True) | ||
| class RoleAssignmentData: | ||
| """ | ||
| Data related to a specific role assignment. | ||
|
|
||
| A role assignment represents the assignment of a role to a subject (e.g., user) | ||
| within a specific scope (e.g., course, organization). | ||
|
|
||
| Attributes: | ||
| operation (str): The operation being performed (e.g., 'created', 'deleted'). | ||
| subject (str): The subject to which the role is assigned (e.g., 'user^john_doe'). | ||
| role (str): The role that is assigned (e.g., 'course_admin'). | ||
| scope (str): The scope in which the role is assigned (e.g., 'course-v1:edX+DemoX+Demo_Course'). | ||
| actor (str): Username of the user performing the operation. | ||
| None if not known or not applicable (system-initiated actions). | ||
| """ | ||
|
|
||
| operation = attr.ib(type=str) | ||
| subject = attr.ib(type=str) | ||
| role = attr.ib(type=str) | ||
| scope = attr.ib(type=str) | ||
| actor = attr.ib(type=str, default=None) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """ | ||
| Standard Open edX events related to the Open edX authorization framework. | ||
|
|
||
| This module defines signals that are used to notify other parts of the system | ||
| about changes or actions related to authorization. | ||
| """ | ||
|
|
||
| from openedx_events.authz.data import RoleAssignmentData | ||
| from openedx_events.tooling import OpenEdxPublicSignal | ||
|
|
||
| # .. event_type: org.openedx.authz.role_assignment.created | ||
| # .. event_name: ROLE_ASSIGNMENT_CREATED | ||
| # .. event_key_field: user.pii.username | ||
| # .. event_description: Emitted when a role assignment is created in Open edX. | ||
| # .. event_data: RoleAssignmentData | ||
| # .. event_trigger_repository: openedx/openedx-authz | ||
| ROLE_ASSIGNMENT_CREATED = OpenEdxPublicSignal( | ||
| event_type="org.openedx.authz.role_assignment.created", | ||
| data={ | ||
| "role_assignment": RoleAssignmentData, | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| # .. event_type: org.openedx.authz.role_assignment.deleted | ||
| # .. event_name: ROLE_ASSIGNMENT_DELETED | ||
| # .. event_key_field: user.pii.username | ||
| # .. event_description: Emitted when a role assignment is deleted in Open edX. | ||
| # .. event_data: RoleAssignmentData | ||
| # .. event_trigger_repository: openedx/openedx-authz | ||
| ROLE_ASSIGNMENT_DELETED = OpenEdxPublicSignal( | ||
| event_type="org.openedx.authz.role_assignment.deleted", | ||
| data={ | ||
| "role_assignment": RoleAssignmentData, | ||
| } | ||
| ) |
41 changes: 41 additions & 0 deletions
41
...events/event_bus/avro/tests/schemas/org+openedx+authz+role_assignment+created_schema.avsc
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "name": "CloudEvent", | ||
| "type": "record", | ||
| "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", | ||
| "fields": [ | ||
| { | ||
| "name": "role_assignment", | ||
| "type": { | ||
| "name": "RoleAssignmentData", | ||
| "type": "record", | ||
| "fields": [ | ||
| { | ||
| "name": "operation", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "subject", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "role", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "scope", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "actor", | ||
| "type": [ | ||
| "null", | ||
| "string" | ||
| ], | ||
| "default": null | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "namespace": "org.openedx.authz.role_assignment.created" | ||
| } |
41 changes: 41 additions & 0 deletions
41
...events/event_bus/avro/tests/schemas/org+openedx+authz+role_assignment+deleted_schema.avsc
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "name": "CloudEvent", | ||
| "type": "record", | ||
| "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", | ||
| "fields": [ | ||
| { | ||
| "name": "role_assignment", | ||
| "type": { | ||
| "name": "RoleAssignmentData", | ||
| "type": "record", | ||
| "fields": [ | ||
| { | ||
| "name": "operation", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "subject", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "role", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "scope", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "name": "actor", | ||
| "type": [ | ||
| "null", | ||
| "string" | ||
| ], | ||
| "default": null | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "namespace": "org.openedx.authz.role_assignment.deleted" | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question, I’m not familiar with these events. Should we add a suffix like
_deletehere?