Skip to content

Commit 2d3c516

Browse files
committed
Switch push created repo to ContainerRepository
https://redhat.atlassian.net/browse/PULP-1748 Assisted by: cursor composer 2
1 parent e42c6ef commit 2d3c516

18 files changed

Lines changed: 439 additions & 111 deletions

CHANGES/+default-push-repo.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed the default created repository on push to be a ContainerRepository instead of a ContainerPushRepository. ContainerPushRepository will eventually be phased out in future releases.

docs/admin/learn/rbac.md

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,15 @@ repository is public, then anyone can `pull` from the repository.
349349
Distributions are Pulp resources that represent URLs where repositories can be consumed.
350350
Permissions for accessing specific container repositories are described in terms of permissions
351351
to access Container Distributions. Each time a new repository is pushed using `podman` or `docker`,
352-
a Container Distribution is created. There is also a Container Push Repository created. Both of
353-
these resources can be accessed using Pulp's API.
352+
a Container Distribution and a Container Repository are created. Both resources can be accessed
353+
using Pulp's API. Registry-pushed repositories inherit distribution and namespace permissions for
354+
read and content-modifying API actions.
355+
356+
!!! note
357+
358+
Older versions of pulp-container created Container Push Repositories on docker pushes. Legacy
359+
pushes still remain available under `/pulp/api/v3/repositories/container/container-push/`, but
360+
will be migrated to Container Repositories in a future release.
354361

355362
The creation of a new distribution creates three user groups that can access the distribution:
356363
Owners, Collaborators, and Consumers. The user that creates the distribution is automatically added to
@@ -369,17 +376,10 @@ object permissions for the Distribution:
369376
"container.change_containerdistribution"
370377
```
371378

372-
The Owners group also has the following permissions for the Container Push Repository associated
373-
with the Distribution:
374-
375-
```
376-
"container.view_containerpushrepository"
377-
"container.modify_content_containerpushrepository"
378-
```
379-
380-
The owners of a Container Distribution have the ability to update and delete the repository
381-
associated with the Distribution. They can also add/remove users from the groups associated with
382-
the distribution.
379+
Distribution roles grant access to the linked Container Repository through the distribution and
380+
namespace permission checks described above. Distribution owners can update and delete the
381+
repository associated with the distribution. They can also add/remove users from the roles
382+
associated with the distribution.
383383

384384
#### Distribution Collaborators
385385

@@ -392,14 +392,6 @@ following object permissions for the Distribution:
392392
"container.push_containerdistribution"
393393
```
394394

395-
The Collaborators group also has the following permissions for the Container Push Repository associated
396-
with the Distribution:
397-
398-
```
399-
"container.view_containerpushrepository"
400-
"container.modify_content_containerpushrepository"
401-
```
402-
403395
Users in the Collaborator group can do everything that the owners can, with the exception for deleting
404396
the Distribution.
405397

@@ -413,14 +405,7 @@ object permissions for the distribution:
413405
"container.pull_containerdistribution"
414406
```
415407

416-
The Consumers group also has the following permissions for the Container Push Repository associated
417-
with the Distribution:
418-
419-
```
420-
"container.view_containerpushrepository"
421-
```
422-
423-
Users in the Consumers group can the `pull` the repository. Users should only need to be added to
408+
Users in the Consumers group can `pull` the repository. Users should only need to be added to
424409
this group if the Distribution has been configured with `private=True`. If the Distribution is
425410
public, then anyone can `pull` from the repository associated with the Distribution.
426411

@@ -484,8 +469,10 @@ permission on the Distribution:
484469
```
485470

486471
Users that wish to be able to access the repository associated with the distribution with Pulp's
487-
API need the following object level permission on the Container Push Repository:
472+
API need one of the following:
488473

489474
```
490-
"container.view_containerpushrepository"
475+
"container.view_containerrepository" (object-level repository role), or
476+
"container.view_containerdistribution" (distribution consumer role or above), or
477+
"container.namespace_view_containerdistribution" (namespace consumer role or above)
491478
```

pulp_container/app/authorization.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ def has_push_permissions(self, path):
295295
if not domain:
296296
return False
297297

298-
print("Checking push permissions for path ", path, "and domain ", domain.name)
299298
try:
300299
distribution = ContainerDistribution.objects.get(base_path=path, pulp_domain=domain)
301300
except ContainerDistribution.DoesNotExist:

pulp_container/app/global_access_conditions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ def has_namespace_obj_perms(request, view, action, permission):
2828
if type(obj) is models.ContainerDistribution:
2929
namespace = obj.namespace
3030
return request.user.has_perm(permission, namespace)
31-
elif type(obj) is models.ContainerPushRepository:
31+
elif type(obj) is models.ContainerPushRepository or type(obj) is models.ContainerRepository:
3232
for dist in obj.distributions.all():
33-
if request.user.has_perm(permission, dist.cast().namespace):
33+
namespace = dist.cast().namespace
34+
if namespace and request.user.has_perm(permission, namespace):
3435
return True
3536
elif type(obj) is models.ContainerPullThroughDistribution:
3637
namespace = obj.namespace

pulp_container/app/registry_api.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@
4545
from pulpcore.plugin import pulp_hashlib
4646
from pulpcore.plugin.exceptions import TimeoutException
4747
from pulpcore.plugin.files import PulpTemporaryUploadedFile
48-
from pulpcore.plugin.models import Artifact, ContentArtifact, RemoteArtifact, UploadChunk
48+
from pulpcore.plugin.models import (
49+
Artifact,
50+
ContentArtifact,
51+
RemoteArtifact,
52+
Repository,
53+
UploadChunk,
54+
)
4955
from pulpcore.plugin.tasking import dispatch
5056
from pulpcore.plugin.util import get_domain, get_objects_for_user, get_url
5157

@@ -436,11 +442,9 @@ def get_dr_push(self, request, path, create=False):
436442
repository = distribution.repository
437443
if repository:
438444
repository = repository.cast()
439-
if not repository.PUSH_ENABLED:
440-
raise RepositoryInvalid(name=path, message="Repository is read-only.")
441445
elif create:
442446
with transaction.atomic():
443-
repository = serializers.ContainerPushRepositorySerializer.get_or_create(
447+
repository = serializers.ContainerRepositorySerializer.get_or_create(
444448
{"name": path, "pulp_domain": domain}
445449
)
446450
distribution.repository = repository
@@ -451,11 +455,22 @@ def get_dr_push(self, request, path, create=False):
451455

452456
def create_dr(self, path, request):
453457
domain = get_domain()
458+
repository_types = [
459+
models.ContainerRepository.get_pulp_type(),
460+
models.ContainerPushRepository.get_pulp_type(),
461+
]
454462
with transaction.atomic():
455463
try:
456-
repository = serializers.ContainerPushRepositorySerializer.get_or_create(
457-
{"name": path, "pulp_domain": domain}
458-
)
464+
# Handle new default of ContainerRepository and fallback old ContainerPushRepository
465+
repository = Repository.objects.filter(name=path, pulp_domain=domain).first()
466+
if repository:
467+
if repository.pulp_type not in repository_types:
468+
raise RepositoryInvalid(name=path, message="Repository is read-only.")
469+
repository = repository.cast()
470+
else:
471+
repository = serializers.ContainerRepositorySerializer.get_or_create(
472+
{"name": path, "pulp_domain": domain}
473+
)
459474
distribution = serializers.ContainerDistributionSerializer.get_or_create(
460475
{"base_path": path, "name": path, "pulp_domain": domain},
461476
{"repository": get_url(repository)},
@@ -464,9 +479,10 @@ def create_dr(self, path, request):
464479
raise RepositoryInvalid(name=path, message="Repository is read-only.")
465480

466481
if distribution.repository:
467-
dist_repository = distribution.repository.cast()
468-
if not dist_repository.PUSH_ENABLED or repository != dist_repository:
469-
raise RepositoryInvalid(name=path, message="Repository is read-only.")
482+
if repository.pk != distribution.repository.pk:
483+
raise RepositoryInvalid(
484+
name=path, message="Repository is not available for push."
485+
)
470486
else:
471487
distribution.repository = repository
472488
distribution.save()

pulp_container/app/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class Meta:
250250
model = models.ContainerNamespace
251251

252252

253-
class ContainerRepositorySerializer(RepositorySerializer):
253+
class ContainerRepositorySerializer(RepositorySerializer, GetOrCreateSerializerMixin):
254254
"""
255255
Serializer for Container Repositories.
256256
"""

0 commit comments

Comments
 (0)