Skip to content

fix(roles): ignore server-generated ids when comparing roles - #1674

Open
RutgerLubbers wants to merge 1 commit into
adorsys:mainfrom
Q24:feat/ignore-role-ids-on-compare
Open

RutgerLubbers wants to merge 1 commit into
adorsys:mainfrom
Q24:feat/ignore-role-ids-on-compare

Conversation

@RutgerLubbers

@RutgerLubbers RutgerLubbers commented Sep 3, 2026 •

Copy link
Copy Markdown

Role change-detection compared the server-assigned id and containerId, so a realm exported from another Keycloak instance made every role look changed and triggered pointless updates. Since Keycloak 26.6.4 those updates fail with HTTP 403 on the admin, create-realm and realm-management roles, aborting the import.

Both identifiers are now excluded from the patch and the equality check for realm and client roles, matching what ClientImportService already does. The existing role's identifiers survive because the patch is built on a clone of it.

Fixes #1672

Role change-detection compared the server-assigned `id` and `containerId`,
so a realm exported from another Keycloak instance made every role look
changed and triggered pointless updates. Since Keycloak 26.6.4 those
updates fail with HTTP 403 on the `admin`, `create-realm` and
`realm-management` roles, aborting the import.

Both identifiers are now excluded from the patch and the equality check
for realm and client roles, matching what ClientImportService already
does. The existing role's identifiers survive because the patch is built
on a clone of it.
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Comment on lines +218 to 219
RoleRepresentation patchedRole = CloneUtil.patch(existingRole, roleToImport, propertiesToIgnoreOnUpdate);
if (roleToImport.getAttributes() != null) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree that this change is the cause of the underlying analysis.
Further the method is only called if existingRole != null and CloneUtil.patch only returns null if origin (or existingRole in this case) is null.

Comment on lines +237 to 238
RoleRepresentation patchedRole = CloneUtil.patch(existingRole, roleToImport, propertiesToIgnoreOnUpdate);
String roleName = existingRole.getName();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Role import sends spurious updates because server-generated id/containerId are compared → HTTP 403 on protected roles (Keycloak 26.6.4+)

1 participant