fix(groups): reconcile members on PUT and invalidate user cache#112
Open
nirclarity wants to merge 1 commit into
Open
fix(groups): reconcile members on PUT and invalidate user cache#112nirclarity wants to merge 1 commit into
nirclarity wants to merge 1 commit into
Conversation
Two related fixes to GroupsController:
1. updateGroup (PUT /Groups/{id}) previously only set displayName and
silently dropped the `members` array. Okta's Group Push uses PUT
(not PATCH) with the desired final member list, so this no-op meant
membership changes from Okta never propagated to Keycloak. The fix
reconciles the request's members against the current members:
removes users no longer in the desired set (with leave events) and
adds new ones (with join events).
2. After mutating membership via user.leaveGroup() / user.joinGroup(),
Keycloak's Infinispan user cache holds a stale view of the user's
group list. Subsequent reads of /users/{id}/groups return outdated
entries until the cache expires. Explicitly evict the affected
user from the UserCache to ensure immediate consistency.
Verified against Okta SCIM provisioning + Keycloak 26.6:
- PUT /Groups/{id} with added/removed members updates both the group's
members list and each user's groups list.
- No manual cache clear required after membership changes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Contributor
|
Thanks for this fix! |
This was referenced May 23, 2026
Author
Sure! I hope to get back to this soon :) |
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.



Summary
Two related fixes to
GroupsControllerthat block end-to-end group membership sync from Okta to Keycloak via SCIM.Bug 1 —
updateGroupsilently dropsmembersThe current implementation only updates
displayName:Okta's Group Push uses
PUT /Groups/{id}(not PATCH) with the desired final member list. With this no-op handler, the plugin returns 200 with the request "accepted" but membership changes never propagate to Keycloak — silently. Particularly nasty because Okta sees success and stops retrying.(This is a separate-but-related issue to the path-less PATCH shape covered in #95 / #100.)
Fix: reconcile the request's
membersagainst the current members. Mirror the logic already increateGroupandpatchGroup's REPLACE branch — remove users not in the desired set (with leave events) and add new ones (with join events).Bug 2 — stale Keycloak user cache after membership change
After calling
user.leaveGroup(...)/user.joinGroup(...), Keycloak's Infinispan user-side cache isn't invalidated. The join table in Postgres updates correctly, andgetGroupMembersStreamreads fresh, so/groups/{id}/membersand the plugin's own SCIMGET /Groups/{id}view are correct. But/users/{id}/groupsreads the user object's cached groups list and returns stale entries until the realm cache is manually cleared or the TTL expires.This caused removed-from-group users to still appear in their groups list via the Admin REST API, even though SCIM had processed the removal correctly.
Fix: after each
leaveGroup/joinGroup, explicitly evict the user fromUserCacheso subsequent reads re-read from DB.Verification
Tested against Keycloak 26.6.0 + Okta SCIM provisioning (real Okta tenant + ngrok-exposed Keycloak):
PUT /Groups/{id}adding a user → user appears in both/scim/v2/Groups/{id}.membersand/admin/realms/{r}/users/{id}/groupsimmediately.PUT /Groups/{id}removing a user → both views update immediately (no cache clear needed).