Repository navigation
Reuse the pooled LDAP admin connection instead of re-binding per operation - #50218
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an LDAP user-federation regression where the pooled admin/service-account connection was effectively re-binding on each operation when JNDI connection pooling is enabled (non-StartTLS), by ensuring credentials are present in the initial JNDI environment so the pool can reuse an already-authenticated connection.
Changes:
- Populate bind credentials in the initial LDAP context environment for non-StartTLS admin connections to allow proper JNDI pool reuse.
- Keep deferred binding for StartTLS connections (bind only after TLS negotiation).
- Add unit tests verifying anonymous vs authenticated environment construction for the admin connection setup.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPContextManager.java | Restores pre-26.6 pooling behavior by binding in the initial env for non-StartTLS while preserving deferred bind for StartTLS. |
| federation/ldap/src/test/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPContextManagerTest.java | Adds tests to validate how initial JNDI env properties are built for anonymous vs simple-auth cases. |
12d6672 to
b576ae4
Compare
b576ae4 to
eed79a0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| // Fill auth properties into the initial connection env so the bound connection can be pooled and reused. | ||
| static void setAuthConnectionProperties(Hashtable<Object, Object> connProp, LDAPConfig ldapConfig, String bindPassword) { | ||
| String authType = ldapConfig.getAuthType(); | ||
| if (authType != null) { | ||
| connProp.put(Context.SECURITY_AUTHENTICATION, authType); | ||
| } | ||
|
|
||
| if (!LDAPConstants.AUTH_TYPE_NONE.equals(authType)) { | ||
| String bindDN = ldapConfig.getBindDN(); | ||
| if (bindDN != null) { | ||
| connProp.put(Context.SECURITY_PRINCIPAL, bindDN); | ||
| } | ||
|
|
||
| if (bindPassword != null) { | ||
| connProp.put(SECURITY_CREDENTIALS, bindPassword); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I think this is a valid observation - worth adding similar debug logging after setAuthConnectionProperties() in the non-StartTLS path, or moving it to a shared spot.
There was a problem hiding this comment.
or moving it to a shared spot
I did exactly this: shared spot to avoid duplicating the masking logic. Extracted a small logConnectionProperties(Map<?, ?> env) helper and call it from both paths:
setAuthConnectionProperties()(non-StartTLS) logs the initial connection env, andsetAdminConnectionAuthProperties()(StartTLS) logs the context env after the bind properties are applied.
So the masked-credentials debug log now fires consistently in both flows, with the masking in a single place.
eed79a0 to
6138ac8
Compare
|
@pedroigor @ahus1 Could either of you trigger the CI for this PR? |
…ation Closes keycloak#50201 Signed-off-by: Rehema Owino <rehema.owino@univention.de>
6138ac8 to
c10e9f7
Compare
Closes #50201
Since 26.6.0 the LDAP user-federation admin/service-account connection is created anonymously and bound afterwards via
addToEnvironment(). With JNDI connection pooling the pooled connection stays keyed as anonymous, so the service account is re-bound (preceded by an implicit anonymous bind) on every operation, flooding the LDAP server withBINDs.For the non-StartTLS case, this restores putting the bind credentials in the initial connection environment so the bound connection can be pooled and reused, as before 26.6.0. The deferred bind is kept only for StartTLS, where the TLS negotiation must complete before the bind is sent. Full analysis and reproduction are in #50201.
Added
LDAPContextManagerTestcovering the admin connection environment for simple and anonymous auth.