Docs Version v0.2
Docs menu

Other protocols

LDAP

Changed 19 min readv0.2

On this page

Introduction

Some older software can check a password only by asking a company directory. It speaks the Lightweight Directory Access Protocol (LDAP), and asks the directory whether a username and password are right. That request is called a "bind". No browser is involved: Ada types her password into the application itself.

Signari can answer those binds as an LDAP server. Software written for a directory can then check the people Signari keeps, with the same password and the same limits as the sign-in page. Which protocol do I need? explains LDAP in plain words.

The LDAP listener is off until you give it an address. You configure it with environment variables when you start Signari.

Note

This page is about Signari acting as a directory. To read people from an existing LDAP directory into Signari, see LDAP as a source.

Turn on the LDAP listener

To start Signari with the LDAP listener on port 636, give it the listener's address, the base of the directory and the organisation it serves:

ShellSIGNARI_LDAP_ADDR=0.0.0.0:636 \SIGNARI_LDAP_BASE_DN="dc=example,dc=com" \SIGNARI_LDAP_ORG_ID=<org-uuid> \signari serve -addr :443 -tls-cert cert.pem -tls-key key.pem

The listener is off unless SIGNARI_LDAP_ADDR is set. It is a second place where passwords are checked, so it runs only when you ask for it.

People bind as uid=<username>,<base-dn>. A "DN", or distinguished name, is the full name of an entry in the directory. The "base DN" is the name at the top of the directory, which is dc=example,dc=com in this example.

A bind DN must end in the base DN. A bare uid=alice, a relative distinguished name (RDN) with nothing after it, is refused.

What the listener supports

Signari's LDAP listener is a compatibility shim. It offers bind and search, so that software written against a directory can authenticate people who live in Signari.

It can also be written to, with add, modify, delete and modify DN (RFC 4511 §4.6–§4.9), against an explicit schema. That is off by default, and takes two decisions to turn on. See Writes below.

The listener works with ldapsearch and ldapwhoami from OpenLDAP, and with the go-ldap library.

It is not a full directory. There is no replication, no directory information tree (DIT) structure rules, no aliases and no subordinate entries. The tree is flat, and holds person entries. Everything outside that is refused, not stubbed, so that no application comes to depend on a half-implemented feature.

Empty passwords are refused

A published vulnerability, CVE-2017-14623, against the go-ldap library, says:

"an attacker may be able to login with an empty password. This issue affects an application using this package if these conditions are met: (1) it relies only on the return error of the Bind function call to determine whether a user is authorized... and (2) it is used with an LDAP server allowing unauthenticated bind."

RFC 4513 §5.1.2 names that case: a simple bind carrying a DN and an empty password is an "unauthenticated" bind. The person supplied a name, and proved nothing. Applications ask "did the bind return an error?", and read nil as "authenticated". So a server that answers success here gives each of those applications an authentication bypass.

Empty passwords are refused. There is no configuration option to allow it. The refusal happens before the credential checker is reached, so it does not depend on a comparison failing.

With ldapwhoami, a bind with an empty password gets this answer:

Text$ ldapwhoami -x -H ldaps://... -D "uid=alice,dc=signari,dc=test" -w ""ldap_bind: Invalid credentials (49)    additional info: a bind with an empty password authenticates nobody                     (RFC 4513 section 5.1.2)

Other decisions

Anonymous search is off by default. An "anonymous" search is one made with no bind. An anonymous search endpoint publishes a directory of people to anyone who can reach the port. SIGNARI_LDAP_ANONYMOUS_SEARCH=1 turns it on.

A bound person sees only their own entry. Binding proves only a password. Reading every name, address and group in the organisation is a separate grant, so it goes to a group. This setting names the group:

ShellSIGNARI_LDAP_SEARCH_GROUP=directory-readers

Members of that group can search the whole directory. They are usually the "service accounts" that applications bind as to look people up: accounts that a program uses, not a person.

Everyone else can search, but the only entry they get back is their own. Reading another person's DN directly returns nothing, and the answer is the same whether or not that person exists. Members of SIGNARI_LDAP_WRITE_GROUP can search as well, since they can already rename and delete anyone. When anonymous search is on, every connection sees everything, because nothing is gained by limiting bound people then.

An LDAP outpost, a Signari program that serves LDAP away from the database, takes its search group from its registration instead. You set it with signari outpost search-group, and the core enforces it. See outposts.

If an application's service account searches for other people, add it to the search group. Otherwise its searches come back with only its own entry. An outpost ignores SIGNARI_LDAP_SEARCH_GROUP in its own environment, and logs a warning naming it, because its registration decides.

Group membership is read on every operation, not at bind. A client keeps a connection open for as long as it likes. So each search and each write looks the bound person up again. Once someone is removed from the search group, their next search on the same connection returns only their own entry.

Once someone is removed from the write group, their next write is refused with insufficientAccessRights. A deactivated person gets nothing back.

No userPassword attribute is ever returned, at any value. A returned hash or placeholder would lead applications to compare credentials themselves, instead of binding.

compare is refused. It answers "does this attribute equal this value?". Against a password attribute, that is a guessing "oracle": something that answers yes or no to each guess, with no failed-sign-in counter.

StartTLS is refused; LDAPS is supported. "StartTLS" upgrades a plain connection to an encrypted one partway through. "LDAPS" is LDAP over Transport Layer Security (TLS) from the first byte. A server that answers success to StartTLS without upgrading the connection has told the client the channel is protected. The client then sends a password over it in the clear.

Supplying -tls-cert makes the LDAP listener LDAPS. Without one, the engine refuses to start unless SIGNARI_LDAP_INSECURE=1 asks for plaintext by name. That is the same rule as for the Admin API and the LDAP outpost.

A failed re-bind drops the identity. A connection that stayed bound as its previous identity would let a client authenticate once. The client could then keep the session while claiming to be someone else.

An unknown person and a wrong password are indistinguishable, in both the message and the timing. The dummy verification runs even when no person was found. Otherwise the port would be an oracle for which accounts exist, open to anyone who can reach it.

A filter this directory cannot evaluate matches nothing, negated or not. A search "filter" says which entries to return. A filter is TRUE, FALSE or Undefined, and only TRUE returns an entry. An attribute it does not know, a matching rule it does not recognise or a malformed substring is Undefined. It stays Undefined through a NOT.

Filters. These kinds of filter are evaluated:

  • Equality.
  • Presence.
  • Substrings, such as (cn=al*), with at most eight parts, none of them overlapping.
  • >= and <=, which compare the case-folded value in byte order.
  • ~=, treated as equality, as RFC 4511 says where approximate matching is not supported.
  • Extensible matches.

An extensible match names its rule by name: caseIgnoreMatch or caseExactMatch, or their IA5 forms. A rule given by object identifier (OID) is not recognised. :dn: also tries the entry's DN. A value is matched as its BER (Basic Encoding Rules) encoding carried it, so a * a client escapes is a character. Beginning-of-name searches on uid and mail are asked of the database. Other substrings are read a page at a time and checked here.

Groups are entries. Each group with somebody active in it is a groupOfNames at cn=<name>,ou=groups,<base>, with a member for each active person. That is where a person's memberOf points. A search of ou=groups, or a subtree search of the base, finds them, paged like people.

Whoever can read the directory can read the groups. Anyone else has their groups on their own entry. An empty group is not published, since groupOfNames must have a member, and publishing it would need a placeholder member. Through an outpost, groups are read from the core in the same way.

The schema is published. The "root DSE" is the entry a client reads first, to learn what a directory supports. It names cn=Subschema as subschemaSubentry. A base search of that entry needs no bind. It returns attributeTypes, objectClasses and ldapSyntaxes: what this directory holds, single-valued where it is, not what the standard allows.

Every person can be found, and a truncated result says so. A filter on uid, mail, cn or memberOf, alone or in an AND or OR, is asked of the database. So one person among a hundred thousand is one query. Anything else is read a page at a time and checked here. That is slower, and gives the same result, because the database only narrows the candidates and this check decides.

A search returns 500 entries at most. Past that, it answers adminLimitExceeded, or sizeLimitExceeded for a limit the client set, with the entries so far. It never answers success. To read more, use the RFC 2696 paged results control (ldapsearch -E pr=500/noprompt), which the root DSE advertises.

A page carries on from its last entry, however far in that is. A cookie this directory did not issue is a protocolError.

The search base and scope are honoured. Every person is a direct child of the base DN, so the scope works like this:

  • A one-level search reaches people only from the base DN.
  • A subtree search reaches everyone from the base DN, or one person from that person's DN.
  • A search based anywhere else returns nobody. ou=groups,… reaches the groups and no person.

A critical control is refused. A request "control" asks the directory to carry out an operation in a particular way, such as sorting its results. Signari applies one request control: paged results on a search, from RFC 2696. An operation carrying any other control marked critical is not performed, and is answered unavailableCriticalExtension (12), as RFC 4511 §4.1.11 requires. Any other control that is not critical is ignored.

One organisation per listener. LDAP has no way to name an organisation, which some products call a "tenant". The DN is the only input, and the client chooses it. Inferring the organisation from data an attacker controls, and getting it wrong, means binding someone against another organisation's directory. SIGNARI_LDAP_ORG_ID is required unless the database holds exactly one organisation.

Binds go through the same credential path as the sign-in form. They use the same query, including its status check, the same Argon2 parameters and the same throttling. A separate credential path for LDAP would bypass the controls the rest of Signari applies.

The guessing budget, and what a client sees when it is spent

Failed binds are counted on two keys: 20 per address per 5 minutes and 30 per account per 15 minutes. Both are the same buckets the sign-in form uses, not a second allowance of the same size, so guessing through both does not double the number of attempts.

Only failures are charged. A correct bind costs nothing. So a mail server, or a virtual private network (VPN) concentrator that binds on every request, is never throttled by its own success. The limits expire by themselves. There is no lockout, and no administrator action is needed to clear one.

The place is taken before the password is verified. Each bind claims its place in both budgets first, and hands it back unless the password turns out to be wrong.

A burst of sixty wrong binds produces thirty verifications and thirty busy answers. Binds in flight count while they are in flight. So a single client making more simultaneous binds than the limit is told busy for the rest.

A bind has ten seconds, the wait for the shared hasher included. Past that, it answers busy and the client retries. The verification waits for the same hasher slots as the sign-in form. Without a deadline, a flood of binds would queue there indefinitely, ahead of people signing in at the browser.

A bind refused for throttling answers busy (51), not invalidCredentials (49). Every other failure gets the same answer: no such person, a wrong password, or a deactivated account. Telling them apart would be an oracle for which accounts exist, for anyone who can open the port.

Throttling is the exception, for two reasons. Its answer is identical whether or not the account exists, so it discloses nothing. And reporting it as a bad password would send an administrator to rotate a credential that was correct, while the guessing that spent the budget went unseen.

A password alone, and a second factor

A bind has one credential field. Remote Authentication Dial-In User Service (RADIUS) with the Password Authentication Protocol (PAP) is the same, and so are the outposts (see outposts). So a person with an authenticator can put their code after their password, as password;123456: six to eight digits after the last semicolon.

The code is held to what the sign-in form holds a code to. It is spent once, and a wrong one is charged to the authenticator and to the person's budget. A code that is given has to be right, even where the password alone would have done. A password that itself ends that way still works.

An emailed or texted code cannot be used. Each is taken only for the sign-in it was sent for, and nothing here sends one.

Each organisation decides what happens when the person binding is someone its sign-in page would ask for a second factor. Under the built-in flow, that is anybody who has one enrolled. Under an unconditional mfa stage, it is everybody.

A registered security key or passkey counts as enrolled, because the sign-in page asks for one after a password. So a person who has registered a passkey is refused a password-only bind under refuse_when_mfa. The setting is password_only_binds:

password_only_bindsA correct password from such a person
refuse_when_mfarefused unless a code came with it, answered as invalidCredentials (49) like any other failure, and audited as login.failed with reason second_factor_required. The default for organisations created since migration 0128
allowaccepted. The value every older organisation keeps until changed, so an upgrade does not stop a VPN working

Set it with signari instance password-binds -org <id> -binds refuse_when_mfa. signari doctor names every organisation still set to allow that has an LDAP or RADIUS listener or outpost. Under allow, the LDAP or RADIUS port accepts a password alone from a person whose sign-in page asks for a second factor, so a stolen password works at a VPN prompt.

The refusal is checked after the password. So the timing and the answer are the same as for a wrong password, and a guesser learns nothing from it. It is not charged to the guessing budget, because the password was right. A client retrying it in a loop would otherwise spend the person's budget at the sign-in page as well. If whether the person has a second factor cannot be read, the bind is refused.

Service accounts that bind to the directory should have no second factor enrolled, or refuse_when_mfa refuses them too. A person with a second factor carries the code with the password instead: the ;123456 suffix above, or, over RADIUS, the Access-Challenge that RADIUS describes. This setting decides only what happens to a bind that carries no code.

Writes

To allow writes to the directory, name the group whose members may write:

ShellSIGNARI_LDAP_WRITE_GROUP=directory-admins

The variable above names who can write, and the engine builds a writer only when it is set. A read-only deployment refuses every write with unwillingToPerform(53).

An empty value means nobody can write. That is the "fail-closed" reading, which refuses when in doubt, as the Shared Signals (SSF) stream's Allows field does. Reading an unset list as "everybody" would turn a half-made configuration into the ability to rewrite the directory, and then bind as anybody in it.

It is a group, not a list of DNs. So the people who hold it appear in their own memberOf, and are managed with signari group member like every other privilege. Startup logs a warning naming the group, so the grant shows somewhere besides an environment variable.

A refusal distinguishes the two cases. It is unwillingToPerform(53) for a read-only directory, and insufficientAccessRights(50) for a bound identity outside the group. Each points an administrator to a different fix. Neither tells an attacker anything they could not learn by trying with any account.

The schema

internal/ldapd/schema.go is an explicit table. Anything not in it is answered undefinedAttributeType(17), not accepted and ignored:

attribute
uidnaming attributenot modifiable: notAllowedOnRDN(67), which names the operation to use instead
cnMUST (RFC 4519 person)writable
snMUST (RFC 4519 person)writable
givenName, displayName, mailwritable
userPasswordwrite-onlynever returned by a search, at any value
memberOfderivedNO-USER-MODIFICATION, because it is a view of group membership
objectClassstructuralfixed: objectClassModsProhibited(69)

Three columns hold this schema: display_name for cn, surname for sn, and given_name for givenName, which the schema makes optional.

sn is a MUST attribute of person, a class every entry here declares. A row with no surname is given one derived from the display name when it is read. That is a guess, and is labelled as one in the code. The alternative is publishing a person with no sn, which a schema-aware client is entitled to reject.

Result codes

Result codes are as specific as the specification allows, because a directory client acts on them:

  • entryAlreadyExists(68) tells a provisioning run to move on.
  • constraintViolation(19) tells it to fix the data.
  • notAllowedOnRDN(67) tells it to use modify DN.

Answering every failure with unwillingToPerform would tell a client only that something went wrong, and it could keep retrying.

Modify is atomic, and resolved before it is applied

RFC 4511 says, in §4.6: "The entire list of modifications MUST be performed in the order they are listed as a single atomic operation ... the client may expect that no modifications of the DIT have been performed if the Modify Response received indicates any sort of error."

So the changes are folded into a final state against the entry as it stands, and the store applies that state in one transaction. Applying them one at a time against the database would make a failure halfway through a partial write, which §4.6 forbids.

The MUST attributes are checked on the result, not per change. A request that deletes sn and adds it back is legal. One that only deletes it is not.

Deleting userPassword removes the credential and keeps the account. It is refused with constraintViolation unless the entry holds at least two passkeys. Otherwise nothing would be left to sign in with (see signing in without a password).

delete deletes

It does not deactivate. If a delete only deactivated the entry, a later search would not find it, but the row would still be there, although the client asked for it to be gone.

The person's sessions are ended first, in the same transaction. So each application they signed in to is sent a Back-Channel Logout notice, with reason user_deleted. Letting the delete cascade the sessions away would remove the list of applications to tell before anyone was told.

It is not signari erase subject. Deleting removes the row and everything cascading from it. It does not destroy the subject's data-encryption key, so the key stays in the database, and ciphertext sealed under it stays readable. Crypto-shredding, destroying that key, is a separate operation. See erasing a subject.

modify DN and deleteoldrdn

RFC 4511 §4.9 says that with deleteoldrdn FALSE, "the attribute values forming the old RDN will be retained as non-distinguished attribute values of the entry".

uid is single-valued here, so that cannot be represented. It is refused (constraintViolation), not ignored. Accepting FALSE and then dropping the old value would contradict the flag.

newSuperior is refused for anything but the base DN. This directory is flat, so the only superior that exists is the naming context. §4.9 specifies noSuchObject with matchedDN for that case.

Every write is audited, inside its own transaction

The audit record is written in the same transaction as the change, so a change cannot commit without its record. Deletion is audited before the row goes, because afterwards there is no subject for the event to name.

The entry is named by its subject ID, and the bound account by actor_id. A rename records that the username moved, not what to.

A password set through this path gets its own event, separate from "the entry was modified". Somebody with directory write access can set any password, then bind as that person, so an investigation needs to find these events on their own.

A write refused because the bound account is not in the write group is audited too. It is audited as ldap.write_refused, with the operation (add, modify, delete, modify_dn), by the account's subject ID.

Passwords go through the same policy as the sign-in form. On a directory write, no person is at a form to be told what is wrong with a password, so without the policy this path could fill the directory with weak passwords.

Writes are in-process only

The LDAP outpost has no write path back to the engine, and refuses everything with unwillingToPerform. Adding one would mean putting directory changes on the outpost API, which by design only verifies passwords.

POSIX accounts

A host can take its accounts from this directory, through the System Security Services Daemon (SSSD) or anything else that reads RFC 2307. To publish POSIX (Portable Operating System Interface) accounts, set:

ShellSIGNARI_LDAP_POSIX=1 SIGNARI_LDAP_POSIX_HOME=/home/{username} SIGNARI_LDAP_POSIX_SHELL=/bin/bash

People then also carry posixAccount, with uid, uidNumber, gidNumber, homeDirectory, loginShell and gecos. Groups carry posixGroup, with gidNumber and memberUid beside member. Nothing changes for a directory that does not ask. All of it is read-only here.

The host still binds with a search account, because a person who only binds sees their own entry. So put that account in the group that SIGNARI_LDAP_SEARCH_GROUP names.

Every person and group has a number from when they are made. It comes from a sequence that never goes back. So deleting somebody frees nothing, and a new employee can never be given an erased one's files. Numbers start at 2000000000, well above a host's own accounts. The sequence is the deployment's, so an organisation comparing two of its own numbers can estimate how many accounts were made between them.

A number you already have can be kept. Suppose you are moving from a directory whose hosts have files owned by uid 1234. Set posix_uid on PATCH /admin/users/{userID}, and posix_gid on PATCH /admin/groups/{groupID}. They take 1000 to 1999999999. Nothing allocated can land there, and below it are a host's own accounts, root among them. Two people in an organisation cannot share one.

A restore from a backup restores the sequence too, so numbers given out after that backup can be given out again. A host that kept their files should be treated with the same care as the people it restored.

A person's gidNumber is their own number, the group private to them. This directory publishes no such group, so id shows the number where a name would be. Groups they belong to come through memberUid, and show normally. A group with nobody in it is not published, here as anywhere in this directory.

Not implemented

Referrals, aliases, every request control but paged results, and the Simple Authentication and Security Layer (SASL) are not implemented.

Group entries are read-only. Membership is managed where groups are, and a write through LDAP would be a second way to change it.