LDAP and Active Directory sign-in
Bongo can check a user’s password against an LDAP or Active Directory server instead of a local password hash. Local accounts keep working beside directory accounts, and a local administrator can always sign in, even when the directory is unreachable.
This page covers sign-in, account creation and the administrator group. The directory address book and an LDAP server for other programs are separate features.
What it does
- A directory account signs in to the web, IMAP, POP3, SMTP submission and CalDAV/CardDAV with its directory password.
- Two-factor authentication and app passwords work as for local accounts. App passwords are the way to give a mail client its own credential, so the directory password does not have to be stored in every client.
- A user the directory disables or removes cannot sign in again, and loses the sessions they have open within five minutes (see below).
- Passwords are never stored in Bongo for these accounts. Bongo cannot change or reset them: the change-password page says the directory manages the password, and the admin page hides Reset password.
Configuration
Add an auth block to the configuration file on every node. It needs a restart.
auth {
ldap {
url = "ldaps://ldap.example.com"
ca_file = "/etc/bongo/ldap-ca.pem"
bind_dn = "cn=bongo,ou=services,dc=example,dc=com"
bind_password = "change-me"
user_base = "ou=people,dc=example,dc=com"
user_filter = "(objectClass=person)"
}
}
| Key | Default | Meaning |
|---|---|---|
url |
required | ldaps://host[:port], or ldap://host[:port] with StartTLS |
ca_file |
system roots | PEM file with the CA that signed the directory’s certificate |
bind_dn |
required | The service account that searches for users |
bind_password |
required | Its password. BONGO_AUTH_LDAP_BIND_PASSWORD overrides it, to keep it out of the file |
user_base |
required | The subtree searched for users |
user_filter |
(objectClass=person) |
Entries it excludes cannot sign in |
mail_attribute |
mail |
The attribute that holds the sign-in address |
display_name_attribute |
displayName |
Used as the display name of an auto-provisioned account |
admin_group |
none | DN of a group whose members are administrators |
group_member_attribute |
member |
The membership attribute of that group |
auto_provision |
false |
Create the account on first sign-in |
connect_timeout |
5s |
1s to 60s |
request_timeout |
10s |
1s to 60s; also how long an attempt waits for one of 16 connection slots per node |
The service account only needs to read the user entries and the admin group. Give it no other rights.
The sign-in name is the address in mail_attribute, the same address as the
Bongo account. With Active Directory, point mail_attribute at
userPrincipalName if that is what users type.
mail_attribute must be writable only by directory administrators. Bongo trusts
it as the proof of who owns an address: a user who can edit their own entry’s
mail attribute can put another person’s address there and sign in to that
person’s Bongo account with their own directory password, or, with
auto_provision on, claim any free address on a hosted domain. Many directories
let users edit parts of their own entry by default; check the access rules
before enabling LDAP sign-in.
Transport
The connection is always encrypted. ldaps:// is TLS from the first byte.
ldap:// must complete StartTLS before Bongo sends any bind, so a password
never crosses the network in the clear, and an LDAP server that refuses StartTLS
makes sign-in fail. Certificates are always verified (TLS 1.2 or newer, the name
checked against the host in url). There is no option to turn that off. If the
directory uses a private CA, put it in ca_file.
Disabled users
Bongo treats a user the user_filter leaves out as disabled or removed. Put the
“is enabled” test in the filter:
- Active Directory:
(&(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2))) - OpenLDAP with the ppolicy overlay:
(&(objectClass=inetOrgPerson)(!(pwdAccountLockedTime=*)))
Without such a test, a directory account that is disabled in the directory but still has an entry keeps signing in only if the directory still accepts its password, which Active Directory does not for a disabled account. The filter makes it explicit and also ends open sessions.
Administrators from a directory group
With admin_group, members of that group (direct members; nested groups are not
followed) are Bongo administrators:
- On sign-in Bongo stores the administrator flag of the account to match the group. A failed write when taking the flag away fails the sign-in. A failed write when granting it is logged and the stored flag stays.
- While a session is open, the account is an administrator only when the stored flag is set and the group still lists it (checked at most every five minutes). Removing someone from the group therefore removes their admin rights without waiting for them to sign in again.
- The admin page refuses to change the administrator flag of such an account (the checkbox is locked).
Without admin_group, the administrator flag of a directory account is set on
the admin page like any other.
Creating directory accounts
On the admin page for a new user, a global or domain admin can choose
Authentication, Directory (LDAP). The form then needs no password. The choice
only appears when auth.ldap is configured. The address must still be on a
domain hosted here.
With auto_provision = true, Bongo creates the account itself the first time a
person signs in with a directory password. It does this only when:
- the address is a valid address on a domain Bongo hosts, and the domain is not an alias domain;
- nothing already holds the address: no account (enabled or disabled), alias, group, shared inbox or resource;
- the directory accepts the password.
With auto_provision on, the time a sign-in takes can tell an address that is
already taken or not on a hosted domain (refused at once, without asking the
directory) from a free address on a hosted domain (the directory is asked).
Anyone can therefore learn which addresses exist here by timing sign-in
attempts. The answer itself is the same in both cases. Leave auto_provision
off if that matters to you and create directory accounts on the admin page.
The account takes its display name from the directory at creation and keeps it afterwards. Converting an existing local account to a directory account is not supported; create a new one.
Five minutes of cached state
Bongo asks the directory whether a directory account still exists, and what its admin group membership is, at most once every five minutes per user. Passwords are never cached: a sign-in, and every CalDAV or CardDAV request, binds to the directory.
A disabled or removed user fails the next sign-in at once, and their open sessions end within five minutes. If the directory is unreachable and the cached state has expired, the state is unknown and Bongo fails closed: IMAP refuses the command, web sessions lose administrator rights. A directory outage longer than five minutes therefore interrupts directory users’ mail sessions. Local accounts are not affected.
When the directory is down
A directory account cannot sign in. Bongo answers the same way as for a wrong
password on every protocol, so clients and attackers learn nothing from it. The
log says what happened: ldap: directory unavailable host=... step=..., where
step is connect, tls, service_bind, search, user_bind or timeout.
One deadline of request_timeout covers a whole attempt (connecting, TLS,
binds and searches), so a directory that stops answering part way, even in the
middle of a TLS handshake, releases the connection slot when it runs out.
A user_base that does not exist in the directory makes every directory
sign-in fail as a wrong password. Bongo logs that as
ldap: user base not found host=... step=search.
Bongo never logs the error text of the LDAP library, a DN, a filter or a
password, only the host and that step. Local accounts, including local
administrators, are unaffected.
The directory as an address book
With auth.ldap configured, the directory also fills two address lists. Both
use the service account from the block above, and both are scoped to the
caller’s own domain.
Compose autocomplete (GET /api/gal) adds directory entries after the
local accounts. The GAL part of an answer holds at most 10 entries: local
accounts come first, and directory entries fill what is left. An address that is
already a local account, a contact or a group is shown once, from the local
source, and an address that belongs to a local account that is disabled (or
whose primary domain is disabled), a room, a piece of equipment or a shared
inbox is never offered from the directory (a user disabled in Bongo does not
come back through LDAP). When the address cannot be checked (a store read
fails), the entry is left out. A user whose domain is disabled gets no GAL
entries at all, local or directory, and the Directory address book applies the
same rule. Directory entries show
as ordinary GAL entries. The share forms (calendar, folder, address book)
never offer directory entries: they accept local accounts only.
The Directory address book is a read-only CardDAV address book that every
user has, with or without LDAP. See docs/caldav-carddav.md. With LDAP it also
lists the directory entries that are not local accounts.
Which entries a user sees
A user sees entries whose mail value ends in @ plus their own primary
address domain, and only that domain. Bongo reads the domain from the stored
profile on every request. It never comes from the URL, a query parameter or the
session’s email, and it is matched exactly (case does not matter). Alias
domains are not added: a user of a.test does not see b.test entries even
when b.test is an alias domain of a.test. The domain is in the search
filter, and every entry that comes back is checked again, so a directory server
that applies the filter loosely cannot show one domain’s people to another. An
entry with several mail values is offered under the first one on the user’s
domain, never under an address on another domain.
What is searched
Autocomplete needs at least two characters and at most 64 bytes; a shorter,
longer or control-character query is answered with local results and never
reaches the directory. The query is escaped as an RFC 4515 filter value. The
search asks for the mail and display name attributes only, under user_base
with user_filter applied (so users the filter excludes are not offered), with
a size limit of 20 for autocomplete and 5000 for the address book listing, and
request_timeout as the time limit, in whole seconds rounded up and at least
1 (a request_timeout under a second still sends a limit of 1 second, never 0,
which LDAP reads as no limit). A size limit answer uses the entries that
arrived.
Caching, limits and staleness
- Autocomplete answers are cached for 10 minutes per node, keyed by domain and query, at most 1024 of them. The address book listing is cached for 10 minutes per domain in the directory client, and 60 seconds in the CardDAV layer, so a multiget does not search again for each card.
- A user removed or disabled in the directory can therefore still be offered for up to 10 minutes (plus 60 seconds in CardDAV). A local change (a new account, a disabled account, a changed name) shows in CardDAV within 60 seconds.
- Searches have their own connection slots (4 at a time), apart from the 16 for sign-ins, so typing in a compose box cannot slow directory sign-in. When all 4 are busy the answer is local results only.
GET /api/galhas a budget of 600 calls per user per hour on each node. Over it the answer is429withRetry-Afterand an empty list. The share-form variant counts too; an empty query does not.- The Directory address book has no per-user request budget. What bounds it is the cache: however often a user’s client syncs, the directory is asked at most once per domain per 10 minutes per node (one listing search, with a size limit of 5000), and the local accounts are read at most once per domain per 60 seconds per node. A user can make Bongo build their card list as often as they like from that cache, which costs CPU but no directory or Pebble scan. The book holds at most 5000 entries (local accounts first, then directory entries), and the CardDAV cache keeps at most 64 domains.
When the directory is down
Autocomplete and the address book give local results only, with no error. After
a failure the directory is not asked again for 30 seconds, so a dead server is
not tried on every keystroke. The failure is logged at most once a minute as
ldap: directory search unavailable host=... step=...; the query, the filter,
a DN and the cache key are never logged. A directory that answers more entries
than the size limit logs ldap: directory search truncated (at most once a
minute) and the entries received are used.
Security notes
- The address typed at sign-in is checked (a bare address, at most 320 bytes, no
control characters or parentheses) and escaped as an LDAP filter value before
it is searched, so
*)(uid=*cannot widen the search. - Bongo binds as the entry the search returned, and only when exactly one entry carries that address.
- An empty password is refused before it reaches the server (an LDAP bind with an empty password is an anonymous bind that many servers accept).
- An unknown address, a wrong password and a disabled user all cost the same
directory operations and one password hash. It is still observable from timing
whether an address is backed by the directory, when
auto_provisionis off for an address that has no local account. - The service account is never bound with a password a user typed, so repeated wrong guesses cannot lock it out. Account lockout of the user’s own directory entry is up to the directory, which sees each wrong password as a failed bind.
- A password changed in the directory does not end open sessions (there is no hash in Bongo to notice the change). A disabled or removed account does, within five minutes.
Clusters and upgrades
Upgrade every node before adding the auth block or creating a directory
account. An older node rejects the unknown block at start-up. It also ignores
the account’s auth_source, so it treats the account as a local one with an
unusable password and refuses the sign-in (safe), but an administrator who
resets that account’s password on an older node gives it a usable local
password there.
Directory entries in autocomplete and the Directory address book are node-local
reads with no Raft write, so nodes cannot diverge, but an older node has none
of it: its /api/gal shows local accounts only and has no per-user budget, and
it answers 404 on the Directory address book path and does not list it. A CardDAV
client that is balanced across nodes would see the book appear and vanish and
could drop its local copy, so upgrade every node before relying on it.
Auto-provisioning writes through the leader. A sign-in that reaches a follower cannot create the account and fails. The user retries once the request lands on the leader. Two nodes creating the same account at once is resolved by the second one losing the address record and failing.
Not included
- Writing to the directory, or a directory book that clients can edit.
- Distribution groups and directory groups in the Directory address book.
- An LDAP server for other applications.
- Converting a local account to a directory account, and syncing the display name after creation.
- Nested group membership for
admin_group.