Skip to content

LDAP Login

Authenticates users against an LDAP or Active Directory server. Requires the Enterprise Edition.

On successful bind, CMDBsyncer looks up a local user by email and logs that user in. If no local user exists, one is auto-created with the email and cn from LDAP.

Roles and the global_admin flag can be driven from LDAP group membership via LDAP_ROLE_MAPPING — see Role Mapping below. When role mapping is configured, LDAP is the source of truth: permissions are recomputed on every login.

Setting It Up

Settings → LDAP Login, or the card LDAP login under Settings → Configuration → Edit local_config.py; both have the same fields. The page is there only when the license includes the LDAP login.

  1. Fill for Active Directory or Fill for OpenLDAP sets how users are found: the search filter and the name attribute, and empties LDAP_USER_DN_TEMPLATE, so the service account searches the user. Server, service account and search base stay as they are.
  2. Enter LDAP_SERVER, LDAP_BIND_USER, LDAP_BIND_PASSWORD and LDAP_SEARCH_BASE of your directory.
  3. Under LDAP_ROLE_MAPPING, give directory groups their rights: one row per group with its full DN, Global admin, the roles and the API roles. Add group adds a row, a row with an emptied group is removed.
  4. Under Test login, enter the login and password of a directory user, as they would type them on the login page, and click Test login. The test uses the values of the card, before they are applied, and saves nothing. It lists every step: the search with the service account, the user found, the login of the user, the groups, the required group, the local user and the rights LDAP_ROLE_MAPPING gives. A failing step comes with what it most likely means, for example an unreachable server, a refused service account, a search base that does not exist or, for Active Directory, a wrong password, an expired password or a locked account. Each test is logged under Settings → Log with source AUTH, who ran it and the result, never the password.
  5. Apply preset and restart the Syncer: the LDAP keys take effect after a restart.

The card shows the values stored in local_config.py; the bind password is never shown, an empty field keeps it. Emptying any other field and applying removes the key, so it goes back to its default.

How It Works

Two modes are supported. Pick the one that matches your directory setup:

Direct-Bind Mode

CMDBsyncer builds the user's DN from a template and binds directly with the submitted password. Fast, no service account required, but only works when every user's DN follows the same pattern.

config = {
    'LDAP_LOGIN': True,
    'LDAP_SERVER': 'ldaps://ldap.example.com',
    'LDAP_USER_DN_TEMPLATE': 'uid={username},ou=people,dc=example,dc=com',
}

The placeholder {username} expands to the local part of the email (everything before @). {email} is also available.

The template must contain one of the two placeholders. A fixed DN is refused, otherwise every login would bind as that one user.

Search-Bind Mode

CMDBsyncer binds first with a service account, searches for the user via a filter, then re-binds as the found DN with the submitted password. Use this when user DNs live in different sub-trees, or when your directory is Active Directory.

config = {
    'LDAP_LOGIN': True,
    'LDAP_SERVER': 'ldaps://ad.example.com',
    'LDAP_BIND_USER': 'cn=syncer,ou=service,dc=example,dc=com',
    'LDAP_BIND_PASSWORD': 'the-service-password',
    'LDAP_SEARCH_BASE': 'ou=people,dc=example,dc=com',
    'LDAP_SEARCH_FILTER': '(mail={email})',
}

LDAP_SEARCH_FILTER supports the placeholders {email} and {username}. For Active Directory (userPrincipalName={email}) or (sAMAccountName={username}) are common choices.

Users can log in with their email or with their account name alone, for example the sAMAccountName in Active Directory. A login without @ gets a local user whose email is the account name plus the domain of the DC= parts of its DN: srv01 in CN=Srv 01,OU=Admins,DC=corp,DC=example,DC=com becomes srv01@corp.example.com. Two accounts of one person, like srv01 and adminsrv01, stay two local users with their own rights.

The filter must contain one of the two placeholders and find exactly one user. When it finds several, the login is refused instead of binding as one of them; the login test lists the users it found.

Configuration Reference

Name Default Description
LDAP_LOGIN False Master switch. Must be True to enable LDAP authentication.
LDAP_SERVER '' Server URL, e.g. ldaps://ldap.example.com (use ldaps:// in production).
LDAP_TLS_CA_FILE '' CA file the server certificate is checked against. Empty = the CAs of the system.
LDAP_USER_DN_TEMPLATE '' Direct-bind mode. Format string with {username} and/or {email} placeholder.
LDAP_BIND_USER '' Search-bind mode. DN of a service account used to locate the user.
LDAP_BIND_PASSWORD '' Password for LDAP_BIND_USER.
LDAP_SEARCH_BASE '' Base DN for the user search (search-bind only).
LDAP_SEARCH_FILTER '(mail={email})' Filter for the user search. Placeholders {email} and {username}.
LDAP_REQUIRED_GROUP '' Full DN of a group. If set, bound user must have it in memberOf.
LDAP_AUTO_CREATE True Auto-create local user record on first successful login.
LDAP_NAME_ATTR 'cn' LDAP attribute used for User.name on creation.
LDAP_ROLE_MAPPING {} Map group DN → permissions. When set, roles sync from LDAP on every login.

Restricting Login to a Group

To allow only members of a specific group to sign in, set LDAP_REQUIRED_GROUP to the full DN of that group:

config = {
    'LDAP_REQUIRED_GROUP': 'cn=syncer-users,ou=groups,dc=example,dc=com',
}

CMDBsyncer reads the memberOf attribute of the bound user and checks — case-insensitively and DN-normalized — whether the required group is present. Users whose memberOf does not contain the group are rejected with "Wrong Password" (the generic message prevents enumeration).

memberOf on OpenLDAP

memberOf is automatic in Active Directory. On OpenLDAP you have to enable the memberof overlay (olcModuleLoad: memberof.la) so this attribute is populated.

User Provisioning

After a successful bind CMDBsyncer looks up the local user by email (disabled__ne=True):

  • Existing, non-disabled user → login succeeds.
  • No matching user and LDAP_AUTO_CREATE = True (default) → a new user record is created with email from the login form and name from the LDAP attribute LDAP_NAME_ATTR (default cn). Falls back to the email if the attribute is absent.
  • No matching user and LDAP_AUTO_CREATE = False → login is rejected.

Disabled users are never auto-logged-in, even if the bind succeeds.

Role Mapping

To drive roles and admin rights from LDAP groups, set LDAP_ROLE_MAPPING, on the page Settings → LDAP Login or in local_config.py. Keys are full group DNs, values are dictionaries of permissions to grant:

config = {
    'LDAP_ROLE_MAPPING': {
        'cn=admins,ou=groups,dc=example,dc=com': {
            'global_admin': True,
        },
        'cn=operators,ou=groups,dc=example,dc=com': {
            'roles': ['host', 'objects', 'log'],
        },
        'cn=api-clients,ou=groups,dc=example,dc=com': {
            'api_roles': ['all'],
        },
    },
}

Supported permission keys per group:

Key Type Effect
global_admin bool Grants the global admin flag.
roles list of str Web UI roles (see roles in application/models/user.py).
api_roles list of str REST API roles (all, ansible, objects, syncer).

Multiple Group Memberships

Group DNs are the outer dict keys and must be unique (standard Python dict semantics). When a user belongs to several mapped groups, CMDBsyncer takes the union of all matched permissions. You do not — and cannot — repeat the roles key within a single group's dict; just list one group per entry and let the union resolve the rest.

config = {
    'LDAP_ROLE_MAPPING': {
        'cn=ops,ou=groups,dc=example,dc=com': {
            'roles': ['host', 'log'],
        },
        'cn=network,ou=groups,dc=example,dc=com': {
            'roles': ['host', 'objects'],
        },
        'cn=api-users,ou=groups,dc=example,dc=com': {
            'api_roles': ['objects'],
        },
        'cn=admins,ou=groups,dc=example,dc=com': {
            'global_admin': True,
            'roles': ['user'],
            'api_roles': ['all'],
        },
    },
}

Example resolutions for this mapping:

memberOf contains Resulting permissions
cn=ops roles=['host', 'log']
cn=ops + cn=network roles=['host', 'log', 'objects'] (duplicates removed)
cn=network + cn=api-users roles=['host', 'objects'], api_roles=['objects']
cn=admins + cn=ops global_admin=True, roles=['host', 'log', 'user'], api_roles=['all']
No matched group roles=[], api_roles=[], global_admin=False

DNs are compared case-insensitively and normalized via ldap3.utils.dn.safe_dn, so whitespace or case differences between the LDAP server's response and the mapping keys do not break the match.

LDAP overwrites manual changes

While LDAP_ROLE_MAPPING is non-empty, roles and global_admin are replaced at each login — grant additional permissions through LDAP group membership, not via the web UI, or they get reverted on the next login. Leave LDAP_ROLE_MAPPING = {} (the default) to disable role sync entirely; new users are then created without roles and you assign them manually.

Local Users and the Local Password

The login checks the local password first. When a local user with that email exists and the password matches, the user is logged in and the directory is not asked: it never sees the password of a local user, and no failed LDAP login is logged for it. The directory is asked only when there is no local user or the local password does not match. You can therefore mix LDAP users and local service accounts without additional configuration.

A user logged in with the local password gets no update of its rights from LDAP_ROLE_MAPPING for that login.

The Syncer waits 10 seconds for the server. An unreachable server, bad TLS or a refused service account count as a failed LDAP login; Settings → LDAP Login and Settings → Log with AUTH_DEBUG show the reason. With AUTH_DEBUG each LDAP login writes one entry, LDAP login: success or LDAP login: refused, with all its steps; a refused login is marked as an error and names the reason. Only an incomplete configuration (no LDAP_SERVER, neither LDAP_USER_DN_TEMPLATE nor LDAP_BIND_USER) aborts the login with LDAP Error.

Security Notes

Always use LDAPS

Plain ldap:// sends the password in cleartext over the network, the login does not upgrade it with StartTLS. In production always use ldaps://.

Server certificate

On ldaps:// the certificate of the directory server is always checked, against the CAs of the system. A certificate of an internal CA needs that CA in the system trust store of the Syncer host, or its file in LDAP_TLS_CA_FILE. A self-signed certificate is refused unless it is set there. Test login in the LDAP card shows a refused certificate as CERTIFICATE_VERIFY_FAILED.

Service-account password

The LDAP_BIND_PASSWORD sits in local_config.py on disk. Restrict file permissions accordingly (chmod 640, owner = the user running CMDBsyncer). Prefer a read-only service account that can only search, never modify.

Troubleshooting

Start with Settings → LDAP Login (global admins). The page shows:

  • whether the login page tries LDAP at all: login test available, LDAP_LOGIN on. While one of them fails, the login page checks local passwords only and answers Wrong Password for every directory user;
  • the LDAP settings the running application uses, without passwords;
  • the LDAP settings to edit, with the same fields and Fill for buttons as the LDAP card of the editor;
  • a test login of a directory user, step by step: connection, service account, search, the user's own bind, groups, required group, local user and its rights. A failing step names what it most likely means.

Test with these values uses the fields as they are and saves nothing; Save writes them to local_config.py. Settings like the server or the service account are used by the running application only after a restart; the page lists the saved keys still waiting for one. The service password never goes back to the browser: after a test, enter it again before Save, an empty field keeps the stored one.

Each test is logged under Settings → Log with source AUTH.

When LDAP_LOGIN is on but the LDAP login is not active, every login writes an AUTH log entry saying so; then check the Enterprise package and the license under Settings → License.

LDAP Error: LDAP_SERVER not configured

LDAP_LOGIN is True but LDAP_SERVER is empty. Set both.

LDAP Error: LDAP_USER_DN_TEMPLATE or LDAP_BIND_USER must be configured

Neither direct-bind nor search-bind mode is fully configured. Set either LDAP_USER_DN_TEMPLATE or LDAP_BIND_USER + LDAP_BIND_PASSWORD + LDAP_SEARCH_BASE.

Login says Wrong Password even though credentials are correct

Check in order:

  1. Settings → LDAP Login shows all preconditions green.
  2. The user's email in CMDBsyncer exactly matches the one used to log in (case is normalized to lowercase on submission).
  3. A local user record exists and is not disabled.
  4. If LDAP_REQUIRED_GROUP is set, the user is actually a member of that group (verify with ldapsearch -b <user_dn> memberOf).

LDAP server is reachable but bind always fails

Test the credentials from the same host with ldapsearch before blaming CMDBsyncer:

ldapsearch -H ldaps://ldap.example.com -x \
    -D 'uid=alice,ou=people,dc=example,dc=com' -W