Repository navigation
KeyCloak Admin token always rejected in the testing server #49145
Replies: 1 comment
|
This is almost always a missing realm-management role, not a token problem. In Keycloak, a master-realm admin's access to other realms is granted per-realm: the master realm holds a client called The built-in Fix it in the master realm → Users → your admin user → Role mapping:
Once |
Uh oh!
There was an error while loading. Please reload this page.
Before reporting an issue
Area
No response
Describe the bug
eycloak Admin REST API returns 403 for one realm but works for another using the same master admin token
Hi everyone,
I am stuck with a Keycloak Admin REST API permission issue.
I have one Keycloak server with multiple realms:
local
dev
test
staging
I have an admin user in the master realm. My application logs in through admin-cli using this master admin user, gets an access token, and then calls Admin REST API endpoints to query users from different realms.
For example:
GET /admin/realms/staging/users
GET /admin/realms/test/users
The strange part is:
/admin/realms/staging/users works
/admin/realms/test/users returns 403 Forbidden
Both requests are made using the same master realm admin user and the same admin-cli token flow.
I have already checked the role mappings in the Keycloak Admin Console. For the master admin user, the relevant roles for the test realm appear to be assigned, including:
test-realm → query-users
test-realm → view-users
test-realm → view-realm
test-realm → manage-users
The equivalent roles for staging are also assigned, and staging works correctly.
I also decoded the access token. The decoded token looks the same when used for both staging and test, which makes sense because it is the same master realm admin user and the same login flow. The token issuer is from the master realm, and the authorized party is admin-cli.
However, when calling the users endpoint, only the test realm fails with 403 Forbidden.
I also checked the UI for fine-grained admin permissions, but in my Keycloak Admin Console I do not see an “Admin Permissions” or “Permissions” section under Realm Settings or under the realm-management client. So I am not sure if fine-grained admin permissions are enabled or relevant in this setup.
What I have verified so far:
My question is:
Why would the same master realm admin token be allowed to query users in staging, but return 403 Forbidden for test, even though the corresponding test-realm roles appear to be assigned to the same master admin user?
Version
20
Regression
Expected behavior
I expected that the admin token will work in testing server
Actual behavior
the response is always "Admin Forbidden"
How to Reproduce?
N/A
Anything else?
No response
All reactions