> For the complete documentation index, see [llms.txt](https://wiki.datadike.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.datadike.com/pam/administration/identities/ldap-and-ad.md). Agents can also search and read this documentation through its [MCP server](https://wiki.datadike.com/~gitbook/mcp).

# LDAP and Active Directory

Authenticate console users against an LDAP or Active Directory server and provision their user records from directory attributes, including the group membership that drives authorizations.

## What this is and when to use it

Connecting a directory does two things at once: people sign in to the solution with the credentials they already have, and their user record is created here from directory attributes instead of being typed by hand. Group membership comes across with them, which is what makes authorizations maintainable — you add someone to a group in Active Directory and their access here follows, and take them out of it and the access follows too.

Use it whenever the organization already has a directory. Keep a small number of local accounts as well, for emergencies and for local administration, since a directory outage otherwise locks everyone out.

{% hint style="warning" %}
Three different features touch Active Directory, and they are routinely confused:

* **This page** — the directory authenticates *console users* and supplies their attributes. Nothing is installed anywhere.
* **Account discovery and rotation** — directory accounts treated as *managed credentials* the solution stores and rotates. That runs over WinRM or OpenSSH against the domain, not over this LDAP connection. See [Discovery of accounts](https://wiki.datadike.com/pam/administration/accounts/discovery-of-accounts.md).
* **AD Bridge** — joining *Linux servers* to the domain so directory identities become operating-system accounts on the host. That is a property of the target, not of console login.
  {% endhint %}

## Before you start

* The **SYSADMIN** profile.
* Reachability from the solution to the directory, and the service account it will bind with.
* If you intend to use LDAPS, the certificate files, and a maintenance window — the service has to be restarted (see below).
* A decision on scope: which part of the directory you actually want here.

{% hint style="info" %}
During a pilot, do not point the solution at the whole domain. Bring across only the users and accounts you intend to work with. Reducing scope later is much more work than widening it.
{% endhint %}

## Steps

1. Open **System Settings › Authentication › LDAP** and enable the provider. Only enabled providers appear on the login screen.
2. Fill in the directory connection parameters and the bind account for your server, and the part of the tree to search.
3. Set the **User attribute** map — the JSON that says which directory attribute feeds which field here. This is the field that decides whether imported users are usable; see [Attribute mapping](#attribute-mapping).
4. Set the **Organization** that directory users are created in, if user creation is enabled. This determines the tenant they land in.
5. For high availability, configure **LDAP HA** with the fallback server. It is used when the primary does not answer.
6. Save, then read the two warnings below before you consider the job done.

### Attribute mapping

The map is plain JSON. A full Active Directory mapping, including groups:

```json
{
  "username": "samAccountName",
  "name": "displayName",
  "email": "mail",
  "groups": "memberof"
}
```

Omit `groups` and only the users are imported, not the groups they belong to:

```json
{
  "name": "cn",
  "email": "mail",
  "username": "sAMAccountName"
}
```

That second form is deliberate, and it is a common choice: membership of one directory group (say `XPTO`) is what qualifies a person to reach the solution at all, while the access they get once inside is granted entirely here. You get the directory logins without importing the directory's group structure.

### Periodic synchronisation

The import can run on a schedule, so that group membership in the console keeps following the directory instead of reflecting the day someone was first imported.

| Field                | What it does                                                   |
| -------------------- | -------------------------------------------------------------- |
| Periodic import      | Turns the scheduled import on                                  |
| Interval, or Crontab | How often it runs. A crontab expression wins over the interval |
| Organisations        | Which organisations imported users land in                     |
| Recipients           | Who receives the result of each run by e-mail                  |

**Group membership is synchronised in both directions.** On each run, the import compares the directory groups a user belongs to now against the groups they hold here, and removes them from the ones they have left. Move someone out of a group in Active Directory and the next run takes them out of the matching group in the console, and with it the access that group carried.

{% hint style="warning" %}
**Only groups that came from the directory are touched.** The comparison is limited to groups whose name carries the `AD` prefix the import gives them. Groups you create by hand here are never modified by a directory run, which is what you want: local grouping survives, directory grouping follows the directory.

**Leaving the directory is not the same as leaving a group.** Removal from a group is applied on the next run. A user account deleted or disabled in the directory is a different case: the account here is not deactivated by the import, so treat directory offboarding as a separate step. This is also why public-key authentication has to be off, as the warning above explains.
{% endhint %}

### LDAPS

To use LDAP over TLS, load `ldap_ca.pem`, `ldap_cert.pem`, and `ldap_cert.key` onto the appliance and restart the service. The certificates are not uploaded through this screen, and the new files are not picked up until the restart.

{% hint style="danger" %}
**Turn off public-key authentication once directory authentication is live.** In **System Settings › Components › SSH & Terminal Protocol**, **Public key** is enabled by default. If you leave it on, a user who has been removed from Active Directory can still reach assets with an SSH key they registered earlier — their directory account is gone, and the offboarding is silently incomplete. Disable it so every terminal session is authenticated through the directory.
{% endhint %}

## What you should see

The login screen offers the directory as a sign-in option. Nothing else on the settings screen tells you the connection is healthy.

## How to verify it worked

1. Sign in as a directory user who is not already a local user here.
2. Open **Users › Users** and find them. The **Source** column must read `LDAP/AD`, not `Local`. If it reads `Local`, you authenticated against a pre-existing local account and have proved nothing.
3. Check that **Name** and **Email** are populated. Blank fields mean the attribute map is wrong, even though the login succeeded.
4. If you mapped `groups`, confirm the user's **User groups** reflect their directory membership.
5. Check the login appears in the audit trail with the directory as the authentication source. See [Audit trail](https://wiki.datadike.com/pam/administration/audit/audit-trail.md).

The login succeeding on its own is not enough of a check: the common failure is a successful login that produces an unusable user record.

## Common errors

| Symptom                                                | Cause                                                                      | Fix                                                                             |
| ------------------------------------------------------ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| Directory users log in but have no name or email       | The **User attribute** map names attributes the directory does not publish | Correct the JSON — `samAccountName`, `displayName`, `mail` for Active Directory |
| Users import but belong to no groups                   | `groups` is absent from the map                                            | Add `"groups": "memberof"`, or grant access through groups defined here instead |
| LDAPS fails after loading the certificates             | The service was not restarted                                              | Restart the service; the files are read at start-up                             |
| A user removed from the directory still reaches assets | **Public key** authentication is still enabled on the terminal connector   | Disable it in **System Settings › Components › SSH & Terminal Protocol**        |
| A directory user reappears after being deleted here    | The directory is the source of the record                                  | Remove or disable the account at the directory, not here                        |
| Nobody can sign in during a directory outage           | Every account is directory-backed                                          | Keep at least one local emergency account                                       |

## Field reference

| Field                | What it means                                                                    |
| -------------------- | -------------------------------------------------------------------------------- |
| Enable               | Per-provider checkbox. Only enabled providers appear on the login screen         |
| User attribute       | JSON map from directory attributes to `username`, `name`, `email`, and `groups`  |
| Organization         | The tenant that directory users are created in when user creation is enabled     |
| LDAP HA              | A second, high-availability directory server used as fallback                    |
| Periodic import      | Runs the import on a schedule, which is what keeps group membership current      |
| Interval, or Crontab | How often the scheduled import runs. A crontab expression wins over the interval |
| Recipients           | Who receives the outcome of each scheduled run by e-mail                         |

Mapping keys, and their usual Active Directory sources:

| Key        | Directory attribute    | Notes                                               |
| ---------- | ---------------------- | --------------------------------------------------- |
| `username` | `sAMAccountName`       | The login. Must be unique                           |
| `name`     | `displayName`, or `cn` | Display name                                        |
| `email`    | `mail`                 | Notifications and password recovery                 |
| `groups`   | `memberof`             | Optional. Omit to import users without their groups |

Radius is configured alongside the directory providers, but it is an external authentication server rather than a directory — it is most often used to add a one-time-password factor. See [Multi-factor authentication](https://wiki.datadike.com/pam/administration/identities/mfa.md).

## Related pages

* [Users and groups](https://wiki.datadike.com/pam/administration/identities/users-and-groups.md) — the user records this creates
* [Single sign-on](https://wiki.datadike.com/pam/administration/identities/sso.md) — the federated methods: SAML2, OIDC, OAuth2, CAS
* [Multi-factor authentication](https://wiki.datadike.com/pam/administration/identities/mfa.md) — adding a second factor on top
* [Authorizations](https://wiki.datadike.com/pam/administration/access/authorizations.md) — what an imported group can reach
* [Discovery of accounts](https://wiki.datadike.com/pam/administration/accounts/discovery-of-accounts.md) — directory accounts as managed credentials
