Can we set an admin user for a realm that is not master?

Hi all,

Our app is running keycloak from a docker container.
when we run the keycloak we set up a user named “keycloak-admin” with password 12345 (not really :slight_smile: ) for the MASTER realm.

after that, we create a new realm named NLS from a realm.json file.
then we add a user named “nls-admin”

Now, if I understand correctly in order to add more users in the NLS realm only the user “keycloak-admin” can do it

when we go into: http:///auth/admin/master/console/ I can log in with “keycloak-admin” and select the NLS realm and then add as many users as I wish.

my question is - is there a way to allow the “nls-admin” user to also have admin permission for the NLS realm? like the “keycloak-admin” but only for the NLS realm.

cause, in the current status, if I try to log in into http:///auth/admin/NLS/console/ with nls-admin i get a page that says that I don’t have permissions.

just to celebrate why we need it - basically, we set up a realm for our customers today. we want to give them an admin user for the keycloak but only for a specific realm

Of course this is possible, but you have to set the proper roles to your “nls-admin” user.
You have to assign the “realm-admin” role from the “realm-management” client to your “nls-admin” user. The “realm-admin” role effectively assigns all the other roles to the user. See picture:

1 Like

thx a lot. this is exactly what I was looking for!

a quick (I hope) follow-up question - can we assign this role using scripts (kcadm.sh)?

Today we do the following to assign role and group for the nls-admin:

kcadm.sh add-roles --uusername nls-admin --rolename Administrators -r NLS
kcadm.sh update users/[nls-admin-id]/groups/$GROUP_ID -r NLS -s realm=NLS -s userId=[nls-admin-id] -s groupId=$GROUP_ID -n

is there a detailed source for all kcadm.sh commands?

The kcadm tool is just a wrapper around the Keycloak Admin REST API and to call the various resources/endpoints. So, basically everthing you do via the admin UI (admin web console), you can also do via kcadm. Documentation for the Admin REST API is on the documentation page: Keycloak - Documentation (ok, it’s not the best docs, but anyhow…)

1 Like