sources/ldap: derive TLS SNI name from hostname, not full server URI#22456
Open
ramazanpolat wants to merge 2 commits into
Open
sources/ldap: derive TLS SNI name from hostname, not full server URI#22456ramazanpolat wants to merge 2 commits into
ramazanpolat wants to merge 2 commits into
Conversation
`LDAPSource.server()` built the TLS SNI server name from the raw `server_uri`, so an `ldaps://host` URI produced an SNI name of `ldaps://host` instead of the bare hostname `host`. ldap3 forwards that as `server_hostname` to the `ssl` module, and SNI-strict servers drop the handshake -- every LDAP sync and the connectivity check fail with `SSL: UNEXPECTED_EOF_WHILE_READING`. Build each `Server` first and take the SNI name from `server.host`, the hostname ldap3 has already parsed out of the URI (scheme and port stripped). Each server in a pool now gets its own SNI name instead of all sharing the first server's raw URI. closes goauthentik#7756 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
LDAPSource.server()builds the TLS SNI server name from the rawserver_uri:server_uriis a full LDAP URI (e.g.ldaps://ldap.example.com)..split(",")[0].strip()only handles the comma-separated multi-server case andtrims whitespace — it does not strip the
ldap:///ldaps://scheme or a:port. The resulting value is passed asTls(sni=...), which ldap3 forwardsas
server_hostnameto Python'ssslmodule.A TLS SNI name must be a bare DNS hostname. Sending
ldaps://ldap.example.comas the SNI name causes SNI-strict servers / load balancers (common for TLS 1.3
load-balanced endpoints) to drop the handshake, so every LDAP sync and the
connectivity check fail with:
This makes the "Use Server URI for SNI verification" toggle strictly worse than
leaving it off for any such endpoint.
Fix
Build each
Serverfirst and derive the SNI name fromserver.host— thehostname ldap3 has already parsed out of the URI (scheme and port stripped).
This also addresses a related point raised in #7756: every server in a
ServerPoolpreviously shared the first server's raw URI as its SNI name;each server now gets its own correct SNI name.
Verified against ldap3 2.9.1 —
Server(uri).hoststripsldap:///ldaps://and
:portforhost,host:port,ldap://host,ldaps://host, andldaps://host:port.closes #7756
Checklist
ak test authentik/)make lint-fix)