-
Notifications
You must be signed in to change notification settings - Fork 4.3k
docs: add ADR for standardizing permissions usage #38187
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
taimoor-ahmed-1
wants to merge
1
commit into
openedx:docs/ADRs-axim_api_improvements
Choose a base branch
from
edly-io:docs/ADR-standardize_permission_class_usage
base: docs/ADRs-axim_api_improvements
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.
+113
−0
Open
Changes from all commits
Commits
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,113 @@ | ||
| Open edX ADR 002: Standardize Permission Classes Across APIs | ||
| ============================================================ | ||
|
|
||
| :Status: Proposed | ||
| :Date: 2026-03-18 | ||
| :Deciders: API Working Group | ||
| :Technical Story: Open edX REST API Standards - Permission standardization for security consistency | ||
|
|
||
| Context | ||
| ------- | ||
|
|
||
| Permissions are inconsistently applied across Open edX apps using custom decorators, inline role-based checks, and embedded authorization logic within views. This creates security gaps, makes it difficult for external systems to reliably determine access, and leads to duplicate authorization logic across multiple views. | ||
|
|
||
| Decision | ||
| -------- | ||
|
|
||
| We will standardize all Open edX REST APIs to use **DRF permission_classes** as the primary authorization mechanism. | ||
|
|
||
| Implementation requirements: | ||
|
|
||
| * Use DRF permission_classes for all authorization logic instead of custom decorators. | ||
| * Create reusable permission classes for common authorization patterns (course staff, global staff, etc.). | ||
| * Replace inline role-based checks with explicit permission classes. | ||
| * Ensure permission classes are properly documented and tested. | ||
| * Maintain consistent permission patterns across similar endpoint types. | ||
|
|
||
| Relevance in edx-platform | ||
| ------------------------- | ||
|
|
||
| Current patterns that should be migrated: | ||
|
|
||
| * **Enrollment API** (``/api/enrollment/v1/enrollment/{username},{course_id}``) uses custom inline role checks. | ||
| * **User Tours API** (``/api/user_tours/v1/{username}``) mixes inline checks and permission_classes. | ||
| * **Course orphan endpoints** (``^orphan/{settings.COURSE_KEY_PATTERN}$``) use functional views with inline permission logic. | ||
|
|
||
| Code example (target permission usage) | ||
| -------------------------------------- | ||
|
|
||
| **Example permission classes and APIView using DRF best practices:** | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # permissions.py | ||
| from rest_framework.permissions import BasePermission | ||
|
|
||
| class IsCourseStaff(BasePermission): | ||
| """ | ||
| Allows access only to course staff members. | ||
| """ | ||
| def has_permission(self, request, view): | ||
| return request.user.is_authenticated and request.user.is_staff | ||
|
|
||
| class IsEnrollmentOwnerOrStaff(BasePermission): | ||
| """ | ||
| Allows access to enrollment data for the user themselves or course staff. | ||
| """ | ||
| def has_object_permission(self, request, view, obj): | ||
| return ( | ||
| obj.user == request.user or | ||
| request.user.is_staff or | ||
| request.user.has_perm('course_staff', obj.course) | ||
| ) | ||
|
|
||
| # views.py | ||
| from rest_framework.views import APIView | ||
| from rest_framework.response import Response | ||
| from rest_framework.permissions import IsAuthenticated | ||
| from .permissions import IsCourseStaff | ||
|
|
||
| class EnrollmentAPIView(APIView): | ||
| permission_classes = [IsAuthenticated, IsCourseStaff] | ||
|
|
||
| def get(self, request): | ||
| return Response({"detail": "Access granted"}) | ||
|
|
||
| Consequences | ||
| ------------ | ||
|
|
||
| Positive | ||
| ~~~~~~~~ | ||
|
|
||
| * Improves security consistency across all APIs. | ||
| * Enhances predictability for external integrations. | ||
| * Ensures reusable, testable authorization logic. | ||
| * Simplifies security audits and permission reviews. | ||
| * Enables centralized permission management. | ||
|
|
||
| Negative / Trade-offs | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| * Requires refactoring existing views with inline permission logic. | ||
| * May need to create custom permission classes for complex authorization scenarios. | ||
| * Initial development effort to identify and standardize permission patterns. | ||
|
|
||
| Alternatives Considered | ||
| ----------------------- | ||
|
|
||
| * **Keep mixed permission approaches**: rejected due to security inconsistencies and maintenance burden. | ||
| * **Use only decorators**: rejected because DRF permission_classes provide better integration with the framework. | ||
|
|
||
| Rollout Plan | ||
| ------------ | ||
|
|
||
| 1. Audit existing endpoints to identify inconsistent permission patterns. | ||
| 2. Create a library of standard permission classes for common use cases. | ||
| 3. Migrate high-security endpoints first (enrollment, user data, course management). | ||
| 4. Add comprehensive tests for permission classes and their usage. | ||
| 5. Update API documentation to clearly specify permission requirements. | ||
|
|
||
| References | ||
| ---------- | ||
|
|
||
| * Open edX REST API Standards: "Permissions" recommendations for security consistency. | ||
Oops, something went wrong.
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.
Can we correct this ADR number? Or may be remove it.