Repository navigation
Conversation
StartTLS wrapped the connection with a tls.Config that had no ServerName. tls.Client does not derive it from the address (tls.Dial does, which is why ldaps:// worked), so with certificate verification on every upgrade failed with "either ServerName or InsecureSkipVerify must be specified" and an ldap:// directory could only be used with allow_insecure or skip_tls_verify. LDAPConnect now sets ServerName from the URL host for both StartTLS and ldaps://. The admin console's Connect (auto-discover) and the Kerberos setup, cleanup and import paths dialled with ldaplib.DialURL and bound directly. On ldap:// that sent the service-account (or AD admin) password in cleartext, ignoring the StartTLS policy, and auto-discover reported success for a config that then refused every login. They now connect through auth.LDAPConnect. Tests use a small in-process LDAP server (internal/ldaptest) that answers StartTLS and records every operation sent before TLS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
An
ldap://directory link can't be used with certificate verification. A verified StartTLS upgrade always fails:So the documented default (
ldap://= StartTLS) never works. Operators are pushed toallow_insecure(cleartext) orskip_tls_verify(unverified), and the admin console offers neither switch.Separately, the console's Connect button (auto-discover) and the Kerberos setup paths bind without StartTLS. They send the password in cleartext on
ldap://even though the saved config requires StartTLS.1. StartTLS had no
ServerNameLDAPConnectpassed&tls.Config{InsecureSkipVerify: cfg.SkipTLSVerify}toconn.StartTLS.tls.Client, which does not deriveServerNamefrom the address.ldaps://worked only because go-ldap dials it withtls.DialWithDialer, which does derive it.Change:
ldapTLSConfig(url, skipVerify)setsServerNamefrom the URL host and is used for both StartTLS andldaps://. It also adds an unexportedldapRootCAs(nil = system pool, which honoursSSL_CERT_FILE) so tests can supply their own CA.2. Admin paths bypassed the TLS policy
These four call sites dialled with
ldaplib.DialURLand bound directly:ldap://handleAutoDiscoverLDAP(console Connect)handleSetupKerberosautoSetupKerberos(import)handleCleanupKerberosAuto-discover then saved a config with
allow_insecureunset. The console said "Connected", and every login failed with the StartTLS error above.Change: all four now connect through
auth.LDAPConnect, so they follow exactly the policy logins use. Auto-discover uses the same TLS mode the saved config will have, so Connect fails fast with the real reason instead of reporting success.Verification
Unit tests. The new tests use
internal/ldaptest, a small in-process LDAP server. It answers StartTLS (or refuses it) and records every operation sent before TLS.TestLDAPConnectStartTLSVerifiesCertificateServerNameerrorTestLDAPConnectStartTLSRejectsWrongHostTestLDAPConnectStartTLSSkipVerifyskip_tls_verifystill worksTestLDAPConnectLDAPSVerifiesCertificateldaps://unchangedTestLDAPTLSConfigServerNameTestAutoDiscoverDoesNotBindInCleartext0x63) in cleartextTestSetupKerberosDoesNotBindInCleartext0x60) with the password in cleartextgo test ./...is green,go vetandgofmtare clean, andgo test -raceis clean on the new tests.End to end: a Samba AD DC whose LDAP certificate comes from an internal CA, with SimpleAuth trusting that CA via
SSL_CERT_FILE. The console's Connect was called with a bare host name.dc1.green.orgldap://dc1.green.org:389POST /api/admin/ldap/testStartTLS upgrade failed … ServerName{"status":"ok"}(certificate verified)Behaviour change
On an
ldap://directory that cannot do StartTLS (no LDAP certificate), console Connect and Kerberos setup now fail with the StartTLS error. Before, they "succeeded" by binding in cleartext, but every login on that config failed anyway, because the saved config never hadallow_insecure. Cleartext directories still needallow_insecure: true, exactly as for logins.🤖 Generated with Claude Code