Skip to content

Prevent mixing cached and uploaded content in repositories - #50

Merged
aKlimau merged 1 commit into
pulp:mainfrom
aKlimau:mixed-content
Aug 31, 2026
Merged

Prevent mixing cached and uploaded content in repositories#50
aKlimau merged 1 commit into
pulp:mainfrom
aKlimau:mixed-content

Conversation

@aKlimau

@aKlimau aKlimau commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Prevent mixing cached and uploaded content in repositories.

When a distribution is created or updated, the serializer checks the repo's existing relationships - its own remote, and the remote/allow_uploads of any sibling distributions pointing at the same repo. If the operation results in mixing caching and uploads - it will be rejected.

Closes #28.

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

See: Pull Request Walkthrough

@aKlimau
aKlimau force-pushed the mixed-content branch 2 times, most recently from 65e9452 to 79b100b Compare August 4, 2026 12:21
@github-actions github-actions Bot removed the no-issue label Aug 4, 2026
@aKlimau

aKlimau commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

There is still a case were both uploaded and cached content can coexist in the same Repo, it can happen after a user decides to change repo_type value after the repo is already linked to a distributions.

Should repo_type field be immutable? This would cover such cases.

@aKlimau
aKlimau marked this pull request as draft August 4, 2026 12:33
@aKlimau
aKlimau marked this pull request as ready for review August 5, 2026 10:31
@dralley

dralley commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Should repo_type field be immutable? This would cover such cases.

I need to think about it and ask around to see if others have a similar use case. I had considered in the past that perhaps we could expose different types of repositories like this without two different models entirely, but I haven't thought through all of the implications. Probably this is the right choice for the first version of this feature though.

@aKlimau aKlimau changed the title Add repo_type field to enforce separation of cache and private reposi… Prevent mixing cached and uploaded content in repositories Aug 24, 2026
Comment thread pulp_rust/app/serializers.py Outdated
)

# A repository is the unit of exclusivity: it may be used for pull-through caching
# OR for uploads, but never both.

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.

Strange wording

# OR for uploads, but never both.
if repository:
repo = repository.cast()
sibling_distributions = models.RustDistribution.objects.filter(repository=repo)

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.

This seems fragile, at the very least the Distribution could probably be pointing to a repository version - "frozen" so to speak.

Which probably ought to also disable uploads?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But why would anyone try to upload something to a repository version? We are trying to prevent mixing of cached and uploaded content and uploading to a repo version doesn't lead to it.

I'm open to other solutions, but I don't see an issue with this one.

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.

They're not uploading to the repository version, they're uploading to the distribution, which has a repo version set. And it shouldn't work. I think right now (not under this PR, I haven't checked, but master branch) it would upload to the repository and make new versions even though the distribution & distributed content doesn't change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I understood the code correctly, uploading via cargo publish won't work if a distribution has repo_version set, since it relies on distro.repository having a value: https://github.com/pulp/pulp_rust/blob/main/pulp_rust/app/views.py#L347

And base distribution class doesn't allow for a distro to have both repo and repo_version set.
https://github.com/pulp/pulpcore/blob/main/pulpcore/app/serializers/publication.py#L315

Was that your concern or am I missing smt?

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.

I suppose that covers it, although it's not a very good error message for this specific case.

@dralley

dralley commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Go ahead and squash the commits

Comment thread pulp_rust/app/views.py Outdated
return self._error_response(
"This distribution serves a fixed repository version and cannot accept uploads.",
status=400,
)

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.

Factor this into a re-usable check. Actually the whole block possibly could be since the bottom line (353, 496, 543) is also basically the same in all cases.

Comment thread pulp_rust/app/views.py Outdated


def repository_write_error(distro):
"""Return a Cargo error response if the distribution can't be written to, else ``None``.

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.

ditch the double-backticks

Comment thread pulp_rust/app/views.py Outdated
"This distribution serves a fixed repository version and cannot be modified.",
status=400,
)
return _cargo_error("no repository associated with this distribution", status=404)

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.

Capitalize "No"

Comment thread pulp_rust/app/views.py Outdated
@@ -434,11 +449,7 @@ def get_permissions(self):

@staticmethod
def _error_response(detail, status=400):

@dralley dralley Aug 31, 2026

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.

Feels like _error_response can just be replaced by _cargo_error yes? Or just rename it in the first place, I don't see what is being added.

Closes pulp#28

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aKlimau
aKlimau merged commit 42fa3a4 into pulp:main Aug 31, 2026
13 of 14 checks passed
@aKlimau
aKlimau deleted the mixed-content branch August 31, 2026 15:08
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.

Enforce that private and public content cannot be mixed within a repository?

2 participants