-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fixes #20929: Require render_config permission for UI config rendering #20975
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
base: feature
Are you sure you want to change the base?
Conversation
- Modified `ObjectRenderConfigView.has_permission()` to require both view and render_config permissions - Added `remove_permissions()` test helper to remove permissions from existing ObjectPermission objects - Added regression tests for Device and VirtualMachine render-config permission enforcement The `render_config` permission action was introduced in #16681 for API endpoints. This extends PR_7604_description to the UI render-config tabs, preventing users from viewing rendered configurations without explicit permission.
| @tag('regression') # #20929 | ||
| def test_device_renderconfig_permission(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this a standard view test?
| @tag('regression') # #20929 | |
| def test_device_renderconfig_permission(self): | |
| def test_device_renderconfig(self): |
| @tag('regression') # #20929 | ||
| def test_virtualmachine_renderconfig_permission(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above.
| actions__contains=[action], object_types=object_type, users=self.user | ||
| ) | ||
| for obj_perm in obj_perms: | ||
| obj_perm.users.remove(self.user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_permissions() creates a new ObjectPermission instance for each permission passed, so it might be prudent to simply delete the instance here instead of removing the assigned user. (This approach could also create a name conflict if calling add_permissions() after remove_permissions() for the same model & action.)
| if super().has_permission(): # enforce base required permission | ||
| perm = get_permission_for_model(self.queryset.model, 'render_config') | ||
| if self.request.user.has_perm(perm): | ||
| self.queryset = self.queryset.restrict(self.request.user, 'render_config') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to avoid altering the queryset directly here if we can. Instead, how about just adding the necessary permission by name to additional_permissions under each view?
Fixes: #20929
ObjectRenderConfigView.has_permission()to require both view and render_config permissionsremove_permissions()test helper to remove permissions from existing ObjectPermission objectsThe
render_configpermission action was introduced in #16681 for API endpoints. This extends PR_7604_description to the UI render-config tabs, preventing users from viewing rendered configurations without explicit permission.