LDAP/AD sync aborts entirely when two directory users share the same e-mail address
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, rust
- Domain
- authentication, backend, databases
Research direction
Start with crates/defguard_core/src/enterprise/ldap/sync.rs at the import path around lines 1133-1169 and apply_user_modifications around line 629; compare the conflict handling in directory_sync/mod.rs:867-897. Reproduce the duplicate-mail case, then verify that the conflicting user is skipped, both users are named in the error, and the remaining sync operations continue instead of rolling back.
Written by the indexing model from the issue text.
Description
Component: defguard core – enterprise/ldap/sync.rs
Version: 2.1.0 (also present on current main)
Description
user.email has a case-insensitive unique index (email_unique_idx, migration 20241204113104_case_insensitive_email). The LDAP sync only checks for username collisions before importing a user, never for e-mail collisions. If two AD accounts carry the same mail attribute (e.g. personal account + admin account, or a shared-mailbox account), User::save() hits the unique violation, the error propagates via ?, the whole transaction is rolled back and the entire sync run fails. All other pending adds/updates/deletes of that run are lost as well.
Affected code paths
- Import: crates/defguard_core/src/enterprise/ldap/sync.rs:1133-1169 – only find_by_username is checked; user.save() at line 1169 fails on duplicate e-mail.
- Update: apply_user_modifications, sync.rs:629 – changing a user's e-mail in AD to an address already used by another Defguard user fails the same way.
- User::save() is a plain INSERT without ON CONFLICT (crates/defguard_common/src/db/models/user.rs:1138).
Steps to reproduce
- Create two AD users alice and alice-admin, both with mail = [email protected].
- Enable LDAP sync (AD, LDAP as authority).
- Trigger sync.
Actual behaviour
Sync fails with a Postgres unique-constraint error on email_unique_idx. No users from that run are imported or updated.
Expected behaviour
Same as the OIDC directory sync (directory_sync/mod.rs:867-897): detect the conflict via User::find_by_email, log an error naming both users, skip that single user and continue the sync. Ideally also surface the conflict in the sync-preview/dry-run.
Workaround
Ensure unique mail attributes in AD or exclude the conflicting account via the LDAP user search filter / sync group.
- Dominant language
- Rust
- Stars
- 2.9k
- Forks
- 121
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 68
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DefGuard/defguard
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
DefGuard/defguard#3851 · 2 comments ·
Maintainers usually reply within 1 day
-
Incorrect "Edit workflow" label for MFA flow formPossibly taken @jakub-tldr claimed this today. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 78/100
DefGuard/defguard#3844 · 2 assignees ·
Maintainers usually reply within 1 day
-
Invalid hover on the OS delete in posture check edit formPossibly taken @jakub-tldr claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
DefGuard/defguard#3842 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
DefGuard/defguard#3751 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in DefGuard/defguard
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
storytold/photocraft#5710 ·
Maintainers usually reply within 1 day
-
Two tests fail on a Windows checkout: a CRLF parse in feature_walk_tests, an 8.3 TEMP path in libraries_testsPossibly taken @CamWight claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
bherbruck/solvecraft#1186 · 1 comment ·
-
area: screenshot audit bug good first issue priority: P3 security severity: info type: correctness
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
pierruno-labs/prowl#31 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
limitlessprojects/Go-Hybrid#50 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day