I have a following use case:
- My solution has multiple projects and each project can have two roles: Project Administrator (who can view and edit project information) and a Project Viewer (who can only view project information)
- There is also a high level Root Administrator who creates these projects and then assigns users to the project level roles.
In KeyCloak, is there a way to create roles under a resource?
Let’s take an example:
- There are 3 users: Bob, John and Adam.
- Bob is the Root Administrator
- Bob creates two projects: ProjectA and ProjectB
- For ProjectA, Bob assigns the role of Project Admin to John and Project Viewer role to Adam.
- For ProjectB, Bob assigns the role of Project Admin to Adam and Project Viewer role to John
How do configure KeyCloak for such a use-case?
Please also note that Bob can later on create new Projects and delete the old ones.
I am still learning KeyCloak but one way to do so is as follows:
- Bob is the Admin for KeyCloak and so can create new resources in it
- For ProjectA, Bob creates 2 roles: ProjectA-Admin, ProjectA-Viewer. John is assigned to former role and Adam to the later
- For ProjectB, Bob creates 2 roles: ProjectB-Admin, ProjectB-Viewer. Adam is assigned to former role and John to the later
- Whenever a new Project needs to be added, Bob has to create a new Project-Admin and -Viewer roles, and assign users to those roles.
I believe these roles would be contained in the access token, so the resource server can parse the roles in the token using some pattern such as (ProjectName-Role) and then decide what kind of permission the user has. One can also create Policies and Permissions as well.
Please provide your feedback. Thanks for your help.