Q&A How can I query Samba/AD LDAP using Kerberos and TLS

Question

How can LDAP data be retrieved from a UCS Samba/AD domain controller using a Kerberos ticket over TLS?

Answer

Use ldapsearch with SASL/GSSAPI and TLS channel binding. On a UCS Samba/AD domain controller, port 636 accesses the Samba/AD directory, not UCS OpenLDAP.

Obtain a Kerberos ticket if no valid ticket is available:

kinit Administrator
klist

Use the following query to get the user data:

LDAPSASL_CBINDING=tls-endpoint \
ldapsearch -LLL -Q -N -Y GSSAPI -O minssf=0,maxssf=0 \
  -H "ldaps://$(ucr get hostname).$(ucr get domainname):636" \
  -b "$(ucr get samba4/ldap/base)" \
  '(&(objectClass=user)(sAMAccountName=Administrator))' \
  sAMAccountName displayName mail memberOf

Run the query as the user who holds the Kerberos ticket.

  • LDAPSASL_CBINDING=tls-endpoint binds Kerberos authentication to the TLS connection.
  • minssf=0,maxssf=0 disables the additional SASL security layer; TLS provides transport encryption.
  • Without valid channel binding, the client may report 80090346 … data 35b, while Samba logs Got GSS_S_BAD_BINDINGS.

To explicitly require server certificate verification, repeat the query with LDAPTLS_REQCERT=demand added before ldapsearch. This verification step remains to be performed in the reported case.

If the issuing CA is not already trusted by the client, also specify:

LDAPTLS_CACERT=/etc/univention/ssl/ucsCA/CAcert.pem

Apply these variables to the same command. Do not disable certificate verification or weaken Samba’s channel-binding requirements.