Skip to content

Add default content guard auto-assignment for distributions within a domain - #7992

Open
dkliban wants to merge 1 commit into
pulp:mainfrom
dkliban:issue-7988/default-content-guard
Open

Add default content guard auto-assignment for distributions within a domain#7992
dkliban wants to merge 1 commit into
pulp:mainfrom
dkliban:issue-7988/default-content-guard

Conversation

@dkliban

@dkliban dkliban commented Aug 18, 2026

Copy link
Copy Markdown
Member

Summary

Adds a default_content_guard field to the Domain model. When a distribution is created within a domain that has a default_content_guard set and the distribution does not specify its own content guard, the domain's default is automatically assigned. To apply multiple guards by default, set a composite content guard as the domain's default_content_guard.

Changes

  • Domain.default_content_guard foreign key (nullable, on_delete=SET_NULL) + migration
  • Distribution BEFORE_CREATE hook auto-assigns the domain default when no guard is specified (an explicit content guard always wins)
  • DomainSerializer exposes the field (plus a _prn convenience field) and validates that the guard belongs to the same domain
  • DomainViewSet select_related to avoid N+1 on list

Tests

  • Unit: serializer validation (cross-domain rejected, rejected on create, same-domain accepted)
  • Functional (pulpcore): domain default_content_guard CRUD
  • Functional (pulp_file): end-to-end auto-assignment and explicit-guard-wins

Closes: #7988

🤖 Generated with Claude Code

@dralley

dralley commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Setting aside the precise implementation, is the goal actually to assign a default value for the content guard, or is it to protect content by default with a certain guard?

Those are slightly different things - in the latter case, maybe you would leave the default value on the distribution null, but null would be remapped to a globally default content guard implicitly.

The semantics are different, in the former case changing the default content guard wouldn't change any distributions, they would need to be updated manually, whereas in the latter case all distributions left in a default state would be remapped to a different content guard.

@dkliban

dkliban commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

@dralley you bring up a good question. explicitly setting the content guard on a distribution should make it easier to debug any issues when a user is having issues with accessing content.

Comment thread CHANGES/7988.feature Outdated
@dkliban

dkliban commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Fixed — switched to single backticks in the changelog entry.

@dkliban
dkliban force-pushed the issue-7988/default-content-guard branch from 25ea583 to 833adc2 Compare September 1, 2026 14:52
@dkliban
dkliban force-pushed the issue-7988/default-content-guard branch from 833adc2 to b7a0c47 Compare September 1, 2026 15:07
Comment thread docs/user/guides/protect-content.md
@dkliban
dkliban force-pushed the issue-7988/default-content-guard branch from b7a0c47 to 27faacb Compare September 1, 2026 15:25
redirect_to_object_storage = models.BooleanField(default=True)
hide_guarded_distributions = models.BooleanField(default=False)
default_content_guard = models.ForeignKey(
"ContentGuard", null=True, on_delete=models.SET_NULL, related_name="+"

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.

What is related_name="+"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

related_name="+" is Django's convention for suppressing the reverse accessor entirely. Without it, Django would create content_guard.domain_set (or similar) pointing back to domains — a second traversal path that would be unused and confusing since ContentGuard already has its own pulp_domain FK for that. The + keeps the FK without polluting the ContentGuard namespace with an accessor nobody would call.

Comment thread pulpcore/app/models/publication.py Outdated
Comment thread pulpcore/app/viewsets/domain.py Outdated
Comment thread pulpcore/tests/functional/api/test_crud_domains.py Outdated
Comment thread pulpcore/tests/unit/serializers/test_domain.py
@dkliban
dkliban force-pushed the issue-7988/default-content-guard branch from 27faacb to d482dd1 Compare September 1, 2026 17:48
@dralley

dralley commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@dkliban Formatting

@dkliban
dkliban force-pushed the issue-7988/default-content-guard branch from d482dd1 to ff4b8b0 Compare September 1, 2026 19:14
Adds a `default_content_guard` field to the Domain model. When a
distribution is created within a domain that has a
`default_content_guard` set and the distribution does not specify its
own content guard, the domain's default is automatically assigned. An
explicitly provided content guard always takes precedence.

Changes:
- Domain.default_content_guard FK (nullable, on_delete=SET_NULL) + migration
- Distribution BEFORE_CREATE hook auto-assigns the domain default
- DomainSerializer exposes the field with cross-domain validation
- DomainViewSet select_related to avoid N+1 on list

Closes: pulp#7988

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dkliban
dkliban force-pushed the issue-7988/default-content-guard branch from ff4b8b0 to 2d350c4 Compare September 1, 2026 19:35
@dkliban

dkliban commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Fixed the CI failure in . The domain deletion task was failing because ContentGuard.pulp_domain has on_delete=PROTECT — a domain with content guards in it cannot be deleted directly. The test creates a guard inside the domain, so the finally block now explicitly deletes the guard before deleting the domain. gen_object_with_cleanup still provides a backup safety net (it'll get a 404 on its cleanup attempt and handle it gracefully).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add default content guard auto-assignment for distributions within a domain

2 participants