Repository navigation
Description
Before reporting an issue
- I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
Area
admin/api
Describe the bug
After upgrading from Keycloak 26.6.3 to 26.7.0, updating a custom realm-level role whose name is exactly admin fails with HTTP 403 Forbidden. The role belongs to an ordinary application realm and is not related to Keycloak server administration.
The failure is caused by the security fix from PR #49624 / commit 39cb8de54c8517efeda4baa8bc314fd40e9c6934, which prevents updates to protected administration roles. The name-based guard used for that fix appears to classify every realm-level role named admin as the protected admin role from the master realm, regardless of the role's actual realm.
Version
26.7.0
Regression
- The issue is a regression
Expected behavior
A custom realm-level role named admin in a non-master realm should be updateable, because it is an application-defined role and not the protected server-administration admin role of the master realm.
Actual behavior
The update request is rejected with HTTP 403 Forbidden.
How to Reproduce?
- Start Keycloak 26.7.0.
- Create a regular realm, for example
test. - Create a realm-level role named
admin. - Attempt to update the role through the Admin REST API:
with any valid
PUT /admin/realms/test/roles/adminRoleRepresentationbody. - The request returns
HTTP 403 Forbidden. - Repeat with a role having a different name, for example
application-admin; the update succeeds.
Anything else?
Minimal request / response
PUT /admin/realms/001-operators/roles/admin
Content-Type: application/json
Authorization: Bearer <token>
Response:
HTTP 403 Forbidden
Server-side stack trace (Keycloak 26.7.0):
jakarta.ws.rs.ForbiddenException: HTTP 403 Forbidden
Additional context
I am importing the realm with keycloak-config-cli. The client-side stack trace is:
jakarta.ws.rs.ForbiddenException: HTTP 403 Forbidden
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:240)
at de.adorsys.keycloak.config.repository.RoleRepository.updateRealmRole(RoleRepository.java:91)
at de.adorsys.keycloak.config.service.RoleImportService.updateRoleIfNeeded(RoleImportService.java:223)
at de.adorsys.keycloak.config.service.RoleImportService.createOrUpdateRealmRole(RoleImportService.java:146)
The relevant code path in RoleContainerResource was changed by PR #49624 to call:
auth.roles().requireManage(role);RolePermissions.canManage then rejects roles for which isRealmAdminRole(role) is true:
private boolean isRealmAdminRole(RoleModel role) {
return role.getContainer() instanceof RealmModel
&& List.of(AdminRoles.ADMIN, AdminRoles.CREATE_REALM)
.contains(role.getName());
}This check only verifies that the role is a realm role and that its name is admin or create-realm. It does not verify that the role belongs to the master realm. As a result, custom application roles in non-master realms are incorrectly treated as protected server-admin roles and cannot be updated.
Related
- Related to: 403 on updating realm-management client #51036, [CVE-2026-9796] Admin role rename TOCTOU bypasses checkAdminRoles — realm-wide escalation from manage-clients #49427
- Caused by: PR Do not allow updates on the realm-management client #49624, commit
39cb8de54c8517efeda4baa8bc314fd40e9c6934 - Possibly fixed in the same area as: fix(admin): block TOCTOU rename bypass of protected admin roles #49516
Activity
alehhu commentedon Jul 31, 2026
Hi! I'm currently looking into this.
You're completely right about the root cause: the
isRealmAdminRolecheck inRolePermissions.javaonly verifies the role name but fails to verify if the role actually belongs to themasteradmin realm.I'm working on a fix to explicitly verify
realm.getName().equals(Config.getAdminRealm())so that ordinary application realms can freely manage custom roles namedadminwithout being blocked by the security checks.I'll submit a PR shortly once my local build finishes!
ahus1 commentedon Aug 2, 2026
@sguilhen / @pedroigor - this is a regression in 26.7 - can you please triage?
pedroigor commentedon Aug 3, 2026
Looks like it is, and we should check if the container of the
admin(same forcreate-realm) role is the master realm. I'll look at it more closely.15 remaining items
ahus1 commentedon Aug 21, 2026
@pedroigor - as this appears only from 26.7 onwards, I don't think this needs to be backported to 26.6.
If this is the case, please remove the backport label and mark it as backported. Thanks!
fix(admin/api): allow non-master realm roles named admin or create-re…