Repository navigation
feat: add opt-in course-authoring filtering to authorization endpoints - #361
mariajgrimaldi wants to merge 9 commits into
Conversation
|
Thanks for the pull request, @mariajgrimaldi! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
7d9f971 to
1f1f1dd
Compare
|
This PR was meant to partially solve #340 & #341 by supporting the proposal made here openedx/frontend-app-admin-console#176 (comment) for the Verawood release - returning False for scopes based on the waffle flag state. But the approach still needs to address other dimensions, such as the performance and correctness of the entire framework, especially since these issues are release blockers and the modified endpoints are critical to the system's functionality. Internally, we discussed the best solution moving forward, given that we shouldn't introduce big changes that put the framework's correctness at risk, and went ahead with #358 and supporting filtering via the admin-console MFE. This will definitely introduce complexity to the MFE logic, which will be addressed in the next release cycle. |
- get_waffle_flag_states used a manual Flag query for the global tier instead of enable_authz_course_authoring, and returned flat booleans for org/course overrides instead of the actual affected orgs/courses, split by whether the override forces the flag on or off. - Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView, and an ADR documenting why this endpoint (issue #358) supersedes PR #361's approach of enforcing the flag cascade inside release-blocking endpoints. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- get_waffle_flag_states used a manual Flag query for the global tier instead of enable_authz_course_authoring, and returned flat booleans for org/course overrides instead of the actual affected orgs/courses, split by whether the override forces the flag on or off. - Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView, and an ADR documenting why this endpoint (issue #358) supersedes PR #361's approach of enforcing the flag cascade inside release-blocking endpoints. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- get_waffle_flag_states used a manual Flag query for the global tier instead of enable_authz_course_authoring, and returned flat booleans for org/course overrides instead of the actual affected orgs/courses, split by whether the override forces the flag on or off. - Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView, and an ADR documenting why this endpoint (issue openedx#358) supersedes PR openedx#361's approach of enforcing the flag cascade inside release-blocking endpoints. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* feat: add waffle flag states rest api and util * fix: address PR #358 review comments on get_waffle_flag_states - get_waffle_flag_states used a manual Flag query for the global tier instead of enable_authz_course_authoring, and returned flat booleans for org/course overrides instead of the actual affected orgs/courses, split by whether the override forces the flag on or off. - Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView, and an ADR documenting why this endpoint (issue #358) supersedes PR #361's approach of enforcing the flag cascade inside release-blocking endpoints. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix: rollback to use Flag instead of enable_authz_course_authoring, because that needs an argument * fix: quality tests * docs: bumpversion to 1.21.0 * docs: update the adr --------- Co-authored-by: Maria Grimaldi <maria.grimaldi@edunext.co> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…line ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…line ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…line ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… Filter Removes PR #361's is_scope_visible/has_visible_scope from rest_api/utils.py and replaces them with AuthorizationDataRequested (openedx_authz/filters.py), a domain-neutral Open edX Filter. PermissionValidationMeView, ScopesAPIView, AssignmentsAPIView, and TeamMemberAssignmentsAPIView call it directly; the actual course-authoring visibility logic lives in the isolated, opt-in CourseAuthoringVisibilityFilter pipeline step, disabled by default. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1f1f1dd to
ef87646
Compare
…line ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… Filter Removes PR #361's is_scope_visible/has_visible_scope from rest_api/utils.py and replaces them with AuthorizationDataRequested (openedx_authz/filters.py), a domain-neutral Open edX Filter. PermissionValidationMeView, ScopesAPIView, AssignmentsAPIView, and TeamMemberAssignmentsAPIView call it directly; the actual course-authoring visibility logic lives in the isolated, opt-in CourseAuthoringVisibilityFilter pipeline step, disabled by default. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ef87646 to
d6c08db
Compare
e2a8c4c to
bf76e58
Compare
|
Follow up comment for #361 (comment): This went through a full redesign since my comment above. Instead of hardcoding waffle flag checks in the endpoints, this now exposes three independent Open edX Filters ( The course-authoring visibility logic itself lives in a separate, opt-in pipeline step (see ADR 0017 for the filter contract and the boundary between shared authorization code and course-authoring policy). I manually tested it against a local install with the Postman collection attached to the description: permission validation, role assignment, and role removal all behave as documented for visible vs. hidden course scopes, including the partial |
BryanttV
left a comment
There was a problem hiding this comment.
Thanks @mariajgrimaldi! I tested it locally with the 3 filters configured and they work perfectly. I just have a few comments as suggestions.
| data, errors = RoleRemovalRequested.run_filter( | ||
| items=data | ||
| ) | ||
| completed = [] | ||
| for user_identifier in data["users"]: | ||
| response_dict = {"user_identifier": user_identifier} |
There was a problem hiding this comment.
I just noticed we're not including the scope here for some reason. Could we include it so it's consistent with the other responses?
| ValidationItem, | ||
| ) | ||
|
|
||
| SCOPE_NOT_AVAILABLE_ERROR = "scope_not_available" |
There was a problem hiding this comment.
Why aren't we including this new error in the RoleOperationError enum? Or is the idea to keep everything in one file so it's easier to remove later when the flag is dropped?
There was a problem hiding this comment.
Yes, because the main goal of this is not to modify or at least to reduce the amount of changes in the main files for when this is dropped.
| # enable_authz_course_authoring only accepts a course key, and there's no public | ||
| # edx-platform API to check an org alone, so this checks the org override directly | ||
| # (see issue #360 for follow-up) when asked to check an org-level course glob | ||
| org_override = WaffleFlagOrgOverrideModel.override_value(AUTHZ_COURSE_AUTHORING_FLAG.name, scope.org) | ||
| if org_override == WaffleFlagOrgOverrideModel.ALL_CHOICES.on: | ||
| return True | ||
| if org_override == WaffleFlagOrgOverrideModel.ALL_CHOICES.off: | ||
| return False |
There was a problem hiding this comment.
With the new function (is_enabled_for_org), we could simplify this, right?
There was a problem hiding this comment.
Yes! We can hold this off until that's merged
| """ | ||
| return { | ||
| scope | ||
| for scope in scopes |
There was a problem hiding this comment.
Would it make sense to remove the duplicated scopes here?
| for scope in scopes | |
| for scope in set(scopes) |
There was a problem hiding this comment.
I think not, because this is a filter, it ideally shouldn't change the data shape and ordering unless the change goes with whatever the filter is supposed to do.
…line ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* docs: add ADR 0016/0017 and update ADR 0015 with the deprecation timeline ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * docs: document the waffle-flag-states consumption contract in ADR 0015 Adds two consequences: callers must resolve their own scope against the raw override lists (course -> org -> global precedence), with frontend-app-admin-console's useCourseAuthoringFlag hook (PR #176) as the reference implementation, and the endpoint takes no client-supplied parameters, so CSRF doesn't apply since it's GET-only and IsAuthenticated is what actually gates access. * docs: correct and tighten the ADR 0015 CSRF/exposure note The concern isn't request forgery, this is a GET endpoint with no client-supplied parameters to forge. It's that the response isn't scoped per caller: any authenticated user gets every org/course override on the instance, with no additional permission check beyond IsAuthenticated. Also trims the Consequences and Addendum prose, which had grown longer than this repo's established ADR style (see docs/decisions/0012 and 0014 for reference). * docs: add ADR 0018 and revise ADR 0016 for cross-domain filtering ADR 0018 records the Open edX Filter mechanism: the shared AuthorizationDataRequested contract, the per-endpoint integration points, and the course-authoring pipeline step's location and opt-in nature. ADR 0016's decisions 3 and 4 are corrected to reflect that the pipeline step implementation lives in this repo, not in the calling application. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * docs: clarify authorization filtering ADR sequence * docs: narrow authorization filter scope * docs: define separate authorization filters for each operation * docs: remove actor bypass from authorization filters * docs: address PR reviews * docs: renumber domain ownership ADRs --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…line ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
5a2248c to
ae9dbf0
Compare
…line ADR 0016 records the domain-ownership audit of openedx_authz.rest_api: which endpoints are Authorization's own data, which is the one exception (WaffleFlagStatesAPIView), and why generic endpoints must not depend on another domain's concepts (the rationale PR #361 ran into). ADR 0017 names the package-layout convention the admin_console/ and course_authoring/ subpackages apply, so a future endpoint has a placement rule instead of a fresh discussion. ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual toggle_target_removal_date (2027-06-09) and upstream tracking issue for the flag, and the confirmed details of openedx-platform's own ToggleStateView as prior art for the rejected /api/toggles/v0/state/ alternative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds two consequences: callers must resolve their own scope against the raw override lists (course -> org -> global precedence), with frontend-app-admin-console's useCourseAuthoringFlag hook (PR #176) as the reference implementation, and the endpoint takes no client-supplied parameters, so CSRF doesn't apply since it's GET-only and IsAuthenticated is what actually gates access.
The concern isn't request forgery, this is a GET endpoint with no client-supplied parameters to forge. It's that the response isn't scoped per caller: any authenticated user gets every org/course override on the instance, with no additional permission check beyond IsAuthenticated. Also trims the Consequences and Addendum prose, which had grown longer than this repo's established ADR style (see docs/decisions/0012 and 0014 for reference).
ADR 0018 records the Open edX Filter mechanism: the shared AuthorizationDataRequested contract, the per-endpoint integration points, and the course-authoring pipeline step's location and opt-in nature. ADR 0016's decisions 3 and 4 are corrected to reflect that the pipeline step implementation lives in this repo, not in the calling application. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ae9dbf0 to
b1919b4
Compare
Description
This PR adds three public Open edX Filter hooks for authorization operations, together with optional course-authoring pipeline steps. When configured, the pipeline prevents stale Casbin assignments from approving or modifying a course scope whose effective
authz.enable_course_authoringflag is off. Without pipeline configuration, the endpoints keep their existing behavior.The filter contract and the boundary between shared authorization code and course-authoring policy are documented in ADR 0017.
The implementation has two parts:
PermissionValidationRequested,RoleAssignmentRequested, andRoleRemovalRequestedexpose independent hooks with payloads specific to each operation.PermissionValidationMeViewand thePUTandDELETEoperations inRoleUserAPIViewcall the corresponding filter.For
POST /validate/me/, a hidden course scope remains in the response withallowed: false. For role assignment and removal, the pipeline rejects hidden scopes before calling the write API and reportsscope_not_availablethrough the endpoint's existing207 Multi-Statusresponse. A multi-scopePUTcan complete operations for visible scopes while reporting rejected ones. Library scopes remain available.Configuration
Each operation is configured independently:
How to test
Register the three pipelines above, then use JWT-authenticated requests from a user with a Casbin assignment for a course whose course-authoring flag is off:
POST /api/authz/v1/validate/me/. Its result should containallowed: false. A library scope in the same request should retain its Casbin result.PUT /api/authz/v1/roles/users/. The response should be207 Multi-Status, with completed operations for visible scopes and ascope_not_availableerror for each rejected user and scope.DELETE /api/authz/v1/roles/users/. A hidden scope should producescope_not_availableerrors without performing the removals.The Postman collection includes the requests and JWT credential setup:
endpoints-flag-aware.postman_collection.json
Automated testing
Merge checklist: