Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are Keycloak roles managed?

Tags:

keycloak

Keycloak is a great tool, but it lacks proper documentation.

So we have Realm.roles, Client.roles and User.roles

How do there 3 work together when accessing an application using a specific client?

Sincerely,

like image 318
Olivier Refalo Avatar asked Dec 15 '17 18:12

Olivier Refalo


People also ask

What are roles in Keycloak?

Keycloak provides the concept of a client scope for this. Clients can define roles that are specific to them. This is basically a role namespace dedicated to the client. A token that provides identity information about the user.

How do I get user roles from a Keycloak?

To assign a user a role: Under the users section in Keycloak, click the user's ID (if there are missing users, click “View all users”). In the role mappings tab, select the GeoStore client from the client roles dropdown.

What is user managed access in Keycloak?

Resource Sharing Resource owners are allowed to manage permissions to their resources and decide who can access a particular resource and how. {project_name} can then act as a sharing management service from which resource owners can manage their resources.

Does Keycloak support RBAC?

For instance, to allow access to a group of resources only for users granted with a role "User Premium", you can use RBAC (Role-based Access Control). Keycloak provides a few built-in policy types (and their respective policy providers) covering the most common access control mechanisms.


1 Answers

In KeyCloak we have those 3 roles:

  1. Realm Role
  2. Client Role
  3. Composite Role

There are no User Roles in KeyCloak. You most likely confused that with User Role Mapping, which is basically mapping a role (realm, client, or composite) to the specific user

In order to find out how these roles actually work, let's first take a look at a simple Realm model I created. As you can see in picture below, every Realm has one or multiple Clients. And every Client can have multiple Users attached to it.

enter image description here

Now from this it should be easy to conclude how role mappings work.

Realm Role: It is a global role, belonging to that specific realm. You can access it from any client and map to any user. Ex Role: 'Global Admin, Admin'

Client Role: It is a role which belongs only to that specific client. You cannot access that role from a different client. You can only map it to the Users from that client. Ex Roles: 'Employee, Customer'

Composite Role: It is a role that has one or more roles (realm or client ones) associated to it.

like image 164
Dino Avatar answered Sep 22 '22 05:09

Dino