Hello there,
I have encountered a strange behavior of my traefik2 setup when proxying via a tcp router to an OpenLDAP server and wanted to share my struggles here before creating an issue on Github. Maybe I'm just too stupid to get this configured properly
This all is on traefik version 2.1.1 which is running in a docker container.
The main parts of the traefik.yaml:
entryPoints:
ldap-entrypoint:
address: ":637"
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
network: web
certificatesResolvers:
leresolver:
acme:
email: "letsencrypt@example.com"
storage: "acme.json"
tlsChallenge: {}
And here ldap/docker-compose.yml defining the OpenLDAP container:
version: '3'
services:
ldap:
image: osixia/openldap:1.2.2
restart: always
environment:
- LDAP_ORGANISATION=example
- LDAP_DOMAIN=example.com
- LDAP_ADMIN_PASSWORD=example
- LDAP_TLS_VERIFY_CLIENT=try
- LDAP_TLS_CRT_FILENAME=fullchain.cer
- LDAP_TLS_KEY_FILENAME=example.key
- LDAP_TLS_CA_CRT_FILENAME=ca.cer
ports:
- "636:636"
expose:
- 389
volumes:
- sso_ldap:/var/lib/ldap
- sso_slapd:/etc/ldap/slapd.d
- sso_certs:/container/service/slapd/assets/certs
networks:
- web
labels:
- "traefik.enable=true"
- "traefik.docker.network=web"
- "traefik.tcp.routers.app-sso-ldap.rule=HostSNI(`ldap.example.com`)"
- "traefik.tcp.routers.app-sso-ldap.entrypoints=ldap-entrypoint"
- "traefik.tcp.routers.app-sso-ldap.tls=true"
- "traefik.tcp.routers.app-sso-ldap.tls.certresolver=leresolver"
- "traefik.tcp.routers.app-sso-ldap.service=app-sso-ldap"
- "traefik.tcp.services.app-sso-ldap.loadbalancer.server.port=389"
This runs perfectly fine with tls using the published port 636. The non-tls port 389 is exposed and configured as the service port for traefik to connect to.
Now I verified, that traefik successfully created a valid certificate and terminates a tls connection properly with openssl:
>openssl s_client -connect ldap.example.com:637
CONNECTED(00000003)
depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3
verify return:1
depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
verify return:1
depth=0 CN = ldap.example.com
verify return:1
---
Certificate chain
0 s:CN = ldap.example.com
i:C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
1 s:C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
i:O = Digital Signature Trust Co., CN = DST Root CA X3
---
Server certificate
-----BEGIN CERTIFICATE-----
XXXXXXXXXXXXXXXXXXXX
-----END CERTIFICATE-----
subject=CN = ldap.example.com
issuer=C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 3636 bytes and written 406 bytes
Verification: OK
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 4096 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol : TLSv1.3
Cipher : TLS_AES_256_GCM_SHA384
Session-ID: XXX
Session-ID-ctx:
Resumption PSK: XXX
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 604800 (seconds)
TLS session ticket:
XXX
Start Time: 1579300651
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
Max Early Data: 0
---
read R BLOCK
^C
Which results in following openldap log output:
5e2236c6 conn=1000 fd=12 ACCEPT from IP=172.18.0.2:33156 (IP=0.0.0.0:389)
5e2236c7 conn=1000 fd=12 closed (connection lost)
This indicates that the tls connection can be opened and should be configured properly, also the certificate should be accepted as I already verified letsencrypt certificates on ldap servers as working.
But the debug log of ldapwhoami show following on a connection attempt to the same port as openssl:
> ldapwhoami -v -d 2 -H ldaps://ldap.example.com:637/ -D cn=user,ou=people,dc=example,dc=com -w example
ldap_initialize( ldaps://ldap.example.com:637/??base )
tls_write: want=293, written=293
...
TLS certificate verification: Error, unable to get local issuer certificate
tls_write: want=7, written=7
0000: 15 03 03 00 02 02 30 ......0
TLS: can't connect: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed (unable to get local issuer certificate).
ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)
Additionally no output is generated in the ldap logs, so this connection is definitely being killed by traefik somehow.
Any clue what could have lead to this?
If anything is missing for further analysis I am happy to provide more information.
If this is not an issue with traefik itself I would try to address this issue somewhere else.
Otherwise thanks in advance for any hint and best regards,
djesionek