Skip to content

Fixes #14601: Health-check pooled LDAP connections and show the directory on the Health Check page - #34649

Merged
mohityadav766 merged 5 commits into
mainfrom
fix/14601-ldap-pool-health-check
Oct 5, 2026
Merged

mohityadav766 merged 5 commits into
mainfrom
fix/14601-ldap-pool-health-check

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #14601

LDAP logins could hang for minutes once a firewall, NAT gateway or load balancer silently dropped an idle connection in the LDAP lookup pool. The pool used the UnboundID SDK's default health check, which never probes a connection, so the dead socket still looked ESTABLISHED. The next login's user search was written into it (the stuck Send-Q in the issue) and waited out the SDK's 5-minute default search response timeout. LdapAuthenticator then retries up to three times, possibly on another dead pooled connection.

This PR:

  • Health-checks the lookup pool. A GetEntryLDAPConnectionPoolHealthCheck reads the root DSE before each checkout, every 60 s in the background, and after a connection-level error. A connection that stays silent for 5 s is replaced, so a login waits about 5 s per dead connection instead of 5 minutes. The background probe also keeps idle connections alive through load balancer and firewall idle timeouts (Azure Load Balancer defaults to 4 min, AWS NLB to 350 s).
  • Retries a search once on a fresh connection when its connection turns out to be dead, e.g. after a directory restart (setRetryFailedOperationsDueToInvalidConnections(true)).
  • Opens pool connections through the existing openConnection, the path the password bind and Test Login already use, which removes a duplicated SSL branch. The socket is closed explicitly when the lookup bind is rejected; the old constructor did that internally.
  • Closes the handlers a security reload replaces. Every SSO settings save built new LDAP pools for LdapAuthenticator and LdapAuthServletHandler and abandoned the old ones without closing them. With background probes, those leftover pools would keep probing the directory even after the provider moved away from LDAP. reinitializeAuthSystem now calls a new default close() on AuthenticatorHandler and AuthServeletHandler from a finally, on every handler the reload replaced, including when the reload fails after the swap. A handler it never replaced is still serving logins and stays open. The LDAP implementations close their pool; every other handler keeps the no-op default.
  • Adds an LDAP entry to the Health Check page (Settings → Preferences → Health Check, backed by /v1/system/status), only when the provider is LDAP. It connects the way login does, with 5 s timeouts, binds as the lookup account and reads the user base DN, and names the step that failed: unreachable host, rejected lookup account, or missing user base DN. The page renders status entries generically, so there is no UI change. The fail-fast connection options Test Login already used moved to LdapAuthenticator so both share them.

The pool and the Health Check entry only exist when the provider is LDAP, so nothing changes for Basic, OIDC or SAML deployments.

Type of change:

  • Bug fix

High-level design:

Approach. Use the SDK's own pool health check rather than a custom one. GetEntryLDAPConnectionPoolHealthCheck on the root DSE ("") is the SDK's standard liveness probe, and the same query Spring LDAP's pool validator sends by default: a base-scope read that directories answer without touching user data.

Hook On Why
checkout yes never hand a silent connection to a login; bounded by the 5 s probe timeout
background, every 60 s yes find dead idle connections between logins, and keep middleboxes from treating them as idle
after an exception yes this check does not fall back to the base class's "retire on a connection-level result code"; with it off, a connection would never be retired after an error
create, release no a freshly bound connection is known good; probing on release adds a round trip for nothing

Cost. One extra base-scope read per pooled operation (a login makes one or two). In the background, one read per pooled connection per minute: with the default maxPoolSize of 3 and up to three pools per server (the app authenticator, the auth servlet's, MCP's), 9 reads a minute.

If a directory refuses root-DSE reads. The probe then fails on every checkout, but the SDK falls back to handing out a freshly created connection without probing it, so logins keep working and the pool just reconnects more. OpenLDAP 2.6.7 (the repo's docker/local-sso/openldap image) answers the probe both bound and anonymously; Active Directory and 389-DS serve the root DSE anonymously by design.

Health Check page entry. LdapDirectoryValidation opens a fresh connection rather than borrowing one from the pool, so the entry answers "can a login reach the directory with the current settings", which is what an admin needs when logins hang. SystemRepository.validateSystem adds it as the LDAP entry only when the current provider is LDAP, keyed off the provider rather than the presence of saved LDAP settings, which survive a switch to another provider. That matches how the S3 log-storage and semantic-search entries only appear when configured. Messages give the root reason, e.g. Could not connect to ldap.example.com:636: Connection refused, instead of the SDK's nested wrapper text. Like the existing "Connected to " entry, it names the host; on a rejected bind it names the lookup DN, never the password.

Alternatives rejected.

  • A shorter search response timeout: a login would still wait the full timeout before retrying, and it would cut off legitimately slow recursive group lookups on large AD forests.
  • New ldapConfiguration fields for the interval and timeout: schema, UI and docs surface for values no deployment should need to tune, while the SSO epic (EPIC - SSO stability and a simpler setup #34298) is removing knobs. Easy to add later if one turns out to be needed.

Compatibility. close() is a default method on both interfaces, and no Collate class implements either (checked openmetadata-collate main). The values are constants: no schema, migration or configuration change.

Tests:

Use cases covered

  • A pooled LDAP connection that a middlebox silently dropped no longer stalls the user lookup: it is detected within the 5 s probe timeout and replaced.
  • A rejected lookup bind does not leave its socket open.
  • Closing an LdapAuthenticator releases its directory connections, and LdapAuthServletHandler.close() closes its authenticator.
  • An SSO settings save (security config PUT) still reloads cleanly with the new close() calls.
  • With LDAP as the provider, the Health Check page reports whether the directory is reachable, accepts the lookup account and has the user base DN; with any other provider there is no LDAP entry, even when LDAP settings are still saved.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated:
    • LdapLookupConnectionPoolTest (new). A real in-process UnboundID directory reached through a TCP relay that can silence the connections it already holds, which is what a dropped connection looks like from the client side. Nothing is mocked.
      • aLookupIsNotStalledByAPooledConnectionThatStoppedAnswering fails without the fix: the lookup is still blocked when the test's 30 s limit hits, and the SDK would wait 5 min. With the fix it passes in about 5 s.
      • aRejectedLookupBindDoesNotLeaveItsConnectionOpen was mutation-checked: removing the close() on bind failure makes it fail.
      • closingTheAuthenticatorReleasesItsDirectoryConnections
    • LdapAuthServletHandlerTest: close_releasesTheAuthenticatorConnectionPool
    • OpenMetadataApplicationAuthReloadTest (new): a reload closes the handlers it replaced, even when it failed after the swap; leaves open the ones it never replaced; and a close() that throws neither escapes nor skips the other handler.
    • LdapDirectoryValidationTest (new), against a real in-process directory: passes when reachable with valid lookup credentials; fails and names the account on a rejected bind; fails and names the DN when the user base DN is missing; fails with the directory's reason for a malformed user base DN; fails with exactly Could not connect to <host>:<port>: Connection refused when nothing listens.
    • SystemRepositoryLdapStatusTest (new): the status gets an LDAP entry when LDAP is the provider, and none under Basic (even with LDAP settings still saved) or with no auth configuration.
  • Every test under org.openmetadata.service.security plus all SystemRepository*Test classes passed (1070). openmetadata-mcp compiles against the changed interface.
  • Coverage %: JaCoCo, unit tests only, on changed lines: 78/89 (87.6%). The new LdapDirectoryValidation 30/30, LdapAuthenticator 26/27 (the uncovered line is the renamed factory call inside init), SystemRepository 8/9, OpenMetadataApplication 8/15, TestLoginCredentialHandler 4/4, LdapAuthServletHandler 2/2. The other uncovered lines are the handler capture and finally call in reinitializeAuthSystem (7), the two no-op interface defaults (2) and the validateSystem call (1). The integration tests below exercise those 10, but ITs are not JaCoCo-instrumented.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • SystemResourceIT.test_getSystemStatus now asserts that /v1/system/status has no LDAP entry on the Basic-auth test server. The LDAP-provider case is covered by the unit tests above, because switching the shared IT server's live provider to LDAP would disturb the suites running alongside it.
  • Ran on MySQL + Elasticsearch: SystemResourceIT#test_getSystemStatus and #test_getSystemHealthCheck (2/2 passed), and #test_updateSecurityConfig* (2/2 passed, re-run after the finally change; the server logged six security reloads through the new close() calls, all successful).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • Ran the probe's exact query (base-scope search on "", filter (objectClass=*), attributes 1.1) against OpenLDAP 2.6.7, the repo's docker/local-sso/openldap image: one entry returned, both bound as the lookup account and anonymously.
  • Not tested against a live OpenMetadata + LDAP deployment behind a real firewall. The failure needs a middlebox that drops established connections while still accepting new ones, which LdapLookupConnectionPoolTest reproduces deterministically. The nightly SsoScenarios.spec.ts @ldap leg will exercise the probe on a real login.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. (N/A: no schema change)
  • For UI changes: I attached a screen recording and/or screenshots above. (N/A: no UI change)
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

Known gap, proposed as a follow-up: MCP builds its own LdapAuthenticator once in McpServer and never rebuilds it on an SSO reload; this PR does not change that. After a switch away from LDAP, that pool (3 connections by default) keeps running, now with probes, until the server restarts, and MCP keeps validating MCP logins against the old provider. Fixing it means rebuilding MCP's credential authenticator on reload.

🤖 Generated with Claude Code

…annot stall login

The LDAP lookup pool used the SDK's default health check, which never probes a
connection. When a firewall or load balancer silently drops an idle pooled
connection, the next login's user search waits out the SDK's five-minute search
response timeout, and the login retry can repeat that on another dead connection.

- Probe each pooled connection with a root DSE read before checkout, every 60 s
  in the background, and after a connection error; a connection that stays
  silent for 5 s is replaced. The background probe also keeps idle connections
  alive through load balancer and firewall idle timeouts.
- Retry a search once on a fresh connection when its connection turns out dead.
- Open pool connections through the same openConnection path as the password
  check and Test Login, and close the socket when the lookup bind is rejected.
- Close the handlers a security reload replaces, so their LDAP pools stop
  probing the directory once the provider is no longer LDAP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mohityadav766
mohityadav766 requested a review from a team as a code owner October 5, 2026 09:52
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 5, 2026
@mohityadav766 mohityadav766 self-assigned this Oct 5, 2026
@mohityadav766 mohityadav766 changed the title Fixes #14601: Health-check pooled LDAP connections so a dropped one cannot stall login Fixes #14601: Health-check pooled LDAP connections and show the directory on the Health Check page Oct 5, 2026
…ealth-check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mohityadav766 and others added 2 commits October 5, 2026 21:06
…4601)

A reload swaps in the new handlers before it initializes the authenticator, so
one that fails afterwards (an unreachable directory, a wrong lookup password)
left the replaced handlers open with nothing routing to them, and an LDAP one
kept probing the old directory. Close whatever the reload replaced in a
finally. A handler it never replaced is still serving logins and stays open,
and a failing close is logged rather than thrown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Oct 5, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · LDAP login connection checks, retries, and reload cleanup change authentication behavior.

Fixes LDAP connection pool stalling by adding health checks that detect dropped connections within 5 seconds instead of timing out after 5 minutes, retrying on fresh connections when needed, and closing pools on SSO settings reloads. Also adds an LDAP health-check entry to the status page showing directory reachability and lookup account validity. Comprehensive unit and integration tests cover pool health checks, connection cleanup, handler closure on reload, and directory validation. No issues found.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Healthcheck for LDAPConnectionPool

2 participants