2015-05-11 17:40:03 +00:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "Auth Backend: LDAP"
|
|
|
|
sidebar_current: "docs-auth-ldap"
|
|
|
|
description: |-
|
2015-07-28 18:00:57 +00:00
|
|
|
The "ldap" auth backend allows users to authenticate with Vault using LDAP credentials.
|
2015-05-11 17:40:03 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Auth Backend: LDAP
|
|
|
|
|
|
|
|
Name: `ldap`
|
|
|
|
|
|
|
|
The "ldap" auth backend allows authentication using an existing LDAP
|
|
|
|
server and user/password credentials. This allows Vault to be integrated
|
|
|
|
into environments using LDAP without duplicating the user/pass configuration
|
|
|
|
in multiple places.
|
|
|
|
|
|
|
|
The mapping of groups in LDAP to Vault policies is managed by using the
|
2015-07-14 23:13:40 +00:00
|
|
|
`users/` and `groups/` paths.
|
2015-05-11 17:40:03 +00:00
|
|
|
|
|
|
|
## Authentication
|
|
|
|
|
|
|
|
#### Via the CLI
|
|
|
|
|
|
|
|
```
|
|
|
|
$ vault auth -method=ldap username=mitchellh
|
|
|
|
Password (will be hidden):
|
|
|
|
Successfully authenticated! The policies that are associated
|
|
|
|
with this token are listed below:
|
|
|
|
|
|
|
|
root
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Via the API
|
|
|
|
|
|
|
|
The endpoint for the login is `auth/ldap/login/<username>`.
|
|
|
|
|
|
|
|
The password should be sent in the POST body encoded as JSON.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ curl $VAULT_ADDR/v1/auth/ldap/login/mitchellh \
|
2015-06-04 14:38:08 +00:00
|
|
|
-d '{ "password": "foo" }'
|
2015-05-11 17:40:03 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
The response will be in JSON. For example:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
2015-10-12 16:10:22 +00:00
|
|
|
"lease_id": "",
|
|
|
|
"renewable": false,
|
|
|
|
"lease_duration": 0,
|
|
|
|
"data": null,
|
|
|
|
"auth": {
|
|
|
|
"client_token": "c4f280f6-fdb2-18eb-89d3-589e2e834cdb",
|
|
|
|
"policies": [
|
2015-05-11 17:40:03 +00:00
|
|
|
"root"
|
|
|
|
],
|
2015-10-12 16:10:22 +00:00
|
|
|
"metadata": {
|
|
|
|
"username": "mitchellh"
|
2015-05-11 17:40:03 +00:00
|
|
|
},
|
2015-10-12 16:10:22 +00:00
|
|
|
"lease_duration": 0,
|
|
|
|
"renewable": false
|
2015-05-11 17:40:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
First, you must enable the ldap auth backend:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ vault auth-enable ldap
|
|
|
|
Successfully enabled 'ldap' at 'ldap'!
|
|
|
|
```
|
|
|
|
|
|
|
|
Now when you run `vault auth -methods`, the ldap backend is available:
|
|
|
|
|
|
|
|
```
|
|
|
|
Path Type Description
|
|
|
|
ldap/ ldap
|
|
|
|
token/ token token based credentials
|
|
|
|
```
|
|
|
|
|
|
|
|
To use the "ldap" auth backend, an operator must configure it with
|
|
|
|
the address of the LDAP server that is to be used. An example is shown below.
|
2015-07-13 10:12:09 +00:00
|
|
|
Use `vault path-help` for more details.
|
2015-05-11 17:40:03 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
$ vault write auth/ldap/config url="ldap://ldap.forumsys.com" \
|
2015-10-12 16:10:22 +00:00
|
|
|
userattr=uid \
|
|
|
|
userdn="dc=example,dc=com" \
|
|
|
|
groupdn="dc=example,dc=com" \
|
|
|
|
upndomain="forumsys.com" \
|
|
|
|
certificate=@ldap_ca_cert.pem \
|
|
|
|
insecure_tls=false \
|
|
|
|
starttls=true
|
2015-05-11 17:40:03 +00:00
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
The above configures the target LDAP server, along with the parameters
|
|
|
|
specifying how users and groups should be queried from the LDAP server.
|
|
|
|
|
2016-01-27 06:51:10 +00:00
|
|
|
If your users are not located directly below the "userdn", e.g. in several
|
|
|
|
OUs like
|
|
|
|
```
|
|
|
|
ou=users,dc=example,dc=com
|
|
|
|
ou=people ou=external ou=robots
|
|
|
|
```
|
|
|
|
you can also specify a `binddn` and `bindpass` for vault to search for the DN
|
2016-01-27 08:25:05 +00:00
|
|
|
of a user. This also works for the AD where a typical setup is to have user
|
|
|
|
DNs in the form `cn=Firstname Lastname,ou=Users,dc=example,dc=com` but you
|
|
|
|
want to login users using the `sAMAccountName` attribute. For that specify
|
|
|
|
```
|
|
|
|
$ vault write auth/ldap/config url="ldap://ldap.forumsys.com" \
|
|
|
|
userattr=sAMAccountName \
|
|
|
|
userdn="ou=users,dc=example,dc=com" \
|
|
|
|
groupdn="dc=example,dc=com" \
|
|
|
|
binddn="cn=vault,ou=users,dc=example,dc=com" \
|
|
|
|
bindpass='My$ecrt3tP4ss' \
|
|
|
|
certificate=@ldap_ca_cert.pem \
|
|
|
|
insecure_tls=false \
|
|
|
|
starttls=true
|
|
|
|
...
|
|
|
|
```
|
2016-01-27 16:06:27 +00:00
|
|
|
To discover the bind dn for a user with an anonymous bind, use the `discoverdn=true`
|
|
|
|
parameter and leave the `binddn` / `bindpass` empty.
|
2016-01-27 06:51:10 +00:00
|
|
|
|
2015-05-11 17:40:03 +00:00
|
|
|
Next we want to create a mapping from an LDAP group to a Vault policy:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ vault write auth/ldap/groups/scientists policies=foo,bar
|
|
|
|
```
|
|
|
|
|
|
|
|
This maps the LDAP group "scientists" to the "foo" and "bar" Vault policies.
|
|
|
|
|
2015-07-17 21:40:06 +00:00
|
|
|
We can also add specific LDAP users to additional (potentially non-LDAP) groups:
|
2015-07-14 23:13:40 +00:00
|
|
|
|
|
|
|
```
|
2015-07-17 21:40:06 +00:00
|
|
|
$ vault write auth/ldap/groups/engineers policies=foobar
|
|
|
|
$ vault write auth/ldap/users/tesla groups=engineers
|
2015-07-14 23:13:40 +00:00
|
|
|
```
|
|
|
|
|
2015-07-17 21:40:06 +00:00
|
|
|
This adds the LDAP user "tesla" to the "engineers" group, which maps to
|
|
|
|
the "foobar" Vault policy.
|
2015-07-14 23:13:40 +00:00
|
|
|
|
2015-05-11 17:40:03 +00:00
|
|
|
Finally, we can test this by authenticating:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ vault auth -method=ldap username=tesla
|
|
|
|
Password (will be hidden):
|
|
|
|
Successfully authenticated! The policies that are associated
|
|
|
|
with this token are listed below:
|
|
|
|
|
2015-07-14 23:13:40 +00:00
|
|
|
bar, foo, foobar
|
2015-05-11 17:40:03 +00:00
|
|
|
```
|
|
|
|
|