Skip to content

Commit

Permalink
Add RBAC to the group endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg authored and bmbouter committed Jan 29, 2021
1 parent e224749 commit 15611ae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/8159.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added RBAC to the endpoint for managing groups.
48 changes: 48 additions & 0 deletions pulpcore/app/viewsets/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from rest_framework.response import Response
from rest_framework.serializers import ValidationError

from pulpcore.app.access_policy import AccessPolicyFromDB
from pulpcore.app.viewsets import BaseFilterSet, NamedModelViewSet
from pulpcore.app.serializers.user import (
GroupSerializer,
Expand Down Expand Up @@ -104,6 +105,53 @@ class GroupViewSet(
serializer_class = GroupSerializer
queryset = Group.objects.all()
ordering = ("name",)
permission_classes = (AccessPolicyFromDB,)
queryset_filtering_required_permission = "auth.view_group"

DEFAULT_ACCESS_POLICY = {
"statements": [
{
"action": ["list"],
"principal": "authenticated",
"effect": "allow",
},
{
"action": ["create"],
"principal": "authenticated",
"effect": "allow",
"condition": "has_model_perms:auth.add_group",
},
{
"action": ["retrieve"],
"principal": "authenticated",
"effect": "allow",
"condition": "has_model_or_obj_perms:auth.view_group",
},
{
"action": ["update", "partial_update"],
"principal": "authenticated",
"effect": "allow",
"condition": "has_model_or_obj_perms:auth.change_group",
},
{
"action": ["destroy"],
"principal": "authenticated",
"effect": "allow",
"condition": "has_model_or_obj_perms:auth.delete_group",
},
],
"permissions_assignment": [
{
"function": "add_for_object_creator",
"parameters": None,
"permissions": [
"auth.view_group",
"auth.change_group",
"auth.delete_group",
],
},
],
}


class GroupModelPermissionViewSet(NamedModelViewSet):
Expand Down

0 comments on commit 15611ae

Please sign in to comment.