Skip to content

LDAP Authentication ​

This document explains how Txlog Server authenticates users with an LDAP directory, and the reasons for the design. For the values of your .env file, see the LDAP configuration reference. For the procedure, see How to Configure LDAP Authentication.

LDAP and OIDC are the two optional authentication methods. You can enable them at the same time, and the two methods create the same auth.User. If you configure neither, the server has no authentication.

The Authentication Flow ​

  1. The user enters a username and a password on /login.
  2. The server opens a connection to the LDAP host. The connection uses TLS when LDAP_USE_TLS=true.
  3. The server searches LDAP_BASE_DN for the user with LDAP_USER_FILTER. The username replaces %s in the filter.
  4. The server binds as the DN of the user, with the password of the user. The LDAP directory accepts or refuses the password.
  5. The server examines the membership in LDAP_ADMIN_GROUP and LDAP_VIEWER_GROUP with LDAP_GROUP_FILTER.
  6. The server creates or updates the user row and sends a session cookie.

The server does step 3 as the service account, if you configured one. If not, it uses an anonymous bind.

For step 5, the server binds as the service account again. Without a service account, it uses the session of the user from step 4.

The server never reads a password hash and never writes a password to the database.

A user who is in neither group cannot sign in, even with the correct password.

Why the Server Uses a Bind ​

With a bind, the directory is the only authority on credentials. The password policies, account locks and expiration dates of the directory continue to apply. If the directory refuses the bind, the sign-in fails.

Also, the server does not read the password attributes. Most directories do not give access to them.

Attribute Mapping ​

The server reads these values from the directory entry:

FieldSource attributesDefault
Usernamethe sign-in form-
Emailmailusername@local
Display namecn or displayNamethe username

The sub of an LDAP user is ldap:<username>. An OIDC user keeps the sub from the provider. Because of the prefix, two users with the same username do not conflict.

LDAP uses the same users and user_sessions tables as OIDC. As a result, it has no database migration of its own.

Roles ​

There are two roles:

  • Admin group: Has all viewer permissions. Also controls the admin panel, the API keys, the users and the assets.
  • Viewer group: Can only read transactions, assets, packages and statistics.

If a user is in the two groups, the admin role applies.

The Service Account Is Optional ​

LDAP_BIND_DN and LDAP_BIND_PASSWORD are optional. Without them, the directory must let:

  • an anonymous client read the user entries.
  • a user read their own group memberships.

This is the default of OpenLDAP and 389 Directory Server.

If the directory refuses these operations, you must use a service account. Active Directory is the most common example, because it refuses an anonymous bind by default.

DirectoryService accountReason
OpenLDAP (default ACLs)Not necessaryAccepts an anonymous bind by default
OpenLDAP (strict ACLs)NecessaryRefuses an anonymous bind
389 Directory ServerUsually notUsually accepts anonymous reads
Active DirectoryNecessaryRefuses an anonymous bind by policy
FreeIPANecessaryHas strict default access policies

Each option has advantages and disadvantages:

  • Service account: Each search has an identity that you can audit, and you can disable the anonymous bind. But you must store and change one more password.
  • Anonymous bind: There is no password to lose. But you cannot find who did a search.

If your rules tell you to record who read the data, use a service account.

This setting has no effect on the users. You can start without a service account and try to sign in. If the search fails, set the two variables. Give the account only read access to the user and group subtrees.

TLS ​

LDAP_USE_TLS=true connects with TLS and always examines the certificate. You cannot disable this, because the bind sends the password of the user on this connection. If your directory uses a private CA, install that CA on the Txlog Server host.

The server writes each failed sign-in to the log. It does not limit the number of attempts. If you want a limit, set it in the reverse proxy.