2022-05-26 10:06:25 -05:00
---
aliases:
2022-12-09 10:36:04 -06:00
- ../../../auth/ldap/
- ../../../installation/ldap/
2022-06-02 11:57:22 -05:00
description: Grafana LDAP Authentication Guide
title: Configure LDAP Authentication
weight: 800
2022-05-26 10:06:25 -05:00
---
2015-07-15 07:48:39 -05:00
2022-06-02 11:57:22 -05:00
# Configure LDAP authentication
2018-09-06 05:11:56 -05:00
The LDAP integration in Grafana allows your Grafana users to login with their LDAP credentials. You can also specify mappings between LDAP
2018-09-12 10:54:47 -05:00
group memberships and Grafana Organization user roles.
2022-12-21 02:44:23 -06:00
> [Enhanced LDAP authentication]({{< relref "../enhanced-ldap/" >}}) is available in [Grafana Cloud Advanced](/docs/grafana-cloud/) and in [Grafana Enterprise]({{< relref "../../../../introduction/grafana-enterprise/" >}}).
2020-02-18 14:28:59 -06:00
2022-10-17 15:24:33 -05:00
> Refer to [Role-based access control]({{< relref "../../../../administration/roles-and-permissions/access-control/" >}}) to understand how you can control access with role-based permissions.
2021-07-29 03:38:46 -05:00
2018-09-12 10:54:47 -05:00
## Supported LDAP Servers
Grafana uses a [third-party LDAP library ](https://github.com/go-ldap/ldap ) under the hood that supports basic LDAP v3 functionality.
This means that you should be able to configure LDAP integration using any compliant LDAPv3 server, for example [OpenLDAP ](#openldap ) or
[Active Directory ](#active-directory ) among [others ](https://en.wikipedia.org/wiki/Directory_service#LDAP_implementations ).
2018-09-06 05:11:56 -05:00
2018-09-06 06:15:36 -05:00
## Enable LDAP
2018-09-06 05:11:56 -05:00
2022-10-17 15:24:33 -05:00
In order to use LDAP integration you'll first need to enable LDAP in the [main config file ]({{< relref "../../../configure-grafana/" >}} ) as well as specify the path to the LDAP
2015-07-15 07:48:39 -05:00
specific configuration file (default: `/etc/grafana/ldap.toml` ).
2023-03-03 16:20:08 -06:00
After enabling LDAP, the default behavior is for Grafana users to be created automatically upon successful LDAP authentication. If you prefer for only existing Grafana users to be able to sign in, you can change `allow_sign_up` to `false` in the `[auth.ldap]` section.
2022-10-12 06:33:33 -05:00
```ini
[auth.ldap]
# Set to `true` to enable LDAP integration (default: `false`)
enabled = true
# Path to the LDAP specific configuration file (default: `/etc/grafana/ldap.toml`)
config_file = /etc/grafana/ldap.toml
# Allow sign-up should be `true` (default) to allow Grafana to create users on successful LDAP authentication.
# If set to `false` only already existing Grafana users will be able to login.
allow_sign_up = true
```
## Disable org role synchronization
If you use LDAP to authenticate users but don't use role mapping, and prefer to manually assign organizations
and roles, you can use the `skip_org_role_sync` configuration option.
```ini
2018-09-06 06:15:36 -05:00
[auth.ldap]
# Set to `true` to enable LDAP integration (default: `false`)
enabled = true
2018-09-12 10:54:47 -05:00
2018-09-06 06:15:36 -05:00
# Path to the LDAP specific configuration file (default: `/etc/grafana/ldap.toml`)
2018-09-12 10:54:47 -05:00
config_file = /etc/grafana/ldap.toml
2022-10-12 06:33:33 -05:00
# Allow sign-up should be `true` (default) to allow Grafana to create users on successful LDAP authentication.
# If set to `false` only already existing Grafana users will be able to login.
2018-09-06 06:15:36 -05:00
allow_sign_up = true
2022-10-12 06:33:33 -05:00
# Prevent synchronizing ldap users organization roles
skip_org_role_sync = true
2018-09-06 06:15:36 -05:00
```
2018-09-12 10:54:47 -05:00
## Grafana LDAP Configuration
2015-07-15 07:48:39 -05:00
2018-09-12 10:54:47 -05:00
Depending on which LDAP server you're using and how that's configured your Grafana LDAP configuration may vary.
See [configuration examples ](#configuration-examples ) for more information.
2015-07-15 07:48:39 -05:00
2018-09-12 10:54:47 -05:00
**LDAP specific configuration file (ldap.toml) example:**
2021-08-06 08:52:36 -05:00
2018-09-12 10:54:47 -05:00
```bash
2015-07-15 07:48:39 -05:00
[[servers]]
2015-10-26 10:21:03 -05:00
# Ldap server host (specify multiple hosts space separated)
2022-08-08 10:27:22 -05:00
host = "ldap.my_secure_remote_server.org"
2015-10-26 10:21:03 -05:00
# Default port is 389 or 636 if use_ssl = true
2022-08-08 10:27:22 -05:00
port = 636
2020-12-23 02:14:02 -06:00
# Set to true if LDAP server should use an encrypted TLS connection (either with STARTTLS or LDAPS)
2022-08-08 10:27:22 -05:00
use_ssl = true
2020-12-23 02:14:02 -06:00
# If set to true, use LDAP with STARTTLS instead of LDAPS
2016-09-10 02:40:57 -05:00
start_tls = false
2023-02-28 05:13:46 -06:00
# The value of an accepted TLS cipher. By default, this value is empty. Example value: ["TLS_AES_256_GCM_SHA384"])
# For a complete list of supported ciphers and TLS versions, refer to: https://go.dev/src/crypto/tls/cipher_suites.go
tls_ciphers = []
# This is the minimum TLS version allowed. By default, this value is empty. Accepted values are: TLS1.1, TLS1.2, TLS1.3.
min_tls_version = ""
2020-05-18 15:56:23 -05:00
# set to true if you want to skip SSL cert validation
2015-07-16 04:57:59 -05:00
ssl_skip_verify = false
2015-10-26 10:21:03 -05:00
# set to the path to your root CA certificate or leave unset to use system defaults
2017-04-06 02:53:11 -05:00
# root_ca_cert = "/path/to/certificate.crt"
2018-08-03 05:00:20 -05:00
# Authentication against LDAP servers requiring client certificates
# client_cert = "/path/to/client.crt"
# client_key = "/path/to/client.key"
2015-07-15 07:48:39 -05:00
# Search user bind dn
bind_dn = "cn=admin,dc=grafana,dc=org"
# Search user bind password
2018-02-15 12:41:04 -06:00
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
2022-03-02 15:08:46 -06:00
bind_password = "grafana"
2022-10-07 11:04:37 -05:00
# We recommend using variable expansion for the bind_password, for more info https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#variable-expansion
# bind_password = '$__env{LDAP_BIND_PASSWORD}'
2015-07-15 07:48:39 -05:00
2022-07-08 01:52:54 -05:00
# Timeout in seconds. Applies to each host specified in the 'host' entry (space separated).
timeout = 10
2015-10-26 10:21:03 -05:00
# User search filter, for example "(cn=%s)" or "(sAMAccountName=%s)" or "(uid=%s)"
2018-08-08 11:13:28 -05:00
# Allow login from email or username, example "(|(sAMAccountName=%s)(userPrincipalName=%s))"
2015-07-15 07:48:39 -05:00
search_filter = "(cn=%s)"
2015-10-26 10:21:03 -05:00
2015-07-15 07:48:39 -05:00
# An array of base dns to search through
search_base_dns = ["dc=grafana,dc=org"]
2015-10-26 10:21:03 -05:00
# group_search_filter = "(&(objectClass=posixGroup)(memberUid=%s))"
2018-09-12 10:54:47 -05:00
# group_search_filter_user_attribute = "distinguishedName"
2015-10-26 10:21:03 -05:00
# group_search_base_dns = ["ou=groups,dc=grafana,dc=org"]
2020-05-18 15:56:23 -05:00
# Specify names of the LDAP attributes your LDAP uses
2015-07-15 07:48:39 -05:00
[servers.attributes]
member_of = "memberOf"
email = "email"
```
2020-04-02 16:07:49 -05:00
### Using environment variables
2020-11-03 05:09:49 -06:00
You can interpolate variables in the TOML configuration from environment variables. For instance, you could externalize your `bind_password` that way:
2020-04-02 16:07:49 -05:00
```bash
bind_password = "${LDAP_ADMIN_PASSWORD}"
```
2019-10-01 03:18:59 -05:00
## LDAP Debug View
> Only available in Grafana v6.4+
Grafana has an LDAP debug view built-in which allows you to test your LDAP configuration directly within Grafana. At the moment of writing, only Grafana admins can use the LDAP debug view.
2020-11-09 14:26:49 -06:00
2019-10-01 03:18:59 -05:00
Within this view, you'll be able to see which LDAP servers are currently reachable and test your current configuration.
2021-05-28 04:27:40 -05:00
{{< figure src = "/static/img/docs/ldap_debug.png" class = "docs-image--no-shadow" max-width = "600px" > }}
2019-10-01 03:18:59 -05:00
To use the debug view:
2021-08-06 08:52:36 -05:00
1. Type the username of a user that exists within any of your LDAP server(s)
1. Then, press "Run"
1. If the user is found within any of your LDAP instances, the mapping information is displayed
2019-10-01 03:18:59 -05:00
2021-05-28 04:27:40 -05:00
{{< figure src = "/static/img/docs/ldap_debug_mapping_testing.png" class = "docs-image--no-shadow" max-width = "600px" > }}
2019-10-01 03:18:59 -05:00
2022-10-17 15:24:33 -05:00
[Grafana Enterprise ]({{< relref "../../../../introduction/grafana-enterprise" >}} ) users with [enhanced LDAP integration ]({{< relref "../enhanced-ldap" >}} ) enabled can also see sync status in the debug view. This requires the `ldap.status:read` permission.
2022-10-11 17:57:27 -05:00
{{< figure src = "/static/img/docs/ldap_sync_debug.png" class = "docs-image--no-shadow" max-width = "600px" > }}
2018-09-12 10:54:47 -05:00
### Bind
2019-10-03 11:20:52 -05:00
#### Bind and Bind Password
2015-07-15 07:48:39 -05:00
2015-08-11 21:46:37 -05:00
By default the configuration expects you to specify a bind DN and bind password. This should be a read only user that can perform LDAP searches.
2019-10-03 11:20:52 -05:00
When the user DN is found a second bind is performed with the user provided username and password (in the normal Grafana login form).
2015-07-15 07:48:39 -05:00
2017-10-05 12:01:03 -05:00
```bash
2015-07-15 07:48:39 -05:00
bind_dn = "cn=admin,dc=grafana,dc=org"
bind_password = "grafana"
```
2018-09-12 10:54:47 -05:00
#### Single Bind Example
2015-07-15 07:48:39 -05:00
2015-08-11 13:58:30 -05:00
If you can provide a single bind expression that matches all possible users, you can skip the second bind and bind against the user DN directly.
2015-07-15 07:48:39 -05:00
This allows you to not specify a bind_password in the configuration file.
2017-10-05 12:01:03 -05:00
```bash
2015-07-15 07:48:39 -05:00
bind_dn = "cn=%s,o=users,dc=grafana,dc=org"
```
2015-08-11 21:46:37 -05:00
In this case you skip providing a `bind_password` and instead provide a `bind_dn` value with a `%s` somewhere. This will be replaced with the username entered in on the Grafana login page.
2015-10-22 00:09:07 -05:00
The search filter and search bases settings are still needed to perform the LDAP search to retrieve the other LDAP information (like LDAP groups and email).
2015-07-15 07:48:39 -05:00
2018-09-12 10:54:47 -05:00
### POSIX schema
2021-08-06 08:52:36 -05:00
2020-05-18 15:56:23 -05:00
If your LDAP server does not support the memberOf attribute add these options:
2015-10-26 10:21:03 -05:00
2018-09-06 06:15:36 -05:00
```bash
2015-10-26 10:21:03 -05:00
## Group search filter, to retrieve the groups of which the user is a member (only set if memberOf attribute is not available)
group_search_filter = "(& (objectClass=posixGroup)(memberUid=%s))"
## An array of the base DNs to search through for groups. Typically uses ou=groups
group_search_base_dns = ["ou=groups,dc=grafana,dc=org"]
2018-09-14 04:28:17 -05:00
## the %s in the search filter will be replaced with the attribute defined below
group_search_filter_user_attribute = "uid"
2015-10-26 10:21:03 -05:00
```
2018-09-12 10:54:47 -05:00
### Group Mappings
2015-10-26 10:21:03 -05:00
2023-03-23 11:27:57 -05:00
In `[[servers.group_mappings]]` you can map an LDAP group to a Grafana organization and role. These will be synced every time the user logs in, with LDAP being the authoritative source.
2015-07-15 07:48:39 -05:00
2020-11-03 05:09:49 -06:00
The first group mapping that an LDAP user is matched to will be used for the sync. If you have LDAP users that fit multiple mappings, the topmost mapping in the TOML configuration will be used.
2015-08-12 09:30:48 -05:00
2018-09-12 10:54:47 -05:00
**LDAP specific configuration file (ldap.toml) example:**
2021-08-06 08:52:36 -05:00
2018-09-12 10:54:47 -05:00
```bash
[[servers]]
# other settings omitted for clarity
[[servers.group_mappings]]
group_dn = "cn=superadmins,dc=grafana,dc=org"
org_role = "Admin"
grafana_admin = true # Available in Grafana v5.3 and above
[[servers.group_mappings]]
group_dn = "cn=admins,dc=grafana,dc=org"
org_role = "Admin"
2018-07-16 09:56:42 -05:00
2018-09-12 10:54:47 -05:00
[[servers.group_mappings]]
group_dn = "cn=users,dc=grafana,dc=org"
org_role = "Editor"
2015-07-15 07:48:39 -05:00
2018-09-12 10:54:47 -05:00
[[servers.group_mappings]]
group_dn = "*"
org_role = "Viewer"
```
2021-08-06 08:52:36 -05:00
| Setting | Required | Description | Default |
| --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------- |
| `group_dn` | Yes | LDAP distinguished name (DN) of LDAP group. If you want to match all (or no LDAP groups) then you can use wildcard (`"*"`) |
2022-10-03 08:20:19 -05:00
| `org_role` | Yes | Assign users of `group_dn` the organization role `Admin` , `Editor` , or `Viewer` . The organization role name is case sensitive. |
2021-08-06 08:52:36 -05:00
| `org_id` | No | The Grafana organization database id. Setting this allows for multiple group_dn's to be assigned to the same `org_role` provided the `org_id` differs | `1` (default org id) |
| `grafana_admin` | No | When `true` makes user of `group_dn` Grafana server admin. A Grafana server admin has admin access over all organizations and users. Available in Grafana v5.3 and above | `false` |
2018-09-12 10:54:47 -05:00
2022-07-12 10:11:09 -05:00
Note: Commenting out a group mapping requires also commenting out the header of
said group or it will fail validation as an empty mapping. Example:
```bash
[[servers]]
# other settings omitted for clarity
[[servers.group_mappings]]
group_dn = "cn=superadmins,dc=grafana,dc=org"
org_role = "Admin"
grafana_admin = true # Available in Grafana v5.3 and above
# [[servers.group_mappings]]
# group_dn = "cn=admins,dc=grafana,dc=org"
# org_role = "Admin"
[[servers.group_mappings]]
group_dn = "cn=users,dc=grafana,dc=org"
org_role = "Editor"
```
2018-09-12 10:54:47 -05:00
### Nested/recursive group membership
Users with nested/recursive group membership must have an LDAP server that supports `LDAP_MATCHING_RULE_IN_CHAIN`
and configure `group_search_filter` in a way that it returns the groups the submitted username is a member of.
2020-03-03 11:11:16 -06:00
To configure `group_search_filter` :
2021-08-06 08:52:36 -05:00
2020-10-02 13:02:11 -05:00
- You can set `group_search_base_dns` to specify where the matching groups are defined.
- If you do not use `group_search_base_dns` , then the previously defined `search_base_dns` is used.
2020-03-03 11:11:16 -06:00
2018-09-12 10:54:47 -05:00
**Active Directory example:**
Active Directory groups store the Distinguished Names (DNs) of members, so your filter will need to know the DN for the user based only on the submitted username.
2020-03-03 11:11:16 -06:00
Multiple DN templates can be searched by combining filters with the LDAP OR-operator. Two examples:
```bash
group_search_filter = "(member:1.2.840.113556.1.4.1941:=%s)"
group_search_base_dns = ["DC=mycorp,DC=mytld"]
group_search_filter_user_attribute = "dn"
```
2018-09-12 10:54:47 -05:00
```bash
group_search_filter = "(member:1.2.840.113556.1.4.1941:=CN=%s,[user container/OU])"
group_search_filter = "(|(member:1.2.840.113556.1.4.1941:=CN=%s,[user container/OU])(member:1.2.840.113556.1.4.1941:=CN=%s,[another user container/OU]))"
2018-09-14 04:28:17 -05:00
group_search_filter_user_attribute = "cn"
2018-09-12 10:54:47 -05:00
```
2020-03-03 11:11:16 -06:00
2018-10-01 10:41:19 -05:00
For more information on AD searches see [Microsoft's Search Filter Syntax ](https://docs.microsoft.com/en-us/windows/desktop/adsi/search-filter-syntax ) documentation.
2015-10-26 10:21:03 -05:00
2018-09-14 04:28:17 -05:00
For troubleshooting, by changing `member_of` in `[servers.attributes]` to "dn" it will show you more accurate group memberships when [debug is enabled ](#troubleshooting ).
2018-09-12 10:54:47 -05:00
## Configuration examples
### OpenLDAP
[OpenLDAP ](http://www.openldap.org/ ) is an open source directory service.
**LDAP specific configuration file (ldap.toml):**
2021-08-06 08:52:36 -05:00
2018-09-12 10:54:47 -05:00
```bash
[[servers]]
host = "127.0.0.1"
port = 389
use_ssl = false
start_tls = false
ssl_skip_verify = false
bind_dn = "cn=admin,dc=grafana,dc=org"
2022-03-02 15:08:46 -06:00
bind_password = "grafana"
2018-09-12 10:54:47 -05:00
search_filter = "(cn=%s)"
search_base_dns = ["dc=grafana,dc=org"]
[servers.attributes]
member_of = "memberOf"
email = "email"
# [[servers.group_mappings]] omitted for clarity
```
2019-05-22 06:53:33 -05:00
### Multiple LDAP servers
Grafana does support receiving information from multiple LDAP servers.
**LDAP specific configuration file (ldap.toml):**
2021-08-06 08:52:36 -05:00
2019-05-22 06:53:33 -05:00
```bash
# --- First LDAP Server ---
[[servers]]
host = "10.0.0.1"
port = 389
use_ssl = false
start_tls = false
ssl_skip_verify = false
bind_dn = "cn=admin,dc=grafana,dc=org"
2022-03-02 15:08:46 -06:00
bind_password = "grafana"
2019-05-22 06:53:33 -05:00
search_filter = "(cn=%s)"
search_base_dns = ["ou=users,dc=grafana,dc=org"]
[servers.attributes]
member_of = "memberOf"
email = "email"
[[servers.group_mappings]]
group_dn = "cn=admins,ou=groups,dc=grafana,dc=org"
org_role = "Admin"
grafana_admin = true
# --- Second LDAP Server ---
[[servers]]
host = "10.0.0.2"
port = 389
use_ssl = false
start_tls = false
ssl_skip_verify = false
bind_dn = "cn=admin,dc=grafana,dc=org"
2022-03-02 15:08:46 -06:00
bind_password = "grafana"
2019-05-22 06:53:33 -05:00
search_filter = "(cn=%s)"
search_base_dns = ["ou=users,dc=grafana,dc=org"]
[servers.attributes]
member_of = "memberOf"
email = "email"
[[servers.group_mappings]]
group_dn = "cn=editors,ou=groups,dc=grafana,dc=org"
org_role = "Editor"
[[servers.group_mappings]]
group_dn = "*"
org_role = "Viewer"
```
2018-09-12 10:54:47 -05:00
### Active Directory
2021-08-06 08:52:36 -05:00
[Active Directory ](<https://technet.microsoft.com/en-us/library/hh831484(v=ws.11 ).aspx>) is a directory service which is commonly used in Windows environments.
2018-09-12 10:54:47 -05:00
Assuming the following Active Directory server setup:
2020-10-02 13:02:11 -05:00
- IP address: `10.0.0.1`
- Domain: `CORP`
- DNS name: `corp.local`
2018-09-12 10:54:47 -05:00
**LDAP specific configuration file (ldap.toml):**
2021-08-06 08:52:36 -05:00
2018-09-12 10:54:47 -05:00
```bash
[[servers]]
host = "10.0.0.1"
port = 3269
use_ssl = true
start_tls = false
ssl_skip_verify = true
bind_dn = "CORP\\%s"
search_filter = "(sAMAccountName=%s)"
search_base_dns = ["dc=corp,dc=local"]
[servers.attributes]
member_of = "memberOf"
email = "mail"
# [[servers.group_mappings]] omitted for clarity
```
#### Port requirements
In above example SSL is enabled and an encrypted port have been configured. If your Active Directory don't support SSL please change `enable_ssl = false` and `port = 389` .
2021-08-06 08:52:36 -05:00
Please inspect your Active Directory configuration and documentation to find the correct settings. For more information about Active Directory and port requirements see [link ](<https://technet.microsoft.com/en-us/library/dd772723(v=ws.10 )>).
2018-09-12 10:54:47 -05:00
## Troubleshooting
2022-10-17 15:24:33 -05:00
To troubleshoot and get more log info enable LDAP debug logging in the [main config file ]({{< relref "../../../configure-grafana/" >}} ).
2018-09-12 10:54:47 -05:00
```bash
[log]
filters = ldap:debug
```