Skip to content

feat(graph): [OCISDEV-1033] eliminate LDAP read-after-write on create/update - #12618

Merged
2403905 merged 6 commits into
stable-8.0from
feat/OCISDEV-1033
Jul 24, 2026
Merged

2403905 merged 6 commits into
stable-8.0from
feat/OCISDEV-1033

Conversation

@2403905

@2403905 2403905 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Related PR's

#12707
#12708
#12709

Description

Related Issue

  • Fixes <issue_link>

Motivation and Context

How Has This Been Tested?

  • test environment:
  • test case 1:
  • test case 2:
  • ...

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@kw-security

kw-security commented Jul 21, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AddRequest when UseServerUUID=false, while retaining read-back when UseServerUUID=true.
  • Update paths now synthesize response entries by folding the applied ModifyRequest onto the pre-read ldap.Entry (avoiding a post-write read-back).
  • Adds ldap_writeback.go helpers 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.

2403905 and others added 5 commits July 23, 2026 12:08
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]>
@2403905 2403905 changed the title feat(graph): eliminate LDAP read-after-write on create/update feat(graph): [OCISDEV-1033] eliminate LDAP read-after-write on create/update Jul 23, 2026
@2403905
2403905 force-pushed the feat/OCISDEV-1033 branch from 00d4205 to 5d32e15 Compare July 23, 2026 10:10
@2403905
2403905 marked this pull request as ready for review July 23, 2026 10:10
@2403905
2403905 changed the base branch from feat/OCISDEV-1030-ldap-client to stable-8.0 July 23, 2026 10:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

@jvillafanez

Copy link
Copy Markdown
Member

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.

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.

@2403905
2403905 enabled auto-merge (squash) July 24, 2026 11:59
@2403905
2403905 merged commit 67deb75 into stable-8.0 Jul 24, 2026
107 of 109 checks passed
@2403905
2403905 deleted the feat/OCISDEV-1033 branch July 24, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants