PowerFlex 4.x Unable to add or remove LDAP group
Summary: After AD removal from PFxM, and Keycloak unable to remove cached LDAP groups.
Symptoms
Scenario
An initial attempt to add a group results in an error:
Failed to add Remote group Failed to find request group


After populating groups in the keycloak ldap filter, per PowerFlex 4.X - How To Apply LDAP Group Search Filter In PFxM Keycloak Admin Console | Dell US , and sync from PFxM to the LDAP provider, the sso.stdout.log shows that group sync is not working:
2024-09-25T07:10:31.684769872Z stdout F 2024-09-25T07:10:31.684Z INFO 1 --- [io-8083-exec-10] c.d.s.c.DirectoryServicesController : Received sync user request 2024-09-25T07:10:31.685080784Z stdout F 2024-09-25T07:10:31.684Z INFO 1 --- [pool-9-thread-1] c.d.s.managers.DirectoryServiceManager : starting sync process for ldap groups 2024-09-25T07:10:31.69678586Z stdout F 2024-09-25T07:10:31.696Z INFO 1 --- [pool-9-thread-1] com.dell.sso.clients.KeycloakClient : Ldap group sync started 2024-09-25T07:10:31.710659167Z stdout F 2024-09-25T07:10:31.710Z ERROR 1 --- [pool-9-thread-1] com.dell.sso.clients.KeycloakClient : Failed to sync groups: HTTP 500 Internal Server Error 2024-09-25T07:10:31.710959458Z stderr F Exception in thread "pool-9-thread-1" java.lang.RuntimeException: com.dell.sso.exceptions.KeycloakException: Failed to sync groups or sync users
After removing the LDAP provider, the database still shows groups (ex. below shows four groups)
delladmin@mvm1:/>kubectl exec -it -c database -n powerflex $(kubectl get pods -n powerflex -l='postgres-operator.crunchydata.com/role=master, postgres-operator.crunchydata.com/instance-set' | grep Running | cut -d' ' -f1) -- psql -U postgres -d keycloak -c "SELECT COUNT(*) FROM keycloak_group;"
count
-------
4
(1 row)
Connectivity to ldap from PFMP should be confirmed with the following command:
kubectl exec -it keycloak-0 -n powerflex -- curl --verbose ldap://
Example:

Impact
Unable to add or remove LDAP groups.
Cause
|
When AD is Removed:
|
Resolution
Delete each group individually using the API one at a time.
1) retrieve keycloak credentials..
kubectl get secrets -n powerflex keycloak-admin-credentials -o jsonpath='{.data.username}' | base64 --decode; echo -e
kubectl get secrets -n powerflex keycloak-admin-credentials -o jsonpath='{.data.password}' | base64 --decode; echo -e
2) Get access token (note: substitute 4578ZZyT3f with the password from the above output):
TOKEN=$(curl -X POST https://keycloak-http.powerflex/auth/realms/master/protocol/openid-connect/token -H 'Content-Type: application/x-www-form-urlencoded' -d 'scope=openid&grant_type=password&client_id=admin-cli&username=keycloak&password=4578ZZyT3f' | jq -r '.access_token'); echo $TOKEN
3) Check for groups using api (list 10 groups at a time)
curl -X GET "https://keycloak-http.powerflex/auth/admin/realms/powerflex/groups?first=0&max=10" -H "Authorization: Bearer $TOKEN" | jq
4) Delete groups one at a time (substitute with each id from step 3 above.
curl -X DELETE https://keycloak-http.powerflex/auth/admin/realms/powerflex/groups/"" -H "Authorization: Bearer $TOKEN"
Alternatively, use loop script to delete group_id's one at a time.
for group_id in $(curl -X GET "https://keycloak-http.powerflex/auth/admin/realms/powerflex/groups" -H "Authorization: Bearer $TOKEN" | jq -r '.[].id'); do curl -X DELETE "https://keycloak-http.powerflex/auth/admin/realms/powerflex/groups/$group_id" -H "Authorization: Bearer $TOKEN"; done
Example

Impacted Versions
PFMP 4.x
Fixed In Version
Future version of keycloak will support bulk group deletion.