§ 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”).
- Agree a time with the customer. Ideally they change the password and you update HiveCFM within minutes.
- Sign in (Administrator sign-in works even if the directory side is broken).
- Type the new password in Bind password (10).
- Run Test connection, then Test user credential with a real person.
- 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 works | What 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:
- Wait. If the outage is short, directory users simply retry.
- 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.
- 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.
- 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
- Switch LDAP / Active Directory sign-in off and Save. No test is needed.
- Everyone is signed out; the login page shows “LDAP sign-in was disabled. Please sign in again.” and the normal email login.
- 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. - 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
| Migration | What it does | Reversible? |
|---|---|---|
20261004120000_add_ldap_identity_provider | ALTER 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_config | Creates 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_at | Adds 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
| Variable | Needed | Effect |
|---|---|---|
ENCRYPTION_KEY | Yes (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_DISABLED | No | 1 = emergency kill switch (see above). 0 or unset = normal. |
EMAIL_AUTH_DISABLED | Must not be 1 on an LDAP site | 1 removes the email form, and with it Administrator sign-in. |
NEXTAUTH_URL / WEBAPP_URL | Yes (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.
| # | Scenario | Expected |
|---|---|---|
| 1 | First run at /setup: local owner + workspace | Local sign-in works |
| 2 | Standard mode, container without AD DNS | LDAP_SRV_NOT_FOUND |
| 3 | Direct, LDAPS 636, no CA | LDAP_TLS_UNTRUSTED_CERT |
| 4 | Direct, LDAPS by IP, CA pasted, certificate without that IP | LDAP_TLS_HOSTNAME_MISMATCH |
| 5 | Direct, LDAPS by DNS name, CA pasted | All steps ✓ |
| 6 | StartTLS 389 with CA | All steps ✓ |
| 7 | LDAPS against port 389 | LDAP_TLS_HANDSHAKE_FAILED |
| 8 | Wrong service password / wrong Base DN / DC stopped | LDAP_BIND_SERVICE_INVALID / LDAP_BASE_DN_NOT_FOUND / LDAP_CONNECT_REFUSED or _TIMEOUT |
| 9 | Test user: normal, disabled, locked, expired, must-change, no mail | ✓, then 533, 775, 701, 773, LDAP_NO_EMAIL_ATTRIBUTE |
| 10 | Count users before and after the tests | Unchanged: tests never create users |
| 11 | Save with the switch on and the DC stopped | Refused, nothing saved |
| 12 | Save with the switch on and the DC up | Enabled; everyone signed out; notice on the login page |
| 13 | Login page in a private window | Company form only; no sign-up, SSO or forgot-password; /auth/signup not found |
| 14 | Administrator sign-in as the local owner | Works |
| 15 | First LDAP sign-in | User created (identityProvider = 'ldap', objectGUID set, no membership), lands on “No workspace found” |
| 16 | Directory person whose mail equals the local owner’s email | ”An account with this email already exists…”; no takeover |
| 17 | Post that person’s correct AD password to the email login | Refused (401) |
| 18 | Change the person’s password in AD | Old one refused, new one accepted |
| 19 | Add the waiting person with a workspace and Read | They open that workspace; team <workspace> members (read) exists |
| 19a | Add from directory a person who never signed in, with a workspace and Read; then they sign in | Members list shows “Waiting for first sign-in” until the sign-in, then Active; they land straight in the workspace |
| 20 | LDAP_AUTH_DISABLED=1 + restart | Normal email login; warning on the settings page |
| 21 | Grep the core logs for the test passwords and usernames | Zero hits |
| 22 | Turn LDAP off | Everyone signed out; email login back |
| 23 | An owner of a second organization opens Organization settings → LDAP; after Test connection and Test user credential pass, clicks Save | Page shows “This setting applies to every organization on this instance”; Save asks “Save LDAP settings for all organizations?“ |
| 24 | Check that a normal directory user cannot edit their own mail | Refused 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.
memberOfmatches 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.