Skip to content

sources/ldap: derive TLS SNI name from hostname, not full server URI - #22456

Merged
BeryJu merged 3 commits into
goauthentik:mainfrom
ramazanpolat:fix/ldap-source-sni-hostname
Jul 13, 2026
Merged

BeryJu merged 3 commits into
goauthentik:mainfrom
ramazanpolat:fix/ldap-source-sni-hostname

Conversation

@ramazanpolat

Copy link
Copy Markdown
Contributor

Details

LDAPSource.server() builds the TLS SNI server name from the raw server_uri:

if self.sni:
    tls_kwargs["sni"] = self.server_uri.split(",", maxsplit=1)[0].strip()

server_uri is a full LDAP URI (e.g. ldaps://ldap.example.com).
.split(",")[0].strip() only handles the comma-separated multi-server case and
trims whitespace — it does not strip the ldap:// / ldaps:// scheme or a
:port. The resulting value is passed as Tls(sni=...), which ldap3 forwards
as server_hostname to Python's ssl module.

A TLS SNI name must be a bare DNS hostname. Sending ldaps://ldap.example.com
as 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:

LDAPSocketOpenError: socket ssl wrapping error:
[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol

This makes the "Use Server URI for SNI verification" toggle strictly worse than
leaving it off for any such endpoint.

Fix

Build each Server first and derive the SNI name from server.host — the
hostname 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
ServerPool previously 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).host strips ldap:// / ldaps://
and :port for host, host:port, ldap://host, ldaps://host, and
ldaps://host:port.

closes #7756


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

`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) <[email protected]>
@netlify

netlify Bot commented May 19, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit e705df5
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a0bbbb9dca569000862137b
😎 Deploy Preview https://deploy-preview-22456--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.21%. Comparing base (c61f818) to head (d9f235e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #22456      +/-   ##
==========================================
- Coverage   93.25%   93.21%   -0.04%     
==========================================
  Files        1044     1045       +1     
  Lines       61191    61206      +15     
  Branches      424      424              
==========================================
- Hits        57062    57054       -8     
- Misses       4129     4152      +23     
Flag Coverage Δ
conformance 36.21% <0.00%> (-0.01%) ⬇️
e2e 41.38% <19.04%> (-0.01%) ⬇️
integration 32.14% <0.00%> (-0.50%) ⬇️
rust 0.00% <ø> (ø)
unit 92.35% <100.00%> (+0.02%) ⬆️
unit-migrate 92.38% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@BeryJu
BeryJu merged commit d91e9fb into goauthentik:main Jul 13, 2026
112 of 115 checks passed
kensternberg-authentik added a commit that referenced this pull request Jul 13, 2026
* main: (30 commits)
  providers/saml: catch InvalidVersion from cryptography when parsing metadata (#21185)
  stages/user_login: refuse to log in an unsaved pending user (#21691)
  web/admin: hide previous loglist when no previous logs available (#23954)
  stages/email: fix ungrammatical expiry time in password reset templates (#22758)
  tests/openid_conformance: Add more conformance coverage (#22174)
  sources/ldap: derive TLS SNI name from hostname, not full server URI (#22456)
  core: bump github.com/grafana/pyroscope-go from 1.3.1 to 1.4.0 (#23885)
  web: Fix Log Viewer Intersection Observer. (#23861)
  web: bump the goauthentik group across 1 directory with 2 updates (#23926)
  ci: bump regclient/actions/regctl-login from 4b4db1dcc7dad75ad67a788a380f75a20cc8a040 to 39bf30ced4be9d147faaabbde2682e9725fb8bd1 (#23890)
  ci: bump regclient/actions/regctl-installer from 4b4db1dcc7dad75ad67a788a380f75a20cc8a040 to 39bf30ced4be9d147faaabbde2682e9725fb8bd1 (#23891)
  core: bump pnpm/pnpm from 11.10.0 to 11.11.0 in /website (#23930)
  core: bump pnpm/pnpm from 11.10.0 to 11.11.0 in /lifecycle/container (#23927)
  core: bump github.com/sethvargo/go-envconfig from 1.3.0 to 1.3.1 (#23921)
  core: bump goauthentik/selenium from 149.0-ak-0.50.1 to 149.0-ak-0.50.2 in /tests/e2e (#23924)
  core: bump uvicorn[standard] from 0.49.0 to 0.50.0 (#23925)
  core: bump ruff from 0.15.20 to 0.15.21 (#23928)
  core: bump goauthentik/fips-python from `aaaab46` to `0798f3b` in /lifecycle/container (#23929)
  ci: bump actions/stale from 10.3.0 to 10.4.0 (#23935)
  ci: bump github/codeql-action/autobuild from 4.36.3 to 4.37.0 (#23931)
  ...
kensternberg-authentik added a commit that referenced this pull request Jul 13, 2026
* main: (48 commits)
  web/bug: harmonize and make routine the display of tasks (part 2: description list abuse) (#23839)
  providers/oauth2: fix iframe logout stage progression (#23919)
  providers/scim: improve error display when error doesn't conform to scim schema (#23955)
  providers/saml: catch InvalidVersion from cryptography when parsing metadata (#21185)
  stages/user_login: refuse to log in an unsaved pending user (#21691)
  web/admin: hide previous loglist when no previous logs available (#23954)
  stages/email: fix ungrammatical expiry time in password reset templates (#22758)
  tests/openid_conformance: Add more conformance coverage (#22174)
  sources/ldap: derive TLS SNI name from hostname, not full server URI (#22456)
  core: bump github.com/grafana/pyroscope-go from 1.3.1 to 1.4.0 (#23885)
  web: Fix Log Viewer Intersection Observer. (#23861)
  web: bump the goauthentik group across 1 directory with 2 updates (#23926)
  ci: bump regclient/actions/regctl-login from 4b4db1dcc7dad75ad67a788a380f75a20cc8a040 to 39bf30ced4be9d147faaabbde2682e9725fb8bd1 (#23890)
  ci: bump regclient/actions/regctl-installer from 4b4db1dcc7dad75ad67a788a380f75a20cc8a040 to 39bf30ced4be9d147faaabbde2682e9725fb8bd1 (#23891)
  core: bump pnpm/pnpm from 11.10.0 to 11.11.0 in /website (#23930)
  core: bump pnpm/pnpm from 11.10.0 to 11.11.0 in /lifecycle/container (#23927)
  core: bump github.com/sethvargo/go-envconfig from 1.3.0 to 1.3.1 (#23921)
  core: bump goauthentik/selenium from 149.0-ak-0.50.1 to 149.0-ak-0.50.2 in /tests/e2e (#23924)
  core: bump uvicorn[standard] from 0.49.0 to 0.50.0 (#23925)
  core: bump ruff from 0.15.20 to 0.15.21 (#23928)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LDAP Source URI is parsed incorrectly which leads to invalid SNI configuration

2 participants