Skip to content

Custom realm-level role named admin cannot be updated in non-master realms after Keycloak 26.7.0 #51323

Closed

Description

@jtregl

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?

  1. Start Keycloak 26.7.0.
  2. Create a regular realm, for example test.
  3. Create a realm-level role named admin.
  4. Attempt to update the role through the Admin REST API:
    PUT /admin/realms/test/roles/admin
    
    with any valid RoleRepresentation body.
  5. The request returns HTTP 403 Forbidden.
  6. 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

Activity

  1. added
    kind/bug
    on Jul 31, 2026
  2. added theissue type on Jul 31, 2026
  3. added
    area/admin/api
    on Jul 31, 2026
  4. alehhu commented on Jul 31, 2026

    @alehhu
    Contributor

    Hi! I'm currently looking into this.

    You're completely right about the root cause: the isRealmAdminRole check in RolePermissions.java only verifies the role name but fails to verify if the role actually belongs to the master admin 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 named admin without being blocked by the security checks.

    I'll submit a PR shortly once my local build finishes!

  5. added
    area/admin/rbac
    and removed
    area/admin/api
    on Aug 2, 2026
  6. ahus1 commented on Aug 2, 2026

    @ahus1
    Member

    @sguilhen / @pedroigor - this is a regression in 26.7 - can you please triage?

  7. pedroigor commented on Aug 3, 2026

    @pedroigor
    Contributor

    Looks like it is, and we should check if the container of the admin (same for create-realm) role is the master realm. I'll look at it more closely.

  8. 15 remaining items

  9. ahus1 commented on Aug 21, 2026

    @ahus1
    Member

    @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!

  10. added a commit that references this issue on Aug 31, 2026
    7dbd1ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Fields

No fields configured for bug.

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions