Repository navigation
feat(graph): [OCISDEV-1033] eliminate LDAP read-after-write on create/update - #12618
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
2a18661 to
ec2cf8a
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the graph LDAP identity backend to avoid immediate LDAP read-after-write calls on create/update paths when oCIS already has enough data to build the response, reducing failures/staleness when writes are proxied to replicated directories.
Changes:
- Create paths now synthesize response entries from the original
AddRequestwhenUseServerUUID=false, while retaining read-back whenUseServerUUID=true. - Update paths now synthesize response entries by folding the applied
ModifyRequestonto the pre-readldap.Entry(avoiding a post-write read-back). - Adds
ldap_writeback.gohelpers and expands/adjusts tests + changelog accordingly.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| services/graph/pkg/identity/ldap.go | Create/update user paths now synthesize responses instead of re-reading after write (when server UUID is not used). |
| services/graph/pkg/identity/ldap_group.go | Create group now synthesizes response entry when client-generated IDs are used. |
| services/graph/pkg/identity/ldap_education_user.go | Education user create/update now avoid read-after-write via synthesis/folding. |
| services/graph/pkg/identity/ldap_education_school.go | Education school create/update now avoid read-after-write; update path folds modifications onto pre-read entry. |
| services/graph/pkg/identity/ldap_education_class.go | Education class create/update now avoid read-after-write; update widens pre-read attrs and folds changes. |
| services/graph/pkg/identity/ldap_writeback.go | New helpers to synthesize entries from AddRequest and fold ModifyRequest changes onto an entry copy. |
| services/graph/pkg/identity/ldap_writeback_test.go | New focused unit/integration-style tests validating “no read-back” behavior and folding correctness. |
| services/graph/pkg/identity/ldap_test.go | Existing UpdateUser tests updated to reflect removal of post-write read-back. |
| services/graph/pkg/identity/ldap_education_user_test.go | CreateEducationUser test pinned to UseServerUUID=true to keep asserting read-back behavior. |
| services/graph/pkg/identity/ldap_education_school_test.go | Create/update education school tests updated for new folding behavior (fewer searches). |
| services/graph/pkg/identity/ldap_education_class_test.go | CreateEducationClass test pinned to UseServerUUID=true to keep asserting read-back behavior. |
| changelog/unreleased/enhancement-ldap-eliminate-read-after-write.md | Adds changelog entry describing the change and rationale. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Every graph LDAP create/update wrote the entry, then immediately re-read it back by DN solely to recover the entry ID for the response model. Against a replicated directory reached through a proxy, that read-back can hit a lagging replica and fail or return stale data. When oCIS generates the UUID itself (GRAPH_LDAP_SERVER_UUID disabled, the default), the read-back returns nothing new: create responses are now synthesized from the data already sent, and update responses are built by folding the applied modifications onto the entry read before the write. When the directory assigns the ID (GRAPH_LDAP_SERVER_UUID enabled), creates keep the existing read-back since the generated ID cannot otherwise be recovered. New ldap_writeback.go with two pure helpers: - attrsFromAddRequest: flatten an AddRequest for ldap.NewEntry (create paths) - applyModifyToEntry: fold a ModifyRequest (Replace/Add/Delete, case-insensitive, non-mutating, ByteValues populated for octet-string id parity) onto a copy of the pre-read entry (update paths) All 9 write sites updated: - creates (user, group, education user/class/school): synthesize when the ID is client-generated, keep the read-back when the server assigns it - updates (user, education user): fold the ModifyRequest onto the pre-read entry; the AccountEnabled trailing override and the rename read-back inside changeUserName are preserved (rename is out of scope) - education school update: updateSchoolProperties now returns its ModifyRequest so the caller can fold it; the displayName ModifyDN rename is folded as a displayName attribute replace - education class update: pre-read widened from name/id only to the full education-class attribute set so classification/externalID are not dropped from the response; the externalID ModifyDN rename is folded as an attribute replace Model builders are untouched, preserving the response shape. Existing update tests were reconciled: read-back Search mocks that are no longer issued were removed and the pre-read fixtures now carry the full baseline entry, with all assertions unchanged. OCISDEV-1033 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Octet-string ID attributes (e.g. Active Directory's objectGUID) are assigned by the directory server and require GRAPH_LDAP_SERVER_UUID=true. With GRAPH_LDAP_SERVER_UUID=false oCIS generates the ID and writes it as a string UUID, so an octet-string ID attribute would be decoded from raw string bytes and produce a corrupt ID on both the read-back and the synthesize path. NewLDAPBackend now rejects this incompatible combination at startup instead of silently returning bad IDs. Also adds regression tests for the id-attribute and group-name lookup fixes: - CreateGroup / CreateEducationClass synthesize the response id under the configured GroupIDAttribute (not a hardcoded attribute name) - getLDAPGroupByNameOrID filters by the group name attribute, not the user one Co-Authored-By: Claude Opus 4.8 <[email protected]>
The synthesize-on-create test matched the read-back on a hard-coded createdDN whose correctness relied on the school base DN being empty. Match on ScopeBaseObject instead: DN-independent and precise about the read-back being eliminated. Co-Authored-By: Claude Opus 4.8 <[email protected]>
00d4205 to
5d32e15
Compare
Just saying that this model needs to be followed up to the top. The problem will still be present if the service or even the client reads after writing. It's a first step though. |
Every graph LDAP create/update wrote the entry, then immediately re-read it back by DN solely to recover the entry ID for the response model. Against a replicated directory reached through a proxy, that read-back can hit a lagging replica and fail or return stale data.
When oCIS generates the UUID itself (GRAPH_LDAP_SERVER_UUID disabled, the default), the read-back returns nothing new: create responses are now synthesized from the data already sent, and update responses are built by folding the applied modifications onto the entry read before the write. When the directory assigns the ID (GRAPH_LDAP_SERVER_UUID enabled), creates keep the existing read-back since the generated ID cannot otherwise be recovered.
New ldap_writeback.go with two pure helpers:
All 9 write sites updated:
Model builders are untouched, preserving the response shape. Existing update tests were reconciled: read-back Search mocks that are no longer issued were removed and the pre-read fixtures now carry the full baseline entry, with all assertions unchanged.
OCISDEV-1033
Related PR's
#12707
#12708
#12709
Description
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: