LDAP / Active DirectoryOperations (day 2)

§ 06 · LDAP / ACTIVE DIRECTORY · DAY TWO

Operations (day 2)

Passwords expire, certificates expire, directories go down. Here is what to do for each.

Every change below is made on Organization settings → LDAP by an organization owner (any organization; the setting covers every organization on the instance and Save asks you to confirm that), unless it says otherwise. While LDAP is on, every Save needs a passing Test connection and Test user credential, so keep a test person available for any maintenance window.

Rotating the service-account password

The customer changes the password of svc-hivecfm@bank.example in AD. Until HiveCFM has the new one, nobody can sign in (the service bind fails, the login page says “temporarily unavailable”).

  1. Agree a time with the customer. Ideally they change the password and you update HiveCFM within minutes.
  2. Sign in (Administrator sign-in works even if the directory side is broken).
  3. Type the new password in Bind password (10).
  4. Run Test connection, then Test user credential with a real person.
  5. Save. The switch did not change, so nobody is signed out.

If you change only other fields, leave Bind password blank to keep the stored one. Exception: if you change the server, port, mode, domain, security, bind user, CA or verify setting, you must retype the password. HiveCFM refuses to send the stored secret to a changed target.

Renewing or replacing the CA certificate

DC certificates are renewed regularly, usually by the same CA, which needs no change in HiveCFM. You must act when:

  • the customer moves to a new root or intermediate CA → LDAP_TLS_UNTRUSTED_CERT;
  • the DC certificate expired → LDAP_TLS_CERT_EXPIRED (fixed on the DC, not in HiveCFM);
  • the DC is reached under a new name → LDAP_TLS_HOSTNAME_MISMATCH.

To switch CAs without an outage, paste both the old and the new CA certificates into CA certificate, one after the other, before the DC switches. Test, save (retype the bind password: the CA is part of the target). After the DC has switched, remove the old CA, test and save again.

When AD is down

What still worksWhat does not
Sessions that are already open.New sign-ins by directory users: “Directory sign-in is temporarily unavailable…”.
Administrator sign-in for organization owners with a local password.There is no fallback to stored passwords, by design.
Turning LDAP off (no test needed, no directory needed).

Options, from mildest to strongest:

  1. Wait. If the outage is short, directory users simply retry.
  2. Point at another DC. If only one DC is down, change Server host to another DC (Direct mode), retype the bind password, test and save. In Standard mode HiveCFM already tries up to 3 DCs from DNS when one cannot be reached.
  3. Turn LDAP off temporarily. Sign in with Administrator sign-in, switch it off, Save. Everyone is signed out and the normal email login returns. Directory users have no usable local password, so this only helps people with local accounts.
  4. Kill switch, if nobody can reach the settings page. See below.

Emergency kill switch

Set the environment variable LDAP_AUTH_DISABLED=1 on the HiveCFM core container and restart it.

  • The normal email login page returns, regardless of the saved settings.
  • The LDAP provider refuses all logins.
  • The settings page shows a warning banner; the directory users card and Add from directory are hidden.
  • The database is not changed and sessions are not revoked.

To undo: remove the variable (or set it to 0) and restart. The saved settings apply again.

⚠️

The kill switch is a container setting, so it needs someone with access to the hosting platform. It is for real emergencies, for example when the only local owner’s password is lost and the directory is down. Write down who can set it at each customer site.

Turning LDAP off for good

  1. Switch LDAP / Active Directory sign-in off and Save. No test is needed.
  2. Everyone is signed out; the login page shows “LDAP sign-in was disabled. Please sign in again.” and the normal email login.
  3. Directory users cannot sign in any more. Their HiveCFM rows stay (identityProvider = 'ldap'); the email login refuses them even if they try their old password.
  4. If those people must keep using HiveCFM, they need new local accounts. Talk to the customer first: emails are unique, so a new local account cannot reuse an email that an LDAP user row already holds.

The configuration row is kept, so turning LDAP back on later only needs tests and a Save.

Deploying the feature

The three migrations

MigrationWhat it doesReversible?
20261004120000_add_ldap_identity_providerALTER TYPE "IdentityProvider" ADD VALUE 'ldap'. Kept alone because PostgreSQLPostgreSQLThe open-source relational database HiveCFM runs on. Replaces SQL Server for this project. cannot use a new enum value in the same transaction that adds it.No. PostgreSQLPostgreSQLThe open-source relational database HiveCFM runs on. Replaces SQL Server for this project. cannot remove an enum value.
20261004120100_add_instance_ldap_configCreates the one-row table instance_ldap_config, with CHECK constraints on mode (standard/direct) and security (ldaps/starttls/none).Yes (drop the table).
20261005090000_add_ldap_sessions_revoked_atAdds sessions_revoked_at to that table.Yes (drop the column).
🚫

The enum migration is permanent. Once 'ldap' is added to "IdentityProvider" on a database, it stays. Never run these migrations against a shared database (for example a shared dev database used by other branches) before the feature is merged into the branch that database follows. Rehearse on an isolated database.

Before the migrations run, the app keeps working: the session check treats a missing table or column as “no revocation” (and logs it once), and the login page treats LDAP as off.

Environment variables

VariableNeededEffect
ENCRYPTION_KEYYes (already required by HiveCFM)Encrypts the bind password. Changing it makes the stored bind password unreadable: re-enter it on the settings page.
LDAP_AUTH_DISABLEDNo1 = emergency kill switch (see above). 0 or unset = normal.
EMAIL_AUTH_DISABLEDMust not be 1 on an LDAP site1 removes the email form, and with it Administrator sign-in.
NEXTAUTH_URL / WEBAPP_URLYes (already required)Must be the real public URL. Post-login redirects only follow same-host targets.

No LDAP setting lives in environment variables. The server, Base DN, service account and CA are all entered on the settings page and stored in the database.

Network

  • Open TCP 636 (LDAPS) or 389 (StartTLS) from the HiveCFM core host or its egress subnet to every DC you will use.
  • For Standard mode, the core container must be able to resolve _ldap._tcp.<domain> SRV records. In most container platforms it cannot without an added DNS zone or forwarder; use Direct mode instead.

Rehearsal checklist

Run this on an isolated stack (own database, a test directory such as a Samba AD DC) before a customer go-live. A scenario only counts as passed when you saw the result.

#ScenarioExpected
1First run at /setup: local owner + workspaceLocal sign-in works
2Standard mode, container without AD DNSLDAP_SRV_NOT_FOUND
3Direct, LDAPS 636, no CALDAP_TLS_UNTRUSTED_CERT
4Direct, LDAPS by IP, CA pasted, certificate without that IPLDAP_TLS_HOSTNAME_MISMATCH
5Direct, LDAPS by DNS name, CA pastedAll steps ✓
6StartTLS 389 with CAAll steps ✓
7LDAPS against port 389LDAP_TLS_HANDSHAKE_FAILED
8Wrong service password / wrong Base DN / DC stoppedLDAP_BIND_SERVICE_INVALID / LDAP_BASE_DN_NOT_FOUND / LDAP_CONNECT_REFUSED or _TIMEOUT
9Test user: normal, disabled, locked, expired, must-change, no mail✓, then 533, 775, 701, 773, LDAP_NO_EMAIL_ATTRIBUTE
10Count users before and after the testsUnchanged: tests never create users
11Save with the switch on and the DC stoppedRefused, nothing saved
12Save with the switch on and the DC upEnabled; everyone signed out; notice on the login page
13Login page in a private windowCompany form only; no sign-up, SSO or forgot-password; /auth/signup not found
14Administrator sign-in as the local ownerWorks
15First LDAP sign-inUser created (identityProvider = 'ldap', objectGUID set, no membership), lands on “No workspace found”
16Directory person whose mail equals the local owner’s email”An account with this email already exists…”; no takeover
17Post that person’s correct AD password to the email loginRefused (401)
18Change the person’s password in ADOld one refused, new one accepted
19Add the waiting person with a workspace and ReadThey open that workspace; team <workspace> members (read) exists
19aAdd from directory a person who never signed in, with a workspace and Read; then they sign inMembers list shows “Waiting for first sign-in” until the sign-in, then Active; they land straight in the workspace
20LDAP_AUTH_DISABLED=1 + restartNormal email login; warning on the settings page
21Grep the core logs for the test passwords and usernamesZero hits
22Turn LDAP offEveryone signed out; email login back
23An owner of a second organization opens Organization settings → LDAP; after Test connection and Test user credential pass, clicks SavePage shows “This setting applies to every organization on this instance”; Save asks “Save LDAP settings for all organizations?“
24Check that a normal directory user cannot edit their own mailRefused by the directory

Customising the user filter

The default filter suits every Active Directory. Change it only for a specific need, test it with a real person, and keep {username} in it.

Only members of one AD group may sign in. Add a memberOf condition inside the outer (&…):

(&(objectCategory=person)(objectClass=user)(memberOf=CN=HiveCFM Users,OU=Groups,DC=bank,DC=example)(|(sAMAccountName={username})(userPrincipalName={username})))
  • Use the group’s full DN. memberOf matches direct members only; people in a nested group are not found.
  • For nested groups, AD supports the “in chain” rule: (memberOf:1.2.840.113556.1.4.1941:=CN=HiveCFM Users,OU=Groups,DC=bank,DC=example). It is slower on large directories.
  • People outside the group get LDAP_USER_NOT_FOUND (“Invalid username or password.”). This only controls who may sign in; it still grants no workspace access.

Exclude disabled accounts at search time (optional; AD refuses their bind anyway):

(&(objectCategory=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(|(sAMAccountName={username})(userPrincipalName={username})))

With this, disabled people see “Invalid username or password.” instead of the “can’t sign in” message.

OpenLDAP (not Microsoft):

(uid={username})

Also set Email attribute to mail and Name attribute to cn (or displayName if your schema has it). OpenLDAP users are identified by entryUUID. Make sure the directory’s access rules stop people from changing their own mail.

Whatever you put in the filter, HiveCFM escapes the typed username before inserting it, so *, (, ) and \ typed by a user cannot change the filter’s meaning.


HiveCFM Developer Hub — internal team guide