Skip to content

Let domain members view all content via core.view_content - #1465

Merged
dkliban merged 1 commit into
pulp:mainfrom
CryptoRodeo:feat/rbac-content-view-access-policy
Sep 11, 2026
Merged

Let domain members view all content via core.view_content#1465
dkliban merged 1 commit into
pulp:mainfrom
CryptoRodeo:feat/rbac-content-view-access-policy

Conversation

@CryptoRodeo

@CryptoRodeo CryptoRodeo commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Under RBAC, content is scoped by repository membership, so content a user pushed but hasn't added to a repo (orphan content) is invisible to them, read-after-push 404s.

Add an access-policy override so that, for any content viewset, list/retrieve is gated on the domain-scoped core.view_content permission (already granted to domain roles) and repository-based queryset scoping is dropped. A domain member can then see all content in their domain. Write statements and creation_hooks are preserved, so uploads are unaffected, and keying on BaseContentViewSet covers every content type in one place.

The change is staged: DomainBasedPermission is still the default permission class, so this only takes effect once RBAC is re-enabled.

Summary by Sourcery

Enable domain-scoped content visibility through RBAC while preserving existing write and staged-permission behavior.

New Features:

  • Allow domain members with the domain-scoped core.view_content permission to list all content in their domain, including orphan content.

Bug Fixes:

  • Restore read-after-push visibility for content that is not associated with a repository.

Enhancements:

  • Adopt settings-based access policies so the content viewset can bypass repository-based queryset scoping while preserving existing write behavior.

Tests:

  • Add coverage for the settings-based access-policy inheritance and content access-policy configuration.

@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The PR adds a centralized access-policy overlay for all BaseContentViewSet subclasses: list and retrieve are gated by domain-scoped core.view_content and repository queryset scoping is removed, while writes, creation hooks, wildcard grants, non-content policies, and the original policy remain intact. The behavior is configured and tested but only activates when the RBAC permission class is enabled.

Sequence diagram for RBAC content visibility

sequenceDiagram
    participant Client
    participant ContentViewSet as BaseContentViewSet
    participant Policy as PulpServiceAccessPolicy
    participant Settings as ACCESS_POLICIES
    participant Domain as DomainPermissions

    Client->>ContentViewSet: list or retrieve
    ContentViewSet->>Policy: get_access_policy(view)
    Policy->>Settings: read ACCESS_POLICIES[content]
    Policy-->>ContentViewSet: read policy with queryset_scoping=None
    ContentViewSet->>Domain: has_domain_perms:core.view_content
    alt permission granted
        Domain-->>ContentViewSet: allow
        ContentViewSet-->>Client: all content in domain
    else permission denied
        Domain-->>ContentViewSet: deny
        ContentViewSet-->>Client: 403
    end
Loading

File-Level Changes

Change Details Files
Overlay a domain-scoped read policy on every content viewset while retaining write behavior.
  • Detect BaseContentViewSet instances centrally in get_access_policy.
  • Replace allow statements for list/retrieve with a core.view_content domain-permission gate.
  • Remove repository queryset scoping for content reads.
  • Preserve non-read statements, wildcard grants, creation hooks, and policy immutability.
pulp_service/pulp_service/app/access_policy.py
Define the shared content access policy used by the override.
  • Gate list and retrieve for authenticated domain members with core.view_content.
  • Disable repository-based queryset scoping for content.
  • Document that behavior is inert until RBAC is active.
pulp_service/pulp_service/app/settings.py
Add focused tests covering content policy merging and passthrough behavior.
  • Verify policy configuration and domain-scoped read gating.
  • Verify repository scoping is removed while create permissions and creation hooks remain.
  • Verify the source policy is not mutated and non-content views pass through unchanged.
pulp_service/pulp_service/tests/functional/test_access_policy.py
Document restored domain-wide content visibility under RBAC.
  • Describe orphan-content visibility and read-after-push behavior.
  • Clarify that writes are unaffected and the change is inactive until RBAC is re-enabled.
CHANGES/rbac-content-view-access-policy.feature

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CryptoRodeo
CryptoRodeo marked this pull request as ready for review September 11, 2026 15:30

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/app/access_policy.py" line_range="82-99" />
<code_context>
+        read_actions = {"list", "retrieve"}
+        merged = deepcopy(policy)
+
+        kept_statements = []
+        for statement in merged.get("statements", []):
+            if statement.get("effect") != "allow":
+                kept_statements.append(statement)
+                continue
+            action = statement.get("action")
</code_context>
<issue_to_address>
**issue (broader_impact):** The merge removes every non-wildcard `allow` statement containing `list` or `retrieve`, then appends a single content read statement; this discards existing read grants with distinct conditions such as object-level permissions, role-specific principals, or special content access rules rather than preserving them. Users who previously qualified through those grants lose access unless they also have the domain-scoped `core.view_content` permission.

**Triggers:** When a content viewset has an existing list/retrieve allow statement whose access condition is broader or different from `has_domain_perms:core.view_content`.

**Suggested fix:** Preserve existing read grants that must remain valid, or explicitly combine the new domain permission with the existing read conditions instead of deleting them.

```suggestion
        kept_statements = merged.get("statements", [])
```
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and when RBAC is active, this changes the authorization policy for every content viewset: a domain member with core.view_content can list and retrieve all content in the domain, without repository scoping. Reverting would stop future access but could not undo content already exposed, and the access decision is wrong for everyone immediately if the policy is wrong.

Blocking findings: pulp_service/pulp_service/app/access_policy.py:99


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pulp_service/pulp_service/app/access_policy.py Outdated
@CryptoRodeo
CryptoRodeo force-pushed the feat/rbac-content-view-access-policy branch from 0380d8a to 68ca218 Compare September 11, 2026 15:53
Under RBAC, content is scoped by repository membership, so content a user
pushed but hasn't added to a repo (orphan content) is invisible to them --
read-after-push 404s on the list-all content endpoint.

Make PulpServiceAccessPolicy inherit from pulpcore's AccessPolicyFromSettings
so each viewset's policy is read from settings.ACCESS_POLICIES[<urlpattern>]
(falling back to the viewset's DEFAULT_ACCESS_POLICY) instead of the DB. The
"content" entry overrides pulpcore's ListContentViewSet to gate the list
action on the domain-scoped core.view_content permission and drop
repository-based queryset scoping, so a domain member can list all content in
their domain. This replaces the earlier custom get_access_policy override with
configuration only.

The change is staged: DomainBasedPermission is still the default permission
class, so this only takes effect once RBAC is re-enabled.

Signed-off-by: Bryan ramos <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
@CryptoRodeo
CryptoRodeo force-pushed the feat/rbac-content-view-access-policy branch from 68ca218 to 68e0700 Compare September 11, 2026 16:38
@dkliban
dkliban merged commit 9fba2a9 into pulp:main Sep 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants