m365_gruppenkorrektur.py (23,8 KB)
m365_gruppenpruefung.py (7,6 KB)
Problem
Existing Microsoft 365 groups contain missing or additional members compared with UCS, although adding and removing individual members currently works.
This behavior was investigated with UCS 5.2-6, UCS@school and Microsoft 365 Connector 6.6. UCS was configured as the authoritative source for group memberships.
Investigation
Confirm the following before correcting memberships:
- The UCS group and the cloud group refer to the same Microsoft 365 group object ID.
- Compare members by their Microsoft 365 object IDs, rather than names or member counts alone.
- All intended UCS members resolve to existing cloud users.
- Check
/var/log/univention/listener.logand available rotated logs for earlier failed group updates.
In the investigated case, a substantial membership change failed while retrieving an access token. Later user synchronization processed additional membership additions. This explains how memberships could diverge, although not every historical membership could be reconstructed.
Successful individual membership changes confirm current synchronization functionality. They do not establish that earlier inconsistencies have been repaired.
Root Cause
The group modification path in Connector 6.6 calculates membership changes from the previous and current UCS group states. It does not perform a complete reconciliation against the existing cloud membership list.
Consequently, subsequent changes do not necessarily repair memberships left inconsistent by an earlier failed update.
Removing and re-adding a UCS member can trigger another addition for that user. It does not remove additional cloud members that are absent from the UCS group.
The underlying cause of the historical token retrieval failure was not conclusively established.
Solution
Use a targeted membership reconciliation as a workaround, after resolving any current synchronization errors. Confirm that UCS is the authoritative source before removing cloud memberships.
For a small number of groups, compare the intended UCS members with the direct members shown in the Microsoft Entra admin center. Add missing memberships and remove only confirmed additional memberships. Preserve the group and user accounts.
For multiple groups, Univention Support can assess whether the support-developed correction scripts used in this investigation are suitable. These scripts are not built-in Connector commands. Obtain both m365_gruppenpruefung.py and the matching m365_gruppenkorrektur.py from Support before using the following procedure.
Place both files in the same directory on the Connector server. As root, first generate a preview for one group:
python3 m365_gruppenkorrektur.py "<GROUP-NAME>"
The preview does not modify memberships. Review the generated JSON file, including the planned additions and removals.
Apply the newly generated plan:
python3 m365_gruppenkorrektur.py --apply --plan "<NEW-PLAN.json>"
The --apply command modifies cloud memberships. Missing members are added and verified before additional members are removed. The script waits for membership changes to become visible and verifies the final membership set.
After validating one group, create a UTF-8 file named groups.txt containing one complete UCS group name per line:
python3 m365_gruppenkorrektur.py --groups-file groups.txt
Review this new preview before applying it with --apply --plan.
Important:
- The correction procedure supports static, non-mail-enabled security groups with direct user memberships. Teams, nested groups and other unsupported configurations require separate assessment.
- Empty UCS member lists are deliberately not applied. An empty UCS group does not prove that its cloud group is empty.
- Avoid concurrent imports or membership changes for the selected groups.
- Always create a fresh plan after a partial or interrupted correction.
stoppedcan mean that some changes were already completed. Changes are not automatically rolled back; processing continues with subsequent groups.- Retain the result JSON file and console output for review.
Finally, compare the memberships directly in UCS and Microsoft Entra. A successful reconciliation restores the current membership state; it does not prevent inconsistencies caused by future synchronization failures.