Story #8940
closedAdd RBAC content guard to pulpcore
100%
Description
Background¶
- https://docs.pulpproject.org/pulpcore/plugins/reference/content-protection.html#plugin-writers-use-content-protection
- https://docs.pulpproject.org/pulpcore/plugins/plugin-writer/concepts/index.html#role-based-access-control
Content guards are added to distributions and are used to protect who can download (and view) content available in that distribution from the content app. Users create content guard instances with specific settings for each distribution they want to protect. RBAC in Pulp is provided by Django and DRF and currently has no relation to content guards, so users can protect who can manage content in Pulp using RBAC, but not who can download it. There is a need for an RBAC enabled content guard that protects content based on RBAC permissions.
Implementation¶
Add a new RBAC content guard that would ship by default in pulpcore. The access policy for these content guard instances should be customizable by the user and if not set should default to the policy used by the distribution. Some requests go through a plugin's extended REST API first and then redirect to the content app, so an option to authorized requests based on redirection origin should be added to the content guard.
Related issues
Updated by bmbouter over 3 years ago
AccessPolicies are global, but allow for object level permissions to be checked. So what if the permission was named can_download
or dowload
and it had object-level permissions relating an instance of a distribution with a ContentGuard? Or maybe it should be on the content guard itself ..... ?
Updated by gerrod over 3 years ago
Talking it over with bmbouter, I think the best implementation would be to add a new permission called can_download
to the RBAC content guard that will determine if a user can download content from a distribution. When creating an RBAC content guard you would specify the users and groups to receive the can_download
permission for that instance of the guard. Then that content guard can be added to any distribution where you want those set of users to be able to download from.
The RBAC content guard would preform authentication and authorization for requests to the content app. It would create a 'fake' DRF view that would convert the aiohttp request to a django request and use the view's authentication and authorization methods defined by DRF settings. Example from container plugin (https://github.com/pulp/pulp_container/blob/master/pulp_container/app/authorization.py#L158) The authentication check will go through each authentication class one by one till the user is found. Then authorization will do a permission check on the user to see if they have the can_download
permission for that content guard.
Additional fields that could be added to content guard:
-
authentication_classes
- a string array listing all the auth classes to use for authenticating the user for the content guard, possible values would come from this setting https://www.django-rest-framework.org/api-guide/authentication/#setting-the-authentication-scheme. Default empty list would use all classes listed in that setting. -
permission_classes
- a string array listing all the permission classes to use for authorization, possible values would be the default permissions in DRF(https://www.django-rest-framework.org/api-guide/permissions/#api-reference) andAccessPolicyFromDB
(https://docs.pulpproject.org/pulpcore/plugins/plugin-writer/concepts/rbac/access_policy.html#viewset-enforcement). Default would be[AccessPolicyFromDB]
-
additional_permissions
- a string array listing additional permission checks needed on top ofcan_download
permission. These permissions would use the objects associated with this content guard (the distribution for the request, the repository of the distribution, the publication of the distribution). This field's behavior might not be easy to define with all the permissions available in Pulp.
Updated by gerrod over 3 years ago
- Related to Story #8951: Add authentication to content app added
Updated by gerrod over 3 years ago
With #8951 this content-guard should only do the permission check and use the authentication coming from the middleware.
Updated by pulpbot over 3 years ago
- Status changed from ASSIGNED to POST
Added by gerrod over 3 years ago
Updated by gerrod over 3 years ago
- Status changed from POST to MODIFIED
- % Done changed from 0 to 100
Applied in changeset pulpcore|19234ff6ec50bfa8e968d157b52c838899c968ff.
Updated by pulpbot over 3 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
Add RBAC content guard
fixes: #8940