Repository navigation
Description
Description
_save_prefixes_txt crashes with MavenMetadata.DoesNotExist when two domains generate a prefixes.txt with identical content (same sha256). This makes modify_repo unusable on the second domain.
Root cause
MavenMetadata.sha256 has a global unique=True constraint (not scoped to _pulp_domain):
# pulp_maven/app/models.py
sha256 = models.CharField(max_length=64, null=False, unique=True, db_index=True)In _save_prefixes_txt, the save-or-get pattern assumes the IntegrityError came from the domain-scoped unique_together constraint, but it actually comes from the global sha256 uniqueness:
# pulp_maven/app/tasks/__init__.py, line ~83-103
metadata_content = MavenMetadata(
group_id="", artifact_id="", version=None,
filename=PREFIXES_TXT_FILENAME,
sha256=artifact.sha256,
_pulp_domain=pulp_domain,
)
try:
with transaction.atomic():
metadata_content.save()
except IntegrityError:
metadata_content = MavenMetadata.objects.get(
group_id="", artifact_id="", version=None,
filename=PREFIXES_TXT_FILENAME,
sha256=artifact.sha256,
_pulp_domain=pulp_domain, # <-- filters by THIS domain
)When domain A and domain B produce prefixes.txt with identical content:
- Domain A's
.save()succeeds — sha256 is new globally. - Domain B's
.save()raisesIntegrityError— sha256 already exists (from domain A). - Domain B's
.get()filters by_pulp_domain=B, but the record belongs to domain A →DoesNotExist.
The same pattern exists in _save_metadata_content (line ~518-529), which is vulnerable to the same bug for any metadata file that happens to have identical content across domains.
How to reproduce
- In a multi-domain Pulp instance, create a Maven repository in domain A.
- Upload a single artifact with
group_id="org.example"and callmodify_repoto add it. This succeeds and generates aprefixes.txtcontaining only/org/example. - In domain B, create a Maven repository and upload an artifact with the same
group_id="org.example". - Call
modify_repoon domain B → crashes withMavenMetadata matching query does not exist.
Traceback
File ".../pulpcore/app/tasks/repository.py", line 259, in add_and_remove
with repository.new_version(base_version=base_version) as new_version:
File ".../pulpcore/app/models/repository.py", line 1513, in __exit__
repository.finalize_new_version(self)
File ".../pulp_maven/app/models.py", line 639, in finalize_new_version
self._generate_metadata(new_version)
File ".../pulp_maven/app/models.py", line 1045, in _generate_metadata
prefixes_pks = _save_prefixes_txt(current_prefixes, self.pulp_domain)
File ".../pulp_maven/app/tasks/__init__.py", line 96, in _save_prefixes_txt
metadata_content = MavenMetadata.objects.get(
django.core.exceptions.ObjectDoesNotExist: MavenMetadata matching query does not exist.
Suggested fix
Either:
-
Scope the
sha256uniqueness to the domain — replace the globalunique=Trueon thesha256field with inclusion in theunique_togetherconstraint (which already includes_pulp_domain). -
Handle the cross-domain collision in the fallback — when the
IntegrityErroris from the globalsha256constraint, look up the existing record without thesha256filter and update it, or share the content record across domains.
Activity
fix: scope MavenMetadata sha256 uniqueness to domain
fix: scope MavenMetadata sha256 uniqueness to domain