Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulp container RBAC #705

Merged

Conversation

newswangerd
Copy link
Member

@newswangerd newswangerd commented Mar 29, 2021

UI PR for container model permissions: ansible/ansible-hub-ui#335

Changes

pulp_container access policies

  • Allow anyone to create a container namespace. This simplifies the new repo creation process by only requiring that the user have create_containerdistribution permissions to create a new container repo.
  • Require authentication for pulling containers
  • Remove group creation. The user that creates the repository is added as an owner on the repository's namespace instead of creating a new group for the user.

Groups

Filtering pulp container groups turned out to be a real challenge, so I've opted to remove the pulp container groups entirely.

Container Repo endpoint

  • Removed groups since permissions will be set at the namespace level
  • Added a my_perms filter that allows querying repos based on permissions that the user has. Ex: ?my_perms=namespace_push_containerdistribution returns all repos that the current user has push permissions on.
  • Updated with the following fields
    • my_permissions: returns the permissions my user has on the namespace object. Used for the UI to toggle edit buttons.
    • owners: list of users who have permissions on the object outside of the assigned groups. This shows who created and owns the namespace.
            "namespace": {
                "name": "a",
                "my_permissions": [
                    "namespace_modify_content_containerpushrepository",
                    "namespace_add_containerdistribution",
                    "namespace_pull_containerdistribution",
                    "view_containernamespace",
                    "namespace_delete_containerdistribution",
                    "change_containernamespace",
                    "namespace_view_containerdistribution",
                    "namespace_push_containerdistribution",
                    "namespace_change_containerdistribution",
                    "delete_containernamespace",
                    "namespace_view_containerpushrepository"
                ],
                "owners": [
                    "test"
                ]
            },

Additions

Container namespace endpoint

Add /api/automation-hub/_ui/v1/execution-environments/namespaces/ endpoint which allows viewing and updating permissions on container namespaces.

Permissions for containers can be set at two levels: container distributions and container namespaces. Namespaces grant a user access to all containers in a namespace.

We are only going to allow users to set permissions at the namespace level for the following reasons:

  • Simplicity: setting permissions on the container distribution level is more complicated because some permissions have to be set on the distribution and others have to be set on the container push repository, which would require extra api calls.
  • Consistency: permissions are set at a namespace level for collections, so it makes sense from a UX perspective to do the same
  • Predictability: only setting permissions at the repo level will lead to confusing situations where a user might think they have permissions on a namespace when they don't.

@newswangerd newswangerd changed the title Pulp container RBAC [WIP] Pulp container RBAC Mar 29, 2021
@newswangerd newswangerd force-pushed the feature/AAH-278-pulp-container-rbac branch from 48c1885 to f84a6ba Compare March 30, 2021 20:17
@newswangerd newswangerd changed the title [WIP] Pulp container RBAC Pulp container RBAC Mar 30, 2021
@newswangerd newswangerd force-pushed the feature/AAH-278-pulp-container-rbac branch 2 times, most recently from f950960 to a37ee63 Compare March 30, 2021 20:57
path(
"namespaces/<str:name>/",
viewsets.ContainerNamespaceViewSet.as_view({'get': 'retrieve', 'put': 'update'}),
name='container-repository-list'),
Copy link
Contributor

Choose a reason for hiding this comment

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

container-repository-detail?

path(
"namespaces/",
viewsets.ContainerNamespaceViewSet.as_view({'get': 'list'}),
name='container-repository-list'),
Copy link
Contributor

Choose a reason for hiding this comment

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

container-namespace-list ?

@@ -73,6 +88,10 @@ def get_pulp(self, distro):
}
}

def get_owners(self, distro):
name = f'container.distribution.owners.{distro.pulp_id}'
return [user.username for user in models.User.objects.filter(groups__name=name)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Would something like

return models.User.objects.filter(groups__name=name).values_list('username', flat=True)

Work here? Not sure if it matters on a small object like User

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, this function should be removed. I must have missed that.

Copy link
Contributor

@alikins alikins left a comment

Choose a reason for hiding this comment

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

One or two requested changes (or really, verifications). Most of the rest are vague suggestions you can take or leave.

galaxy_ng/app/access_control/fields.py Show resolved Hide resolved
galaxy_ng/app/api/ui/viewsets/execution_environment.py Outdated Show resolved Hide resolved
@@ -36,6 +40,12 @@ class Meta:
'description': ['exact', 'icontains', 'contains', 'startswith'],
}

def has_permissions(self, queryset, name, value):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe 'get_permissions'? has_permissions implies a boolean response to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Though, I guess it is returning a queryset of ContainerNamepaces, so 'get_permissions' doesn't seem right either...

Copy link
Member Author

Choose a reason for hiding this comment

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

would with_permissions make more sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the django_filter docs tend to name them 'filter_whatever' (https://django-filter.readthedocs.io/en/master/ref/filters.html#method).

'filter_by_permission' ? 'filter_accesible_namespaces' ?

Your call ;->

galaxy_ng/app/api/ui/viewsets/group.py Outdated Show resolved Hide resolved
galaxy_ng/app/models/container.py Show resolved Hide resolved
Copy link
Contributor

@alikins alikins left a comment

Choose a reason for hiding this comment

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

LGTM

@mdellweg
Copy link

mdellweg commented Apr 1, 2021

I was asked to take a look at this and as far as i understood, almost everything looks sane to me. Especially the changes to the access_policy.
However a warning is in order: Running pulpcore-manager flush will remove the access policies and still prevent this migration to run. That is the reason, why we decided to switch creating them to a post-migrate signal.

viewsets = {
# Note. This is the default Pulp Continer access policy with some modifications.
# Our changes have been marked with comments.
"distributions/container/container": {
Copy link

Choose a reason for hiding this comment

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

The policy for container-push repos is omitted here (tag/untag/remove image) - this will be added later whenever image management will be enabled, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ipanova are there things in the container push repo access policies that we should change? it looked like the defaults would work to me.

Copy link

Choose a reason for hiding this comment

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

clarified on the irc, resolved.

],
},
{
"action": ["pull"],
Copy link

Choose a reason for hiding this comment

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

there are 2 policies for pull operation - should you want to distinguish rules between private and public repo - it makes sense to keep this as it is proposed, otherwise it could be consolidated into one rule where the authentication is required regardless of the private/public repo type

{
                "action": ["pull"],
                "principal": "authenticated",
                "effect": "allow",
            },

Issue: AAH-278
- Add my permissions to repos and namespaces
- Add my_permissions filter to repo list view.
- Fix access policies.

Issue: AAH-278
@newswangerd newswangerd force-pushed the feature/AAH-278-pulp-container-rbac branch from 3cd2dfe to fbdfe81 Compare April 9, 2021 13:40
@newswangerd newswangerd force-pushed the feature/AAH-278-pulp-container-rbac branch from 0190aaa to 2ea72a3 Compare April 9, 2021 17:50
@newswangerd newswangerd merged commit d974f6a into ansible:master Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants