LDAP Authentication#

To create a User with the login method "LDAP Authentication," you need to check the box "Use LDAP Authentication," and then fill in the "LDAP Users" field.

You also need to fill in the fields:

Interface ElementDescription
Email*User's email address.
First NameUser's first name.
Last NameUser's last name.
DepartmentSubdivision or department to which the User belongs.
RoleUser's role in the system. Defines available sections and actions.
User is blockedAllows blocking the user's account. A blocked user will not be able to log in.
Notify about license expiration via emailEnables sending notifications to the user's email when the license expiration date approaches.

LDAP sign-in requires an administrator to connect Sherpa AI Server to the organization's directory. Active Directory (AD) uses the same LDAP mechanism. Parameter values depend on the directory structure.

For a Docker installation, set the parameters in the .env file in the Sherpa AI Server installation directory:

  • LDAP_SERVER — directory server hostname or IP address, for example ldap.example.com. For AD, use the domain controller address, for example dc01.example.com.
  • LDAP_PORT — connection port agreed with the directory administrator: usually 389 for LDAP with StartTLS or 636 for LDAPS.
  • LDAP_ENCRYPTION — set tls for both StartTLS on port 389 and LDAPS on port 636. The connection method must match the directory server configuration.
  • LDAP_BASE_DN — full path to the directory branch used to find accounts. For example, use dc=example,dc=com for the example.com domain.
  • LDAP_GROUP — name of an organizational unit (OU) within LDAP_BASE_DN, rather than an AD security group name. For example, People sets the search base to ou=People,dc=example,dc=com. Leave it empty to search the entire LDAP_BASE_DN.
  • LDAP_UID_KEY — directory attribute containing the user's login. Set uid for LDAP accounts with a uid attribute. Set sAMAccountName for AD accounts with a sAMAccountName attribute. The attribute must match the accounts in your directory.
  • LDAP_USER — full DN of the account used to connect to the directory, for example cn=directory-reader,ou=ServiceAccounts,dc=example,dc=com.
  • LDAP_PASSWORD — password for that account. Obtain it from the directory administrator and enter it only in the server configuration.
  • LDAP_USERNAME — account name used to build the DN when LDAP_USER is unset. For example, LDAP_USERNAME=directory-reader, LDAP_GROUP=People, and LDAP_BASE_DN=dc=example,dc=com produce cn=directory-reader,ou=People,dc=example,dc=com. A full DN in LDAP_USER takes precedence.
  • LDAP_FILTER — optional filter for the account list. For example, (objectClass=inetOrgPerson) for matching LDAP entries or (&(objectCategory=person)(objectClass=user)) for AD users. Without a filter, the list includes entries with the attribute specified in LDAP_UID_KEY.

The connection account must have read access to the required directory entries. If the directory allows anonymous connections and searches, LDAP_USER, LDAP_USERNAME, and LDAP_PASSWORD are not required.

LDAP example: server ldap.example.com, StartTLS on port 389, LDAP_ENCRYPTION=tls, LDAP_BASE_DN=dc=example,dc=com, LDAP_GROUP=People, and LDAP_UID_KEY=uid. For AD with the dc01.example.com controller and accounts in OU=Employees, set LDAP_SERVER=dc01.example.com, LDAP_GROUP=Employees, and LDAP_UID_KEY=sAMAccountName. Set the remaining parameters, including the connection account DN and password, according to your directory configuration. The addresses and names in these examples are fictional.

After changing .env, recreate the application container from the installation directory with docker compose up -d --force-recreate aiserver. A regular docker compose restart does not apply updated environment variables. Then select the "Use LDAP Authentication" checkbox in the User form and select an account in the LDAP Users field. Save the User and verify sign-in with that directory account's login and password.

Automatic Role Assignment from AD Groups#

When an LDAP User signs in, Sherpa AI Server assigns Roles whose names match the User's AD groups. This lets administrators manage access through directory group membership.

To enable synchronization, set LDAP_ROLE_SYNC_ENABLED=true in .env and recreate the application container. The default is false: LDAP password authentication still works, but groups are not read and roles are not synchronized. Disabling synchronization keeps existing role assignments. A manual synchronization request returns 422.

When synchronization is enabled, removing an AD group revokes its automatic role at the next login or manual synchronization. For example, if a user has two roles and one group is removed, one role and its permissions remain. Once the last active role is revoked, login is rejected (401). An existing session ends on the next protected request or /api/v1/auth/me check. An active manual role is preserved and allows the user to continue. A deleted role does not count as active.

There is no background AD polling. To restore access, an administrator must restore the group with a matching role and synchronize again, or assign a role manually. The user can then log in again. If reading groups fails, existing roles are preserved. Login remains possible if the user has at least one active role. Local and OAuth users, account login, and API keys are unaffected by this policy.

Before using this feature, create the Roles in the same Account and give them the same names as the AD groups. The group CN from memberOf is compared with the Role name without regard to case or leading and trailing spaces. For example, CN=Finance,OU=Groups,DC=example,DC=com matches the Finance Role. Nested groups are not included. Groups without a matching Role are ignored. Roles and Users are not created from the directory automatically.

Example: if a User belongs to the Finance AD group and the Account has a Finance Role, the Role is assigned automatically after sign-in. If the User leaves the group, the Role is removed at the next sign-in unless it was assigned manually.

After successful LDAP authentication, group-based Roles are updated: new Roles are assigned and Roles for groups the User has left are removed. Roles assigned manually in Sherpa AI Server remain in place. If LDAP credential verification fails, sign-in is rejected.

An administrator with permission to update Users can repeat synchronization for one existing LDAP User through the API: POST /api/v1/users/{user_guid}/ldap_memberships. Use the User's GUID from the current Account in the path. The response includes the numbers of assigned and removed Roles. Roles remain unchanged if AD cannot be read.

To keep an automatically assigned Role after the User leaves an AD group, an administrator with permission to create Roles can make the assignment manual through POST /api/v1/role_user_links/assign. Send the user_id and role_id from the current Account in the request body. Simply saving the User's details does not make the Role assignment manual.