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

Add a set_current_group method for users #176

Merged
merged 1 commit into from
Nov 13, 2017
Merged

Add a set_current_group method for users #176

merged 1 commit into from
Nov 13, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Nov 3, 2017

The current way of setting a user’s current_group via edit uses resource_search, which encounters some RBAC issues. For example, when a user changes from the super administrator group to the tenant group, they are no longer able to switch back even though they belong to the group because resource_search returns a forbidden error. By choosing a group based off of their current miq_groups, it resolves the issue and keeps the ability to change groups consistent with that in the classic-ui.

How it works in the classic ui:
group_switching_classic_ui

The failure present in the SUI before the fix:
group_switching_sui

The successful API call with set_current_group:
group_switching_api

In addition, with update_attributes! it raises a validation error saying that the superadministrator group is not in their groups, also appears to be due to RBAC. I looked to the classic UI to see how their behavior works, and chose to use update_attribute based off of that. Because this is different behavior than a typical edit, I felt that it also deserved a specialized method, thus removing this functionality from edit and moving it to set_current_group.

This is also a unique use case, and did not think it would apply as a collection action, but am open to discussion around that.

https://bugzilla.redhat.com/show_bug.cgi?id=1467364

@miq-bot add_label bug, gaprindashvili/yes
@miq-bot assign @abellotti

cc: @AllenBW

config/api.yml Outdated
@@ -2779,6 +2779,8 @@
:identifier: rbac_user_edit
- :name: delete
:identifier: rbac_user_delete
- :name: set_current_group
:identifier: rbac_user_edit
Copy link
Member

Choose a reason for hiding this comment

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

does this mean if a user does not have that role they cannot change their current group ?

Copy link
Author

Choose a reason for hiding this comment

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

@abellotti yeah, I guess so. I am not sure if users should always be allowed to change their own group or if they need that particular role?

Copy link
Member

Choose a reason for hiding this comment

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

May be easy to verify, in classic UI login as a user without that role but a member of a couple of groups, see if you can change the current group in the upper right hand pull-down. If you can, we'll need to somehow handle that.

Copy link
Author

Choose a reason for hiding this comment

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

@abellotti verified that a user in the classic UI without this edit role is still able to change their group. updated accordingly 👍

@abellotti
Copy link
Member

With the role identifier removed, we probably need to make sure that the action is only run on the authenticated user, otherwise anyone can change anyone else's group. Can you verify this and add a test pertaining to that ? Thanks.

AllenBW added a commit to AllenBW/manageiq-ui-service that referenced this pull request Nov 6, 2017
def set_current_group_resource(_type, id, data)
User.current_user.tap do |user|
raise "Can only edit authenticated user's current group" unless user.id == id
group_id = parse_id(data["current_group"], :groups)
Copy link
Member

Choose a reason for hiding this comment

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

can you use parse_group(data["current_group"]) here ? it support both id/href as well as the identifying attr,i.e. be able to set current group by description.

Copy link
Member

Choose a reason for hiding this comment

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

or maybe the parse_fetch_group we used earlier.

Copy link
Author

Choose a reason for hiding this comment

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

@abellotti can't use parse_fetch_group because it uses resource_search. Will update to use parse_group though

@AllenBW
Copy link
Member

AllenBW commented Nov 9, 2017

I know everyone is da 🐝, wanted to do a quick status check on this 👶

🙇‍♀️ ⭕️ :octocat:

@abellotti
Copy link
Member

I think I'm good with this, @jntullo can you take care of the rubocop warning ? Thanks.

@jntullo
Copy link
Author

jntullo commented Nov 9, 2017

@abellotti the rubocop warning can't be fixed, it is part of the solution to the current issue

@abellotti
Copy link
Member

Hmm, can user.current_group = new_group be done instead ? If not, maybe simply add a comment in the code that update_attributes! cannot be used just so that it's not inadvertently "fixed" in the future. Thanks.

The current way of setting a user’s current_group uses resource_search, which encounters some RBAC issues. For example, when a user changes from the super administrator group to the tenant group, they are no longer able to change to the super administrator group even though it is in their MIQ groups because resource_search does not allow them to see the super administrator group. By choosing a group based off of their current miq_groups, it resolves the issue and keeps the ability to change groups consistent with that in the classic-ui.

https://bugzilla.redhat.com/show_bug.cgi?id=1467364
@miq-bot
Copy link
Member

miq-bot commented Nov 13, 2017

Checked commit jntullo@119312c with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 2 offenses detected

**

  • 💣 💥 🔥 🚒 - Linter/Yaml - missing config files

app/controllers/api/users_controller.rb

@abellotti
Copy link
Member

Thanks @jntullo for updating this. 👍

@abellotti abellotti added this to the Sprint 73 Ending Nov 13, 2017 milestone Nov 13, 2017
@abellotti abellotti merged commit 8f30e9c into ManageIQ:master Nov 13, 2017
simaishi pushed a commit that referenced this pull request Nov 14, 2017
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 29014b7a216d843ee8a46106f0601d60e98aaa91
Author: Alberto Bellotti <abellotti@users.noreply.github.com>
Date:   Mon Nov 13 16:47:43 2017 -0500

    Merge pull request #176 from jntullo/bug/change_current_group
    
    Add a set_current_group method for users
    (cherry picked from commit 8f30e9cd9894e302add1729d7aa7bb54764db33b)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1513191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants