PULP-2241: Create identity content guards for new domains - #1440
Conversation
Reviewer's GuideThe 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 provisioningsequenceDiagram
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
Flow diagram for domain content guard behaviorflowchart 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]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Assisted-by: OpenCode <[email protected]>
Assisted-by: OpenCode <[email protected]>
f2dd6e5 to
e13689a
Compare
Assisted-by: OpenCode <[email protected]>
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/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
Assisted-by: OpenCode <[email protected]>
Summary
Provision a domain-scoped identity content guard for newly created non-public domains.
The guard requires a valid base64-encoded JSON
x-rh-identityheader, but deliberately does not inspect its identity fields. Authenticity and entitlement remain the responsibility of the trusted Akamai/authentication path.Changes
pulpcore==3.117.1forDomain.default_content_guard.HeaderContentGuardfrom the domain post-save signal.public-*domains anonymously readable.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.
EnvVarHeaderContentGuardis intentionally not used.Testing
pulpcoreis 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:
Bug Fixes:
Enhancements:
Build:
Tests: