Skip to content

PULP-2241: Create identity content guards for new domains - #1440

Open
decko wants to merge 4 commits into
pulp:mainfrom
decko:pulp-2241-default-content-guards
Open

PULP-2241: Create identity content guards for new domains#1440
decko wants to merge 4 commits into
pulp:mainfrom
decko:pulp-2241-default-content-guards

Conversation

@decko

@decko decko commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

Provision a domain-scoped identity content guard for newly created non-public domains.

The guard requires a valid base64-encoded JSON x-rh-identity header, but deliberately does not inspect its identity fields. Authenticity and entitlement remain the responsibility of the trusted Akamai/authentication path.

Changes

  • Require pulpcore==3.117.1 for Domain.default_content_guard.
  • Create a domain-local HeaderContentGuard from the domain post-save signal.
  • Assign it as the domain default for non-public domains.
  • Preserve explicit distribution-level content guards; existing distributions are unchanged.
  • Keep public-* domains anonymously readable.
  • Provision the guard within the existing domain creation transaction and cleanup path.
  • Update unit and functional tests for private/public domain behavior.

Scope and follow-up

This PR delivers the identity-guard/default-guard portion of PULP-2241/PULP-2242. VPN assertion validation and the identity/VPN composite remain deferred to PULP-2257 until the Akamai assertion contract is finalized. EnvVarHeaderContentGuard is intentionally not used.

Testing

  • Ruff check and format check pass for changed files.
  • Python compilation passes for changed files.
  • Functional tests require the Pulp development environment; they could not be collected locally because pulpcore is unavailable.

Jira

Refs: PULP-2241, PULP-2242, PULP-2257


Assisted-by: OpenCode [email protected]

Summary by Sourcery

Add automatic identity-based content protection for newly created non-public domains while keeping public domains anonymously readable.

New Features:

  • Provision a domain-scoped X-RH-IDENTITY content guard as the default for newly created non-public domains.

Bug Fixes:

  • Ensure newly created private-domain distributions deny unauthenticated access while preserving anonymous access for public domains.

Enhancements:

  • Preserve explicit distribution-level content guards and allow distributions without an effective guard to retain unrestricted SAFE_METHOD behavior.
  • Create default content guards transactionally alongside domain setup and clean up standalone domain creation failures.

Build:

  • Upgrade the pulpcore dependency to version 3.117.1.

Tests:

  • Add unit and functional coverage for private-domain identity guards, public-domain access, missing headers, and ignored identity payloads.

@sourcery-ai

sourcery-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The PR upgrades pulpcore and provisions a domain-scoped x-rh-identity HeaderContentGuard as the default for newly created non-public domains, integrated atomically with domain ownership setup and cleanup while preserving explicit distribution guards and anonymous access for public-* domains. Tests cover provisioning, header validation, payload-agnostic behavior, and updated private/public access expectations.

Sequence diagram for domain creation and content guard provisioning

sequenceDiagram
    participant Creator
    participant DomainSave
    participant PostSave as post_create_domain
    participant Guard as HeaderContentGuard
    participant Database

    Creator->>DomainSave: save()
    DomainSave->>PostSave: post_save(created=true)
    PostSave->>Database: transaction.atomic()
    PostSave->>Database: assign domain ownership and roles
    alt non-public domain
        PostSave->>Guard: objects.create(name, header_name, jq_filter, pulp_domain)
        Guard-->>PostSave: guard
        PostSave->>Database: save(default_content_guard=guard)
    else public-* domain
        PostSave-->>PostSave: skip guard provisioning
    end
    Database-->>Creator: committed domain and guard state
Loading

Flow diagram for domain content guard behavior

flowchart TD
    A[Request distribution content] --> B{Domain starts with public-?}
    B -->|Yes| C[Anonymous access remains allowed]
    B -->|No| D{Explicit distribution guard exists?}
    D -->|Yes| E[Use distribution guard]
    D -->|No| F[Use domain default HeaderContentGuard]
    F --> G{Valid base64 JSON x-rh-identity header?}
    G -->|Yes| H[Allow content access]
    G -->|No| I[Deny content access]
Loading

File-Level Changes

Change Details Files
Provision identity-header content guards as defaults for newly created non-public domains.
  • Create a domain-local HeaderContentGuard requiring a valid x-rh-identity header without inspecting identity fields.
  • Assign the guard through the domain default_content_guard field.
  • Skip provisioning for public-* domains and leave existing domains unchanged.
pulp_service/pulp_service/app/signals.py
pulp_service/CHANGES/2241.feature
Make guard provisioning part of domain creation consistency and preserve existing guard behavior.
  • Run guard creation with ownership and authorization setup in the existing atomic/cleanup path.
  • Retain explicit distribution-level content guards and existing distribution configuration.
pulp_service/pulp_service/app/signals.py
Upgrade pulpcore to support domain default content guards.
  • Pin pulpcore to version 3.117.1.
pulp_service/requirements.txt
Update coverage for private and public domain access semantics.
  • Add unit tests for guard provisioning, public-domain skipping, update behavior, missing headers, and ignored identity payloads.
  • Change functional tests to require authentication for new non-public distributions while preserving anonymous access for public domains.
pulp_service/pulp_service/tests/unit/test_signals.py
pulp_service/pulp_service/tests/functional/test_authentication.py
pulp_service/pulp_service/tests/functional/test_content_guard_permission.py

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

@decko
decko force-pushed the pulp-2241-default-content-guards branch from f2dd6e5 to e13689a Compare September 8, 2026 13:52
@decko
decko marked this pull request as ready for review September 8, 2026 14:02

@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/signals.py" line_range="60-67" />
<code_context>
+    if domain.name.startswith("public-"):
+        return
+
+    domain.default_content_guard = HeaderContentGuard.objects.create(
+        name="x-rh-identity",
+        header_name="x-rh-identity",
+        header_value="",
+        jq_filter='""',
+        pulp_domain=domain,
+    )
+    domain.save(update_fields=["default_content_guard"])
+
+
</code_context>
<issue_to_address>
**issue:** The new domain default guard makes a distribution with no explicit `content_guard` deny unauthenticated PyPI SAFE_METHOD requests on non-public domains, but `DomainBasedPermission._check_pypi_safe_method_access` still documents that distributions without a content guard allow all SAFE_METHOD access. That docstring now gives an incorrect contract to maintainers and API reviewers.

**Triggers:** When reading or relying on the `_check_pypi_safe_method_access` contract for distributions on newly created non-public domains.

**Suggested fix:** Update the permission docstring and related module-level test documentation to explain that an absent distribution guard can inherit the domain's default content guard.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and this changes the default access policy for every newly created non-public domain: requests with an X-RH-IDENTITY header are admitted while requests without it are denied, regardless of the identity payload. If that trust boundary is wrong, the policy is wrong for all such domains immediately, and reverting the code will not remove content guards already persisted on domains.

Blocking findings: pulp_service/pulp_service/app/signals.py:67


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

Comment thread pulp_service/pulp_service/app/signals.py
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.

1 participant