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>
The fake directory only completed the TLS handshake and then discarded everything, so tests could not exercise anything that binds (the /test endpoint, auto-discover). Once a connection is secured it now answers a bind (any credentials succeed), a RootDSE search (defaultNamingContext = NamingContext) and any other search (no entries). Also adds StartPlainServer, a cleartext directory that refuses StartTLS (for allow_insecure paths), and CA.PEM, the CA certificate as an operator would paste it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
An AD whose domain controllers have certificates from an internal root CA could only be used with skip_tls_verify (unverified) or by adding the CA to the host's trust store; the console offered neither. ca_cert: new LDAP config field (JSON "ca_cert") holding the PEM of one or more CA certificates. LDAPConnect adds them to the system pool and uses that pool for both StartTLS and ldaps://, so the certificate is verified against the AD root CA. PUT /api/admin/ldap refuses (400) a ca_cert that is not PEM, holds a non-certificate block (e.g. a private key), has a damaged/truncated block or a certificate that does not parse. A stored ca_cert that cannot be parsed makes LDAPConnect fail before dialling; it never falls back to the system pool. Only "set / not set" goes to the audit log. TLS by scheme: the connection is now decided by the URL scheme alone, not by use_tls: - ldaps:// with use_tls=false (what the console's manual form saves) was dialled with go-ldap's default TLS settings, ignoring skip_tls_verify (and now ca_cert); it now always uses the TLS config. - ldap:// with use_tls=true skipped StartTLS entirely (go-ldap ignores a TLS config for ldap://) and bound in cleartext; it now uses StartTLS. use_tls stays in the JSON and is set from the scheme on save. A handshake that fails on an untrusted CA now says to set ca_cert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
POST /api/admin/ldap/import and /api/admin/ldap/auto-discover built a fresh config without skip_tls_verify / allow_insecure (and now ca_cert): re-running the console's Connect or importing the setup script's JSON silently reset them, and Connect could not reach an AD with an internal CA at all. Both now accept skip_tls_verify, allow_insecure and ca_cert. A field the request omits keeps its stored value (off when nothing is stored); a field it sends replaces it, including switching it off or clearing ca_cert with "". Auto-discover already connects with the resolved settings, so Connect verifies against the pasted CA. An invalid ca_cert is refused with 400 before anything is saved or dialled. GetLDAPConfig now returns store.ErrLDAPNotConfigured (same message) so a real store error is reported (500) instead of being taken for "nothing stored". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
The console offered no way to trust an internal AD root CA, skip verification or allow cleartext, and the manual form never sent them, so saving silently reset any value set through the API. A shared "TLS & certificates" section is now in every LDAP form: the Connect card, Manual Setup, Import Config, and Edit on the Connection card. It has - "AD root CA certificate (PEM)": paste the root CA that issued the domain controllers' certificates; verification stays on (recommended); - "Skip certificate verification", with a warning that anyone between SimpleAuth and AD could impersonate AD and capture passwords (testing only); - "Allow cleartext (no StartTLS)", with a stronger warning (no effect on ldaps://). Every save sends all three fields (PUT is a full replace), so editing the connection or the attributes keeps them. Import Config is prefilled with the current settings and takes them from the uploaded JSON when it has them. The Connection card shows the encryption (StartTLS / TLS / none) and whether certificates are checked. A failed Connect stays on screen instead of only in a 3-second toast, and a certificate error opens the TLS section. Also: .alert-success/.alert-error now get their dark colours in the Auto theme on a dark OS, not only with the explicit Dark theme. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
ACTIVE-DIRECTORY.md: new "TLS and Certificates" section (how ldaps:// and StartTLS are chosen, what the certificate must satisfy, how to export the AD root CA and paste it as ca_cert, why skip_tls_verify and allow_insecure are not the fix); the console's TLS & certificates switches; corrected API and auto-discover examples (PUT, real fields and body); connection reference table and certificate troubleshooting. API.md: ca_cert, skip_tls_verify, allow_insecure and the derived use_tls on PUT (full replace, 400 on an invalid ca_cert); auto-discover and import keep stored TLS settings when the body omits them; audit fields. CHANGELOG.md: Unreleased section with upgrade notes (ldap:// + use_tls=true no longer binds in cleartext; console saves now send the TLS fields). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
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.
On v2.3.0, an AD reached over
ldap://fails every StartTLS upgrade witheither ServerName or InsecureSkipVerify must be specified in the tls.Config; #75 fixes that. The next wall is an AD whose domain controllers carrycertificates from the organisation's own CA:
certificate signed by unknown authority.The only way out was
skip_tls_verify, and it barely worked:What
ca_certon the LDAP config (PEM, one or more CA certificates).ldaps://, so verification stays on.400 invalid ca_cert: …: non-PEM text, a pasted privatekey, a damaged or truncated block, a certificate that doesn't parse.
ldaps://always dials with the TLS config;ldap://always upgrades withStartTLS before any bind, unless
allow_insecureis set.use_tlsis set from the scheme on save and is no longerused to connect. This fixes two bugs:
ldaps://saved from the console (nouse_tls) ignoredskip_tls_verify(and nowca_cert).ldap://with"use_tls": trueskipped StartTLS and bound in cleartext (row S12 below). go-ldap ignores theTLS config for
ldap://, andLDAPConnectreturned early onUseTLS.skip_tls_verify,allow_insecureandca_cert. A field left out keeps itsstored value instead of being reset (
"ca_cert": ""clears it). Auto-discover connects with the resolvedsettings. PUT stays a full replace.
(no StartTLS)" (a stronger warning).
.alert-error/.alert-successget their dark colours in the Auto theme on a dark OS.; … set ca_cert to the AD root CA certificate (PEM).docs/ACTIVE-DIRECTORY.md("TLS and Certificates"),docs/API.md, andCHANGELOG.md("Unreleased",with upgrade notes; rename the heading at release).
Verification
go vet ./...andgofmt -lare clean;go test ./...andgo test -race(auth, handler) pass on Go 1.26.8.internal/ldaptest, which now answers bind and RootDSEsearch after TLS) with a certificate from a separate test CA:
TestLDAPConnectCACert: StartTLS and ldaps; fails closed without the CA; works with it, with a bundle; failswith the wrong CA.
TestLDAPConnectCACertStillChecksHost,TestLDAPConnectSkipVerifyUntrustedCA,TestLDAPConnectInvalidCACert,TestParseLDAPCACert,TestIsLDAPS.ca_certrefused,use_tlsfollows the scheme,/testtrustsca_cert,ldaps-without-
use_tlsuses the TLS settings, storeduse_tlsonldap://still uses StartTLS, import andauto-discover take and keep the settings.
ca_certauth tests don't compilethere (the field doesn't exist yet).
dc1.satls.test) whose LDAP certificate comes from its own OpenSSL CA,with no
SSL_CERT_FILEanywhere. Stock 2.3.0 image vs fix(ldap): verify StartTLS certificates; keep admin binds encrypted #75 vs this branch:ldap://+ ca_cert,/testldap://, no ca_certldap://+ skipldaps://+ ca_cert, no use_tls (as the console saves it)ldaps://, no ca_certldaps://+ skip, no use_tlsdc1.satls.test+ ca_cert/testok/testokldap://+use_tls:true+ ca_certThe console was walked through in light, dark and auto-dark against the same DC:
ldaps://with the CA, and the cleartext warning.Behaviour changes
ldap://with"use_tls": truenow uses StartTLS instead of a cleartext bind. A directory without an LDAPcertificate now fails with the StartTLS error, exactly like
"use_tls": false(setallow_insecurefor acleartext directory).
ldaps://now honoursskip_tls_verifyandca_cert.ca_cert(400).Not in this PR
The
govulncheckjob fails on master already (since at least 2026-10-26). Go 1.26.8 has reachable stdlibvulnerabilities fixed in 1.26.9 / 1.26.10, including GO-2026-6809 in
crypto/x509, andgolang.org/x/netv0.58.0needs v0.60.0. That is a separate toolchain bump.
🤖 Generated with Claude Code
https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP