authentik icon indicating copy to clipboard operation
authentik copied to clipboard

rbac: unable to assign user permissions to add manage group members

Open JanKoppe opened this issue 1 year ago • 4 comments

Describe your question/ I'm trying to assign some user the permissions to manage the members of a specific group, by using the new RBAC features and assigning object permissions and global permissions

Relevant infos Authentik 2023.10.6

Screenshots

Permissions of the user that should be able to manage the group members:

image

Screenshot of error message and failed (403) request when trying to add a new group member:

image

Additional context From what I understand after reading the source code for a few minutes I'm think that I should be running into this GroupView action:

https://github.com/goauthentik/authentik/blob/main/authentik/core/api/groups.py#L149C1-L149C60

It's setup with required the authentik_core.add_user permission, which the user has assigned as a global permission. It also has the authentik_core.change_group permission on that specific Group object as far as I understand.

I'm not sure which permission is missing, or which permission check is failing here.

Also, I'm not sure if checking for authentik_core.add_user permission is correct here - shouldn't this rather be an additional permission to check (e.g. authentic_core.add_group_member and authentic_core.remove_group_member) similar to how additional permissions have been added on the User model? https://github.com/goauthentik/authentik/blob/main/authentik/core/models.py#L275

It seems like this method is requiren people to create new Users just to be able to add existing users to existing groups, which seems like unnecessarily wide permissions.

My use-case for this is that I want to grant some unprivileged users the permission to manage the members of specific groups. This would allow me to give owners of an application that uses Authentik for authentication to control who exactly can authenticate for that application, which we would like to use as a very binary authorization function.

Am I misunderstanding something here, or is this an actual issue with the very early preview of RBAC?

I really appreciate you adding the RBAC feature by the way, it would solve a huge issue and remove a bunch of work for us!

JanKoppe avatar Jan 23 '24 10:01 JanKoppe

Am I misunderstanding something here, or is this an actual issue with the very early preview of RBAC?

I just tested out this feature today aswell and expected that exact behaviour like you said. Basically thats how the most services like that work. Glad I found out that im not alone.

I also experimented with a few additional permissions, such as "Core Can Change User" but these did not work either. Therefore, I'm starting to think this might be a bug in the RBAC system.

From me also great feature. keep up the great work!

esimes avatar Jan 26 '24 13:01 esimes

Hey @JanKoppe just make the following changes and it should do the trick ->

  1. Remove Can Change User permission
  2. Add Can add Group permission

This worked for me and I was able to create group managers

hiteshsondhi88 avatar Feb 14 '24 19:02 hiteshsondhi88

@hiteshsondhi88 thanks for the suggestion. We've already saw that as well, but this is a complete no-go: This will allow those group managers to create groups with superadmin privileges and thus elevate their privileges. Security-wise, this would be a complete no-go.

JanKoppe avatar Feb 15 '24 11:02 JanKoppe

@JanKoppe Can add Group doesn't allow users to create groups. If they try they just get a loading screen:

image

It's poorly named and really means "can add user to group"

lectrician1 avatar Feb 18 '24 02:02 lectrician1

They can do it via the API, e.g. with the Terraform Provider. We've tried that, and it works without any issues.

The reason why the WebUI breaks is because it tries to fetch other information first to which the user does not have permissions.

This will not prevent someone who wants to abuse this from doing so.

Example code for Terraform (written from memory, not tested, but that's the gist):

data "authentik_user" "me" {
  user = "maliciousperson"
}

resource "authentik_group" "hijack" {
  name = "allyourbasearebelongtome"
  users = [data.authentik_user.me.id]
  is_superuser = true
}

JanKoppe avatar Feb 21 '24 09:02 JanKoppe

curl -v -X POST "https://sso.yourdomain.com/api/v3/core/groups/" \
 -H "accept: application/json" \
 -H "content-type: application/json" \
 -H "Authorization: Bearer apitokenofuser" \
 -d '{"name":"supermaliciousgroup","is_superuser":true,"attributes":{}}'

Here is a quick curl command to check that. Jan is right. The right "Can add group" gives via API the right to create superuser groups.

After removing the permission again the user gets the error. {"detail":"You do not have permission to perform this action."}

esimes avatar Feb 21 '24 12:02 esimes

To clarify further: My current assumption (not verified, didn't have enough experience with DRF or the time to research it) is that for whatever reason adding a user to a group is not just interpreted as the action itself (which it is declared as) and only its permissions being checked, but also as a general POST to the Group ViewSet, which translates to the automatic/default permission of add_group internally. That would at least explain why adding the "Can add group" permissions suddenly allows adding users to a group. #8555 IMO should not be addressed, as it is correctly named, but just misbehaving and thus misunderstood.

JanKoppe avatar Feb 22 '24 07:02 JanKoppe

I forgot to link it, but this is fixed by #9254

BeryJu avatar Apr 19 '24 10:04 BeryJu

Nice feature! Would it be possible to restrict the visibility of a subset of users through permissions? Okta recently introduced the concept of realms, enhancing user management security for large organizations.

marcportabellaclotet-mt avatar Jun 05 '24 00:06 marcportabellaclotet-mt

You can already restrict the visibility of users by assigning permissions to specific users, however we're also planning to have an additional container object most likely called "Organizations" to further group users and manage them in chunks

BeryJu avatar Jun 06 '24 03:06 BeryJu

Organizations will help a lot when managing governance. Thanks

marcportabellaclotet-mt avatar Jun 07 '24 00:06 marcportabellaclotet-mt

I'm getting a similar issue, but the problem with mine is that it's just a blank error.

5zgw5cu4j8

Can't assign a user at all, just throws a blank message, and no other info in the logs.

Aetherinox avatar Jun 21 '24 19:06 Aetherinox