Repository navigation
Fixes #14601: Health-check pooled LDAP connections and show the directory on the Health Check page - #34649
Conversation
…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>
…ealth-check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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>
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. OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
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 stuckSend-Qin the issue) and waited out the SDK's 5-minute default search response timeout.LdapAuthenticatorthen retries up to three times, possibly on another dead pooled connection.This PR:
GetEntryLDAPConnectionPoolHealthCheckreads 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).setRetryFailedOperationsDueToInvalidConnections(true)).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.LdapAuthenticatorandLdapAuthServletHandlerand 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.reinitializeAuthSystemnow calls a new defaultclose()onAuthenticatorHandlerandAuthServeletHandlerfrom afinally, 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./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 toLdapAuthenticatorso 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:
High-level design:
Approach. Use the SDK's own pool health check rather than a custom one.
GetEntryLDAPConnectionPoolHealthCheckon 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.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
maxPoolSizeof 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/openldapimage) answers the probe both bound and anonymously; Active Directory and 389-DS serve the root DSE anonymously by design.Health Check page entry.
LdapDirectoryValidationopens 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.validateSystemadds it as theLDAPentry 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.
ldapConfigurationfields 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 (checkedopenmetadata-collatemain). The values are constants: no schema, migration or configuration change.Tests:
Use cases covered
LdapAuthenticatorreleases its directory connections, andLdapAuthServletHandler.close()closes its authenticator.PUT) still reloads cleanly with the newclose()calls.Unit tests
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.aLookupIsNotStalledByAPooledConnectionThatStoppedAnsweringfails 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.aRejectedLookupBindDoesNotLeaveItsConnectionOpenwas mutation-checked: removing theclose()on bind failure makes it fail.closingTheAuthenticatorReleasesItsDirectoryConnectionsLdapAuthServletHandlerTest:close_releasesTheAuthenticatorConnectionPoolOpenMetadataApplicationAuthReloadTest(new): a reload closes the handlers it replaced, even when it failed after the swap; leaves open the ones it never replaced; and aclose()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 exactlyCould not connect to <host>:<port>: Connection refusedwhen nothing listens.SystemRepositoryLdapStatusTest(new): the status gets anLDAPentry when LDAP is the provider, and none under Basic (even with LDAP settings still saved) or with no auth configuration.org.openmetadata.service.securityplus allSystemRepository*Testclasses passed (1070).openmetadata-mcpcompiles against the changed interface.LdapDirectoryValidation30/30,LdapAuthenticator26/27 (the uncovered line is the renamed factory call insideinit),SystemRepository8/9,OpenMetadataApplication8/15,TestLoginCredentialHandler4/4,LdapAuthServletHandler2/2. The other uncovered lines are the handler capture andfinallycall inreinitializeAuthSystem(7), the two no-op interface defaults (2) and thevalidateSystemcall (1). The integration tests below exercise those 10, but ITs are not JaCoCo-instrumented.Backend integration tests
openmetadata-integration-tests/for new/changed API endpoints.SystemResourceIT.test_getSystemStatusnow asserts that/v1/system/statushas noLDAPentry 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.SystemResourceIT#test_getSystemStatusand#test_getSystemHealthCheck(2/2 passed), and#test_updateSecurityConfig*(2/2 passed, re-run after thefinallychange; the server logged six security reloads through the newclose()calls, all successful).Ingestion integration tests
Playwright (UI) tests
Manual testing performed
"", filter(objectClass=*), attributes1.1) against OpenLDAP 2.6.7, the repo'sdocker/local-sso/openldapimage: one entry returned, both bound as the lookup account and anonymously.LdapLookupConnectionPoolTestreproduces deterministically. The nightlySsoScenarios.spec.ts@ldapleg will exercise the probe on a real login.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.Known gap, proposed as a follow-up: MCP builds its own
LdapAuthenticatoronce inMcpServerand 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