feat: default to PulpServiceAccessPolicy for RBAC (PULP-2120) - #1452
feat: default to PulpServiceAccessPolicy for RBAC (PULP-2120)#1452CryptoRodeo wants to merge 1 commit into
Conversation
Reviewer's GuideThe PR switches the REST API from DomainBasedPermission to PulpServiceAccessPolicy/object-level RBAC, adds explicit authentication and domain authorization behavior for the special domain views, preserves dual-write context propagation, and updates functional coverage to use the supported self-service creation endpoint and RBAC response semantics. Sequence diagram for authenticated domain creation with dual-write contextsequenceDiagram
actor User
participant API as CreateDomainView
participant Context as authorization.py
participant Domain as Domain creation
participant Signal as post_create_domain
User->>API: POST /api/pulp/create-domain/
API->>API: IsAuthenticated
API->>Context: set_domain_create_context(request)
Context-->>API: org_id_var and user_id_var set
API->>Domain: create domain
Domain->>Signal: post_create_domain
Signal-->>Signal: dual-write using context vars
Domain-->>User: Domain response
Sequence diagram for RBAC-protected domain migrationsequenceDiagram
actor User
participant API as MigrateDomainView
participant Domain as Target domain
participant RBAC as User permissions
User->>API: POST migrate domain
API->>API: IsAuthenticated
API->>Domain: resolve target domain
alt Domain not viewable
Domain-->>API: Not found
API-->>User: 404
else Domain resolved
API->>RBAC: has_perm(core.change_domain, domain)
alt Permission granted
API-->>User: Migration response
else Permission denied
API-->>User: 403
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pulp_service/pulp_service/tests/functional/conftest.py" line_range="123-128" />
<code_context>
+ # the domain's distributions and repositories here first, else the domain delete task
+ # fails with ProtectedError and the domain leaks into later same-org list assertions.
+ try:
+ for api in (pulpcore_bindings.DistributionsApi, pulpcore_bindings.RepositoriesApi):
+ for obj in api.list(pulp_domain=name).results:
+ _delete_href(obj.pulp_href)
+ _delete_href(href)
+ except Exception:
+ pass
+
+
</code_context>
<issue_to_address>
**issue (testing):** The create_service_domain fixture catches every exception during cleanup and silently passes, so failed distribution/repository/domain deletions leave domains and content in the test stack while the tests still pass. Those leaked objects alter later list/count assertions and can make the functional suite order-dependent.
**Triggers:** When an asynchronous cleanup task fails, deletion returns an unexpected status, or a protected related object cannot be removed.
**Suggested fix:** Fail the fixture teardown or at least log and re-raise cleanup errors after attempting all created objects, rather than swallowing the exception.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and this changes the global API permission default and the authentication and object-level authorization decisions for domain creation and migration, so an incorrect policy could deny access or expose protected operations from the moment it ships. Reverting restores the prior checks, but requests processed under an overly permissive policy cannot be undone.
Blocking findings: pulp_service/pulp_service/tests/functional/conftest.py:128
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
d5860e7 to
68dd43c
Compare
Make `PulpServiceAccessPolicy` the default DRF permission class instead of `DomainBasedPermission`. The API is now governed by object-level RBAC (pulpcore's `AccessPolicyFromDB`) rather than the old org_id-match check. Changes - Config: flip PULP_REST_FRAMEWORK__DEFAULT_PERMISSION_CLASSES in clowdapp.yaml and dev-container/settings.py. - PyPIYankMonitorViewSet: drop its DomainBasedPermission override so it picks up the new default. - CreateDomainView / MigrateDomainView: switch to IsAuthenticated. DomainBasedPermission used to set the ContextVars the dual-write reads, so CreateDomainView now calls set_domain_create_context(request) instead. - MigrateDomainView also enforces core.change_domain directly now that it no longer gets domain scoping from DomainBasedPermission. - authorization.py: add set_domain_create_context(request), which pulls org_id/user_id from X-RH-IDENTITY for the dual-write. Heads up for callers - Non-admins can't create domains via the generic DomainsApi anymore (needs core.add_domain, else 403). Use POST /api/pulp/create-domain/. - Unviewable domains return 404, not 403. - Cross-org listing on non-PyPI endpoints returns an empty, scoped 200 instead of a 403 — no rows leak. Tests - Non-admin domain creation moved off DomainsApi onto a new create_service_domain fixture (test_authentication, test_group_based_permissions, test_domain_dual_write, test_content_guard_permission, test_domain_based_permissions). - test_authentication: accept 405 for PUT/DELETE/PATCH on the PyPI simple API — pulp_python's SimpleView only maps GET/POST, so the router 405s before any permission check. - test_content_guard_permission: cross-org non-PyPI listing now expects 200 + count == 0. - test_domain_dual_write: both DomainsApi tests drive the create-domain endpoint; the non-admin autocommit branch is now unreachable (covered by unit tests). Known regressions / out of scope - Lightwell readonly-group and subscription content-listing tests: that behavior is DomainBasedPermission-only and deliberately not ported. Expected. - Features-Service tests fail closed to 403 in a bare dev container — needs the real service, not a code regression. - test_content_view_search: blocked on missing client bindings + fixture from feature pulp#1439, unrelated to this change. Signed-off-by: Bryan Ramos <bramos@redhat.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
68dd43c to
6aacabc
Compare
Make
PulpServiceAccessPolicythe default DRF permission class instead ofDomainBasedPermission. The API is now governed by object-level RBAC (pulpcore'sAccessPolicyFromDB) rather than the old org_id-match check.Changes
Heads up for callers
Tests
Known regressions / out of scope
Summary by Sourcery
Adopt PulpServiceAccessPolicy as the default API authorization model and align domain operations and coverage with object-level RBAC.
New Features:
Bug Fixes:
Enhancements:
Tests:
Chores: