Vault
Use dynamic credentials with LDAP
Use dynamic LDAP credentials and manage LDAP user accounts through LDIF.
Before you start
- Check your Vault permissions. You must have permission to enable and configure plugins in Vault.
- You must have an LDAP plugin configured for OpenLDAP or Active Directory. If you do not already have an LDAP plugin enabled, follow the setup guide.
Step 1: Create your LDAP LDIF entries
Vault manages LDAP accounts through LDIF entries. LDIF entries are a base64-encoded version of the LDIF string that Vault parses and validates against proper LDIF syntax.
LDIF parameters (*_ldif) define account templates using the
go template language.
When you craft your LDIF entries:
- Check for, and remove, trailing spaces on any line, including empty lines.
- Make sure each
modifyblock has an empty line before it and closes with a single dash (-).
You can define multiple modifications for a dn entry in a single modify
block.
Example LDIF file:
dn: uid=johndoe,ou=users,dc=example,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
uid: johndoe
cn: John Doe
sn: Doe
givenName: John
mail: john.doe@example.com
Step 2: Create a Vault role configuration file
For easier maintenance and reuse, create a JSON file ldap-role.json, with the
dynamic role details so Vault knows how to create an LDAP domain user account.
We strongly recommend configuring a rollback LDIF to ensure Vault removes any partialy created entities in the event of a failure. Vault automatically runs the rollback statments if credential creation fails for any reason.
{
"creation_ldif": "@/path/to/creation.ldif",
"deletion_ldif": "@/path/to/deletion.ldif",
"rollback_ldif": "@/path/to/rollback.ldif",
"default_ttl": "1h",
"max_ttl": "24h"
}
Step 3: Save the Vault role
Use vault write with the
/{mount_path}/static-role
path and your dynamic role configuration, ldap-role.json, to create a new
dynamic role entry:
$ vault write <mount_path>/role/<role_name> @ldap-role.json
For example:
$ vault write devcreds/role/developers @ldap-role.json
Step 4: Test credential generation
Generate credentials to confirm setup:
Use vault write with the
/{mount_path}/static-role
path and your dynamic role configuration, ldap-role.json, to create a new
dynamic role entry:
$ vault write <mount_path>/role/<role_name> @ldap-role.json
For example:
$ vault write devcreds/role/developers @ldap-role.json
The distinguished_names field is an array of DNs that are created from the creation_ldif statements. If more than
one LDIF entry is included, the DN from each statement will be included in this field. Each entry in this field
corresponds to a single LDIF statement. No de-duplication occurs and order is maintained.