-
Notifications
You must be signed in to change notification settings - Fork 60
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
[RHCLOUD-33414] - restrict the Custom default access group renaming #1383
base: master
Are you sure you want to change the base?
[RHCLOUD-33414] - restrict the Custom default access group renaming #1383
Conversation
/retest |
rbac/management/group/view.py
Outdated
@@ -435,6 +455,7 @@ def update(self, request, *args, **kwargs): | |||
} | |||
""" | |||
validate_uuid(kwargs.get("uuid"), "group uuid validation") | |||
self.restrict_custom_default_group_renaming(request) |
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.
If you put this after the group = self.get_object(), you can check if the group is custom default group by group.platform_default. Which will simplify your method a lot
rbac/management/group/view.py
Outdated
@@ -438,6 +458,10 @@ def update(self, request, *args, **kwargs): | |||
self.protect_system_groups("update") | |||
|
|||
group = self.get_object() | |||
|
|||
if group.platform_default: | |||
self.restrict_custom_default_group_renaming(request) |
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.
Since you get the group above, you can put it into the method. If the name/description different from group.name/description, raise validation error
/retest |
…plit the check for and raising of error
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.
LGTM!
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.
hi Evan, thank you for the change, but we need to review it a little bit, please after you try to change the Custom default access
group and you get 400 (that is expected), check the data from database and you will see the record was changed, that is because self.restrict_custom_default_group_renaming(group)
is called after group = super().update(instance, validated_data)
.
def update(self, instance, validated_data):
"""Update the role object in the database."""
group = super().update(instance, validated_data)
self.restrict_custom_default_group_renaming(group)
group_obj_change_notification_handler(self.context["request"].user, group, "updated")
return group
I think we should use different direction here, I am open to discussion because I am not so experienced here and maybe we can use something similar as protect_system_groups()
in the view (here), and we should still keep in mind that it is possible to delete this group and add and remove roles from it
one option is to add new condition into protect_system_groups()
, for example something like
def protect_system_groups(self, action, group=None):
"""Deny modifications on system groups."""
if group is None:
group = self.get_object()
if group.system:
key = "group"
message = "{} cannot be performed on system groups.".format(action.upper())
error = {key: [_(message)]}
raise serializers.ValidationError(error)
if group.platform_default and action == "update":
key = "group"
message = "It is not allowed to change name or description of the 'Custom default access' group."
error = {key: [_(message)]}
raise serializers.ValidationError(error)
Yea, thanks Petra, good catch!!! And I agree putting the function inside the view seems to be appropriate. The |
Link(s) to Jira
https://issues.redhat.com/browse/RHCLOUD-33414
Description of Intent of Change(s)
Local Testing
How can the feature be exercised?
How can the bug be exploited and fix confirmed?
Is any special local setup required?
Checklist
Secure Coding Practices Checklist Link
Secure Coding Practices Checklist