8000 fix(admin/api): verify role belongs to master realm when checking for protected admin roles by alehhu · Pull Request #51329 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

fix(admin/api): verify role belongs to master realm when checking for protected admin roles - #51329

Merged
pedroigor merged 1 commit into
keycloak:mainfrom
alehhu:fix/issue-51323
Aug 4, 2026
Merged

pedroigor merged 1 commit into
keycloak:mainfrom
alehhu:fix/issue-51323

Conversation

@alehhu
@alehhu alehhu commented Jul 31, 2026 •
Copy link
Copy Markdown
Contributor

Which problem is this PR solving?

Fixes #51323

Custom realm-level roles named admin in non-master realms were being incorrectly blocked from updates with HTTP 403 Forbidden. The recent security fix in PR #49624 relied on isRealmAdminRole(), which checked the role name but did not verify if the role belonged to the protected master admin realm.

Short description of the changes

  • Updated RolePermissions.isRealmAdminRole() to explicitly check that the role belongs to the master realm (Config.getAdminRealm()) before blocking it.
  • This ensures that ordinary application realms can freely use and manage custom roles named admin or create-realm without being incorrectly flagged as protected server-administration roles.

(Note: AI was used in autocomplete mode)

Copilot AI review requested due to automatic review settings July 31, 2026 09:53
@alehhu
alehhu requested a review from a team as a code owner July 31, 2026 09:53
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The security-boundary fix needs regression coverage for both non-master and master realm behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Restricts protected admin-role detection to the configured master realm, fixing false 403 responses in application realms.

Changes:

  • Checks the role container’s realm name.
  • Protects admin and create-realm only in the master realm.
File summaries
File Description
services/src/main/java/org/keycloak/services/resources/admin/fgap/RolePermissions.java Narrows protected-role detection to master-realm roles.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@alehhu
alehhu force-pushed the fix/issue-51323 branch from 412d1b5 to 7f7bd94 Compare July 31, 2026 09:58
Copilot AI review requested due to automatic review settings August 1, 2026 10:19
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The regression test renames both roles to the same name, causing the second update to fail with a duplicate-role conflict.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

tests/base/src/test/java/org/keycloak/tests/admin/authz/rbac/InternalClientManagementTest.java:117

  • Both loop iterations rename their role to TEMP_ROLE_NAME, so after the first succeeds the second update conflicts with the existing role name instead of verifying permission. Use a distinct target name for each protected-name case.
                client.realm("myrealm").rolesById().updateRole(role.getId(), renamed(role));
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings August 3, 2026 05:43
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The regression test should exercise the name-based endpoint reported in #51323.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

tests/base/src/test/java/org/keycloak/tests/admin/authz/rbac/InternalClientManagementTest.java:113

  • This regression test exercises the ID-based endpoint, but #51323 reproduces the failure through PUT /roles/{role-name}; the two endpoints have distinct request paths and the name-based path performs an additional container permission check. Invoke the name-based update here so the test covers the reported regression end to end.
                client.realm("myrealm").rolesById().updateRole(role.getId(), renamed(role));
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings August 3, 2026 05:47
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this c 8000 omment to others. Learn more.

🟢 Ready to approve

The focused authorization fix matches the reported regression and preserves master-realm protection with adequate test coverage.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Updated RolePermissions.isRealmAdminRole() to explicitly check that the role belongs to the master realm before blocking it. This ensures that application realms can use and manage custom roles named admin or create-realm without being flagged as protected roles.

Closes keycloak#51323

Signed-off-by: alehhu <159355663+alehhu@users.noreply.github.com>
@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest#employeeSigPostNoIdpKeyTestCertSubjectAsKeyNameInKeyInfo

Keycloak CI - Adapter IT Strict Cookies

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@pedroigor
pedroigor merged commit f38c16b into keycloak:main Aug 4, 2026
91 checks passed
@pedroigor
Copy link
Copy Markdown
Contributor

Thanks, @alehhu.

@alehhu
alehhu deleted the fix/issue-51323 branch August 4, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants

0