Enforce membership permission when creating users - #51458
Open
pedroigor wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Enforces FGAP V2 group membership permissions during user creation, addressing CVE-2026-18571.
Changes:
- Validates
MANAGE_MEMBERSHIPbefore assigning each requested group. - Adds a customizable group membership handler.
- Adds integration coverage for permitted, unpermitted, and mixed assignments.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
UsersResource.java |
Enforces group membership authorization. |
RepresentationToModel.java |
Adds the membership-handler overload. |
UserResourceTypeEvaluationTest.java |
Tests authorization during user creation. |
sguilhen
approved these changes
Aug 6, 2026
Closes keycloak#51378 Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (3)
tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/UserResourceTypeEvaluationTest.java:526
search(\"myadmin\").get(0)assumes the first hit is the intended user and that ordering is stable. To avoid nondeterministic failures, select the exact match (e.g., filter bygetUsername().equals(\"myadmin\")) and assert it exists uniquely before usinggetId().
UserRepresentation myadmin = realm.admin().users().search("myadmin").get(0);
UserPolicyRepresentation allowMyAdminPermission = createUserPolicy(realm, adminPermissionsClient, "Only My Admin User Policy", myadmin.getId());
tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/UserResourceTypeEvaluationTest.java:534
- The test creates two groups but doesn’t register cleanup for them, which can leak state across test runs and make failures harder to debug. Add cleanup entries to delete
permittedGroup/unpermittedGroupat the end of the test (similar to the user deletions).
GroupRepresentation permittedGroup = createGroup("permitted-group");
GroupRepresentation unpermittedGroup = createGroup("unpermitted-group");
server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java:809
- The new overload makes group assignment dependent on the provided
membershipHandler, but this isn’t obvious from the signature and is easy to misuse (e.g., passing a permission-check-only consumer and unintentionally skippingjoinGroup). Consider adding Javadoc that explicitly states the consumer must perform the membership operation, or adjust the API to separate 'authorize' from 'join' to prevent accidental no-op group assignment.
public static void createGroups(KeycloakSession session, UserRepresentation userRep, RealmModel newRealm, UserModel user) {
createGroups(session, userRep, newRealm, user, user::joinGroup);
}
public static void createGroups(KeycloakSession session, UserRepresentation userRep, RealmModel newRealm, UserModel user, Consumer<GroupModel> membershipHandler) {
Objects.requireNonNull(membershipHandler, "membershipHandler must not be null");
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #51378