Skip to content

[9.5] fix(outlook): retry LDAP user searches with fresh connections (#4441) - #4464

Merged
Jan-Kazlouski-elastic merged 1 commit into
9.5from
backport/9.5/pr-4441
Sep 9, 2026
Merged

Jan-Kazlouski-elastic merged 1 commit into
9.5from
backport/9.5/pr-4441

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Backports the following commits to 9.5:

Part of elastic/sdh-search#1898

## Problem

On large on-prem Exchange deployments the Outlook Server connector
enumerates users from Active Directory via LDAP before opening each
mailbox over EWS. `ExchangeUsers` kept a single cached `ldap3`
connection for both the normal-user and admin-user searches.

`get_user_accounts()` consumes users lazily: it yields each normal user,
the sync processes that mailbox (often for hours), then continues. The
admin-user LDAP search can therefore run days after the first bind. AD
or intermediate network gear often drops the idle TCP session, and the
next search fails with errors such as:

```
UsersFetchFailed: Something went wrong while fetching users. Error: socket sending error[Errno 104] Connection reset by peer
```

Unlike the Office365 Graph path, LDAP had no retry layer. A single
transient failure aborted the entire sync. A customer on SDH #1898 hit
this after indexing 4.2M+ documents over ~45 hours.

## Fix

- Replace the cached LDAP connection with a fresh `Connection` per
search.
- Add `_ldap_search()` with the existing `@retryable` settings
(`RETRIES`, `RETRY_INTERVAL`, exponential backoff) and
`skipped_exceptions=[UsersFetchFailed]` so empty LDAP results are not
retried.
- Unbind after each search attempt.
- Refactor `_fetch_normal_users` / `_fetch_admin_users` to call the
shared helper.

## Checklists

#### Pre-Review Checklist
- [x] this PR does NOT contain credentials of any kind, such as API keys
or username/passwords (double check `config.yml.example`)
- [x] this PR has a meaningful title
- [x] this PR links to all relevant github issues that it fixes or
partially addresses
- [x] if there is no GH issue, please create it. Each PR should have a
link to an issue
- [x] this PR has a thorough description
- [x] Covered the changes with automated tests
- [x] Tested the changes locally
- [ ] Added a label for each target release version (example: `v7.13.2`,
`v7.14.0`, `v8.0.0`)
- [ ] For bugfixes: backport safely to all minor branches still
receiving patch releases
- [x] Considered corresponding documentation changes
- [x] Contributed any configuration settings changes to the
configuration reference
- [x] if you added or changed Rich Configurable Fields for a Native
Connector, you made a corresponding PR in
[Kibana](https://github.com/elastic/kibana/blob/main/packages/kbn-search-connectors/types/native_connectors.ts)

#### Changes Requiring Extra Attention

- [ ] Security-related changes (encryption, TLS, SSRF, etc)
- [ ] New external service dependencies added.

## Related Pull Requests

* #4406 — skip accounts with
non-primary SMTP addresses
* #4078 — skip AD users
without a valid `mail` attribute
* #4094 — per-account EWS
error handling and TLS hardening

## Release Note

**Outlook Server connector**: LDAP user enumeration now opens a fresh
Active Directory connection per search and retries transient network
failures instead of aborting long syncs when the admin-user query runs
on a stale connection.

Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@Jan-Kazlouski-elastic
Jan-Kazlouski-elastic enabled auto-merge (squash) September 9, 2026 11:20
@Jan-Kazlouski-elastic
Jan-Kazlouski-elastic merged commit fe4a753 into 9.5 Sep 9, 2026
2 checks passed
@Jan-Kazlouski-elastic
Jan-Kazlouski-elastic deleted the backport/9.5/pr-4441 branch September 9, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants