Skip to content

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

@jgraichen

Description

@jgraichen

Describe the bug

I am testing Authentik with LDAP federation using a TLS-only openLDAP. The LDAP server runs on Debian Bookworm with a normal TLS setup, a valid LE cert, TLS 1.2+, etc.

The Authentik 2023.10.4 image fails to connect to that LDAP error and instead logs an SSL error. The LDAP server reports a TLS negotiation failure.

The wire trace indicates a TLS v1.0 connection failure.

To Reproduce

  1. Set up LDAP federation with an openLDAP server over LDAPS.
  2. Manually run LDAP sync.
  3. Nothing visually happens, but an error is logged in the worker.

Expected behavior

Connect to LDAP server over TLS and sync users and groups.

Logs

Error logged in worker:

{
  "event": "Task authentik.sources.ldap.tasks.ldap_sync_single[f90970f7-1710-4c07-9435-b205cbb9068a] raised unexpected: LDAPSocketOpenError(\"('socket ssl wrapping error: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)',)\")",
  "exception": [
    {
      "exc_type": "Exception",
      "exc_value": "('socket ssl wrapping error: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)',)",
      "frames": [
        {
          "filename": "/usr/local/lib/python3.11/site-packages/celery/app/trace.py",
          "line": "",
          "lineno": 477,
          "locals": {},
          "name": "trace_task"
        },
        {
          "filename": "/usr/local/lib/python3.11/site-packages/celery/app/trace.py",
          "line": "",
          "lineno": 760,
          "locals": {},
          "name": "__protected_call__"
        },
        {
          "filename": "/authentik/sources/ldap/tasks.py",
          "line": "",
          "lineno": 51,
          "locals": {},
          "name": "ldap_sync_single"
        },
        {
          "filename": "/authentik/sources/ldap/tasks.py",
          "line": "",
          "lineno": 64,
          "locals": {},
          "name": "ldap_sync_paginator"
        },
        {
          "filename": "/authentik/sources/ldap/sync/base.py",
          "line": "",
          "lineno": 30,
          "locals": {},
          "name": "__init__"
        },
        {
          "filename": "/authentik/sources/ldap/models.py",
          "line": "",
          "lineno": 174,
          "locals": {},
          "name": "connection"
        },
        {
          "filename": "/usr/local/lib/python3.11/site-packages/ldap3/core/connection.py",
          "line": "",
          "lineno": 1313,
          "locals": {},
          "name": "start_tls"
        },
        {
          "filename": "/usr/local/lib/python3.11/site-packages/ldap3/strategy/sync.py",
          "line": "",
          "lineno": 57,
          "locals": {},
          "name": "open"
        },
        {
          "filename": "/usr/local/lib/python3.11/site-packages/ldap3/strategy/base.py",
          "line": "",
          "lineno": 146,
          "locals": {},
          "name": "open"
        }
      ],
      "is_cause": false,
      "syntax_error": null
    }
  ],
  "level": "error",
  "logger": "celery.app.trace",
  "timestamp": 1701462020.284353
}

Compose logs:

goauthentik-worker-1      | {"event": "Task failure", "exc": "LDAPSocketOpenError(\"('socket ssl wrapping error: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)',)\")", "level": "warning", "logger": "authentik.root.celery", "pid": 985, "task_id": "task-f90970f717104c079435b205cbb9068a", "timestamp": "2023-12-01T20:20:20.284100"}
goauthentik-worker-1      | {"event": "Task authentik.sources.ldap.tasks.ldap_sync_single[f90970f7-1710-4c07-9435-b205cbb9068a] raised unexpected: LDAPSocketOpenError(\"('socket ssl wrapping error: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)',)\")", "exception": [{"exc_type": "Exception", "exc_value": "('socket ssl wrapping error: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)',)", "frames": [{"filename": "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", "line": "", "lineno": 477, "locals": {}, "name": "trace_task"}, {"filename": "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", "line": "", "lineno": 760, "locals": {}, "name": "__protected_call__"}, {"filename": "/authentik/sources/ldap/tasks.py", "line": "", "lineno": 51, "locals": {}, "name": "ldap_sync_single"}, {"filename": "/authentik/sources/ldap/tasks.py", "line": "", "lineno": 64, "locals": {}, "name": "ldap_sync_paginator"}, {"filename": "/authentik/sources/ldap/sync/base.py", "line": "", "lineno": 30, "locals": {}, "name": "__init__"}, {"filename": "/authentik/sources/ldap/models.py", "line": "", "lineno": 174, "locals": {}, "name": "connection"}, {"filename": "/usr/local/lib/python3.11/site-packages/ldap3/core/connection.py", "line": "", "lineno": 1313, "locals": {}, "name": "start_tls"}, {"filename": "/usr/local/lib/python3.11/site-packages/ldap3/strategy/sync.py", "line": "", "lineno": 57, "locals": {}, "name": "open"}, {"filename": "/usr/local/lib/python3.11/site-packages/ldap3/strategy/base.py", "line": "", "lineno": 146, "locals": {}, "name": "open"}], "is_cause": false, "syntax_error": null}], "level": "error", "logger": "celery.app.trace", "timestamp": 1701462020.284353}
goauthentik-worker-1      | {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 985, "state": "FAILURE", "task_id": "f90970f717104c079435b205cbb9068a", "task_name": "ldap_sync_single", "timestamp": "2023-12-01T20:20:20.284693"}

Version and Deployment (please complete the following information):

  • authentik version: 2023.10.4
  • Deployment: docker-compose

Additional context

slapd.conf:

TLSCertificateFile /etc/acme/openldap/fullchain.pem
TLSCertificateKeyFile /etc/acme/openldap/privkey.pem
TLSCACertificateFile /etc/ssl/certs/ca-certificates.crt
TLSCipherSuite NORMAL:!CIPHER-ALL:+AES-128-GCM:+AES-256-GCM:+CHACHA20-POLY1305:!COMP-ALL:+COMP-NULL

security tls=1 ssf=128

openLDAP log:

Dec 01 20:33:27 ldap slapd[1757597]: conn=1012 fd=20 ACCEPT from IP=10.72.0.217:36935 (IP=0.0.0.0:636)
Dec 01 20:33:27 ldap slapd[1757597]: conn=1012 fd=20 closed (TLS negotiation failure)
Dec 01 20:33:27 ldap slapd[1757597]: conn=1013 fd=20 ACCEPT from IP=10.72.0.217:42083 (IP=0.0.0.0:636)
Dec 01 20:33:27 ldap slapd[1757597]: conn=1013 fd=20 closed (TLS negotiation failure)

testssl of the LDAP server (no issues connecting):

> testssl ldap.example.org:636

No engine or GOST support via engine with your /usr/bin/openssl

###########################################################
    testssl       3.0.7 from https://testssl.sh/

      This program is free software. Distribution and
             modification under GPLv2 permitted.
      USAGE w/o ANY WARRANTY. USE IT AT YOUR OWN RISK!

       Please file bugs @ https://testssl.sh/bugs/

###########################################################

 Using "OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)" [~76 ciphers]
 on broadhead:/usr/bin/openssl
 (built: "Oct 13 12:02:49 2023", platform: "debian-amd64")


 Start 2023-12-01 21:11:19        -->> 10.72.253.38:636 (ldap.example.org) <<--

 rDNS (10.72.253.38):    ldap.example.org.
 Service detected:       Couldn't determine what's running on port 636, assuming no HTTP service => skipping all HTTP checks


 Testing protocols via sockets except NPN+ALPN 

 SSLv2      not offered (OK)
 SSLv3      not offered (OK)
 TLS 1      not offered
 TLS 1.1    not offered
 TLS 1.2    offered (OK)
 TLS 1.3    offered (OK): final
 NPN/SPDY   not offered
 ALPN/HTTP2 not offered

 Testing cipher categories 

 NULL ciphers (no encryption)                  not offered (OK)
 Anonymous NULL Ciphers (no authentication)    not offered (OK)
 Export ciphers (w/o ADH+NULL)                 not offered (OK)
 LOW: 64 Bit + DES, RC[2,4] (w/o export)       not offered (OK)
 Triple DES Ciphers / IDEA                     not offered
 Obsolete CBC ciphers (AES, ARIA etc.)         not offered
 Strong encryption (AEAD ciphers)              offered (OK)


 Testing robust (perfect) forward secrecy, (P)FS -- omitting Null Authentication/Encryption, 3DES, RC4 

 PFS is offered (OK)          TLS_AES_256_GCM_SHA384 TLS_CHACHA20_POLY1305_SHA256 ECDHE-ECDSA-AES256-GCM-SHA384 ECDHE-ECDSA-CHACHA20-POLY1305 TLS_AES_128_GCM_SHA256 ECDHE-ECDSA-AES128-GCM-SHA256 
 Elliptic curves offered:     prime256v1 secp384r1 secp521r1 X25519 X448 
 Finite field group:          ffdhe2048 ffdhe3072 ffdhe4096 ffdhe6144 ffdhe8192

 Testing server preferences 

 Has server cipher order?     no (NOT ok)
 Negotiated protocol          TLSv1.3
 Negotiated cipher            TLS_AES_256_GCM_SHA384, 253 bit ECDH (X25519) (limited sense as client will pick)
 Negotiated cipher per proto  (limited sense as client will pick)
     ECDHE-ECDSA-AES256-GCM-SHA384: TLSv1.2
     TLS_AES_256_GCM_SHA384:        TLSv1.3
 No further cipher order check has been done as order is determined by the client


 Testing server defaults (Server Hello) 

 TLS extensions (standard)    "EC point formats/#11" "renegotiation info/#65281" "key share/#51" "supported versions/#43" "extended master secret/#23" "max fragment length/#1"
 Session Ticket RFC 5077 hint no -- no lifetime advertised
 SSL Session ID support       no
 Session Resumption           Tickets no, ID: no
 TLS clock skew               Random values, no fingerprinting possible 
 Signature Algorithm          SHA256 with RSA
 Server key size              EC 256 bits
 Server key usage             Digital Signature
 Server extended key usage    TLS Web Server Authentication, TLS Web Client Authentication
 Serial                       03.................................. (OK: length 18)
 Fingerprints                 SHA1 sha1 2E7.....................................
                              SHA256 sha256 8DD.............................................................
 Common Name (CN)             ldap1.region1.example.org 
 subjectAltName (SAN)         ldap.example.org ldap1.region1.example.org 
 Issuer                       R3 (Let's Encrypt from US)
 Trust (hostname)             Ok via SAN (same w/o SNI)
 Chain of trust               Ok   
 EV cert (experimental)       no 
 ETS/"eTLS", visibility info  not present
 Certificate Validity (UTC)   30 >= 30 days (2023-10-03 04:12 --> 2024-01-01 04:12)
 # of certificates provided   3
 Certificate Revocation List  --
 OCSP URI                     http://r3.o.lencr.org
 OCSP stapling                not offered
 OCSP must staple extension   --
 DNS CAA RR (experimental)    not offered
 Certificate Transparency     yes (certificate extension)


 Testing vulnerabilities 

 Heartbleed (CVE-2014-0160)                not vulnerable (OK), no heartbeat extension
 CCS (CVE-2014-0224)                       not vulnerable (OK)
 Ticketbleed (CVE-2016-9244), experiment.  --   (applicable only for HTTPS)
 ROBOT                                     Server does not support any cipher suites that use RSA key transport
 Secure Renegotiation (RFC 5746)           supported (OK)
 Secure Client-Initiated Renegotiation     VULNERABLE (NOT ok), potential DoS threat
 CRIME, TLS (CVE-2012-4929)                not vulnerable (OK) (not using HTTP anyway)
 POODLE, SSL (CVE-2014-3566)               not vulnerable (OK), no SSLv3 support
 TLS_FALLBACK_SCSV (RFC 7507)              No fallback possible (OK), no protocol below TLS 1.2 offered
 SWEET32 (CVE-2016-2183, CVE-2016-6329)    not vulnerable (OK)
 FREAK (CVE-2015-0204)                     not vulnerable (OK)
 DROWN (CVE-2016-0800, CVE-2016-0703)      not vulnerable on this host and port (OK)
                                           no RSA certificate, thus certificate can't be used with SSLv2 elsewhere
 LOGJAM (CVE-2015-4000), experimental      not vulnerable (OK): no DH EXPORT ciphers, no DH key detected with <= TLS 1.2
 BEAST (CVE-2011-3389)                     not vulnerable (OK), no SSL3 or TLS1
 LUCKY13 (CVE-2013-0169), experimental     not vulnerable (OK)
 RC4 (CVE-2013-2566, CVE-2015-2808)        no RC4 ciphers detected (OK)


 Testing 370 ciphers via OpenSSL plus sockets against the server, ordered by encryption strength 

Hexcode  Cipher Suite Name (OpenSSL)       KeyExch.   Encryption  Bits     Cipher Suite Name (IANA/RFC)
-----------------------------------------------------------------------------------------------------------------------------
 x1302   TLS_AES_256_GCM_SHA384            ECDH 253   AESGCM      256      TLS_AES_256_GCM_SHA384                             
 x1303   TLS_CHACHA20_POLY1305_SHA256      ECDH 253   ChaCha20    256      TLS_CHACHA20_POLY1305_SHA256                       
 xc02c   ECDHE-ECDSA-AES256-GCM-SHA384     ECDH 253   AESGCM      256      TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384            
 xcca9   ECDHE-ECDSA-CHACHA20-POLY1305     ECDH 253   ChaCha20    256      TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256      
 x1301   TLS_AES_128_GCM_SHA256            ECDH 253   AESGCM      128      TLS_AES_128_GCM_SHA256                             
 xc02b   ECDHE-ECDSA-AES128-GCM-SHA256     ECDH 253   AESGCM      128      TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256            

Could not determine the protocol, only simulating generic clients.

 Running client simulations via sockets 

 Android 4.4.2                TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 521 bit ECDH (P-521)
 Android 5.0.0                TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256, 521 bit ECDH (P-521)
 Android 6.0                  TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256, 256 bit ECDH (P-256)
 Android 7.0 (native)         TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256, 256 bit ECDH (P-256)
 Android 8.1 (native)         TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256, 253 bit ECDH (X25519)
 Android 9.0 (native)         TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)
 Android 10.0 (native)        TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)
 Chrome 74 (Win 10)           TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)
 Chrome 79 (Win 10)           TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)
 Firefox 66 (Win 8.1/10)      TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)
 Firefox 71 (Win 10)          TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)
 IE 6 XP                      No connection
 IE 8 Win 7                   No connection
 IE 8 XP                      No connection
 IE 11 Win 7                  TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 IE 11 Win 8.1                TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 IE 11 Win Phone 8.1          TLSv1.2 ECDHE-ECDSA-AES128-GCM-SHA256, 256 bit ECDH (P-256)
 IE 11 Win 10                 TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 Edge 15 Win 10               TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 253 bit ECDH (X25519)
 Edge 17 (Win 10)             TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 253 bit ECDH (X25519)
 Opera 66 (Win 10)            TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)
 Safari 9 iOS 9               TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 Safari 9 OS X 10.11          TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 Safari 10 OS X 10.12         TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 Safari 12.1 (iOS 12.2)       TLSv1.3 TLS_CHACHA20_POLY1305_SHA256, 253 bit ECDH (X25519)
 Safari 13.0 (macOS 10.14.6)  TLSv1.3 TLS_CHACHA20_POLY1305_SHA256, 253 bit ECDH (X25519)
 Apple ATS 9 iOS 9            TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 Java 6u45                    No connection
 Java 7u25                    No connection
 Java 8u161                   TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 Java 11.0.2 (OpenJDK)        TLSv1.3 TLS_AES_128_GCM_SHA256, 256 bit ECDH (P-256)
 Java 12.0.1 (OpenJDK)        TLSv1.3 TLS_AES_128_GCM_SHA256, 256 bit ECDH (P-256)
 OpenSSL 1.0.2e               TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 256 bit ECDH (P-256)
 OpenSSL 1.1.0l (Debian)      TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, 253 bit ECDH (X25519)
 OpenSSL 1.1.1d (Debian)      TLSv1.3 TLS_AES_256_GCM_SHA384, 253 bit ECDH (X25519)
 Thunderbird (68.3)           TLSv1.3 TLS_AES_128_GCM_SHA256, 253 bit ECDH (X25519)

 Done 2023-12-01 21:11:58 [  41s] -->> 10.72.253.38:636 (ldap.example.org) <<--

Wireshark recorded TLS failure:

image

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingbug/confirmedConfirmed bugs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions