Configure Grafana LDAP authentication and role-based access control with Active Directory integration

Intermediate 25 min Apr 20, 2026 14 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up Grafana with LDAP authentication to connect with Active Directory, configure role-based access control for teams, and implement production-ready security policies for enterprise environments.

Prerequisites

  • Active Directory server with administrative access
  • Service account for LDAP binding
  • SSL certificates for production deployment

What this solves

This tutorial configures Grafana to authenticate users through LDAP with Active Directory integration. You'll set up role-based access control to automatically assign permissions based on LDAP groups, eliminating manual user management while maintaining security policies across your organization.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you have the latest versions.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install Grafana

Install Grafana from the official repository to get the latest stable version with security updates.

curl -fsSL https://packages.grafana.com/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/grafana.gpg
echo "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
sudo tee /etc/yum.repos.d/grafana.repo << 'EOF'
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF
sudo dnf install -y grafana

Install LDAP dependencies

Install the required LDAP client libraries that Grafana uses to communicate with Active Directory.

sudo apt install -y ldap-utils
sudo dnf install -y openldap-clients

Test LDAP connectivity

Verify you can connect to your Active Directory server before configuring Grafana.

ldapsearch -x -H ldap://ad.example.com:389 -D "CN=grafana-ldap,CN=Users,DC=example,DC=com" -W -b "DC=example,DC=com" "(sAMAccountName=testuser)"
Note: Replace ad.example.com with your Active Directory server and adjust the Distinguished Names to match your domain structure. You'll be prompted for the bind user password.

Create LDAP configuration

Create the LDAP configuration file that defines how Grafana connects to Active Directory and maps groups to roles.

# LDAP configuration for Active Directory integration
[[servers]]
host = "ad.example.com"
port = 389
use_ssl = false
start_tls = true
skip_verify_ssl = false
ssl_skip_verify = false

Bind credentials for service account

bind_dn = "CN=grafana-ldap,CN=Users,DC=example,DC=com" bind_password = "SecurePassword123!"

User search configuration

search_filter = "(sAMAccountName=%s)" search_base_dns = ["DC=example,DC=com"]

User attribute mapping

[servers.attributes] name = "givenName" surname = "sn" username = "sAMAccountName" member_of = "memberOf" email = "mail"

Group to role mapping

[[servers.group_mappings]] group_dn = "CN=Grafana Admins,OU=Groups,DC=example,DC=com" org_role = "Admin" grafana_admin = true [[servers.group_mappings]] group_dn = "CN=Grafana Editors,OU=Groups,DC=example,DC=com" org_role = "Editor" [[servers.group_mappings]] group_dn = "CN=Grafana Viewers,OU=Groups,DC=example,DC=com" org_role = "Viewer"

Configure Grafana main settings

Enable LDAP authentication in Grafana's main configuration and set security options.

sudo cp /etc/grafana/grafana.ini /etc/grafana/grafana.ini.backup
[auth.ldap]
enabled = true
config_file = /etc/grafana/ldap.toml
allow_sign_up = true
sync_cron = "0 0 1   *"
active_sync_enabled = true

[security]
admin_user = admin
admin_password = StrongAdminPassword123!
secret_key = SecureSecretKey123456789012345678901234567890
disable_gravatar = true
cookie_secure = true
cookie_samesite = strict
strict_transport_security = true

[server]
protocol = https
cert_file = /etc/ssl/certs/grafana.crt
cert_key = /etc/ssl/private/grafana.key
http_port = 3000
enforce_domain = true

[users]
allow_sign_up = false
allow_org_create = false
auto_assign_org = true
auto_assign_org_id = 1
auto_assign_org_role = Viewer
default_theme = dark

[auth]
disable_login_form = false
disable_signout_menu = false
oauth_auto_login = false

[log]
mode = file
level = info
format = json

Set proper file permissions

Configure secure permissions for Grafana configuration files to protect sensitive LDAP credentials.

sudo chown grafana:grafana /etc/grafana/ldap.toml
sudo chmod 640 /etc/grafana/ldap.toml
sudo chown grafana:grafana /etc/grafana/grafana.ini
sudo chmod 640 /etc/grafana/grafana.ini
Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions like 640 for config files with secrets.

Create SSL certificates

Generate SSL certificates for secure HTTPS communication. For production, use certificates from a trusted CA.

sudo mkdir -p /etc/ssl/private
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/ssl/private/grafana.key \
  -out /etc/ssl/certs/grafana.crt \
  -subj "/C=US/ST=State/L=City/O=Organization/CN=grafana.example.com"
sudo chown grafana:grafana /etc/ssl/private/grafana.key
sudo chown grafana:grafana /etc/ssl/certs/grafana.crt
sudo chmod 600 /etc/ssl/private/grafana.key
sudo chmod 644 /etc/ssl/certs/grafana.crt

Start and enable Grafana

Enable Grafana to start automatically on boot and start the service immediately.

sudo systemctl enable --now grafana-server
sudo systemctl status grafana-server

Configure firewall rules

Open the necessary ports for Grafana HTTPS access while maintaining security.

sudo ufw allow 3000/tcp comment 'Grafana HTTPS'
sudo ufw reload
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload

Configure role-based access control

Create Active Directory groups

Create security groups in Active Directory that correspond to Grafana roles. These groups control user permissions.

New-ADGroup -Name "Grafana Admins" -SamAccountName "GrafanaAdmins" -GroupCategory Security -GroupScope Global -DisplayName "Grafana Administrators" -Path "OU=Groups,DC=example,DC=com"
New-ADGroup -Name "Grafana Editors" -SamAccountName "GrafanaEditors" -GroupCategory Security -GroupScope Global -DisplayName "Grafana Editors" -Path "OU=Groups,DC=example,DC=com"
New-ADGroup -Name "Grafana Viewers" -SamAccountName "GrafanaViewers" -GroupCategory Security -GroupScope Global -DisplayName "Grafana Viewers" -Path "OU=Groups,DC=example,DC=com"

Add users to groups

Assign users to the appropriate Grafana groups based on their required access level.

Add-ADGroupMember -Identity "Grafana Admins" -Members "john.doe"
Add-ADGroupMember -Identity "Grafana Editors" -Members "jane.smith","bob.wilson"
Add-ADGroupMember -Identity "Grafana Viewers" -Members "alice.brown","charlie.davis"

Configure organization-level permissions

Set up additional RBAC configurations for multiple organizations if needed.

# Additional organization mappings
[[servers.group_mappings]]
group_dn = "CN=DevOps Team,OU=Groups,DC=example,DC=com"
org_role = "Editor"
org_id = 1

[[servers.group_mappings]]
group_dn = "CN=Security Team,OU=Groups,DC=example,DC=com"
org_role = "Admin"
org_id = 1

[[servers.group_mappings]]
group_dn = "CN=Business Users,OU=Groups,DC=example,DC=com"
org_role = "Viewer"
org_id = 2

Test LDAP authentication

Use Grafana's LDAP debug tool to test the configuration before users attempt to log in.

sudo grafana cli admin ldap-test --username testuser --password TestPassword123!
sudo grafana cli admin ldap-sync --username testuser

Verify your setup

sudo systemctl status grafana-server
curl -k https://localhost:3000/api/health
sudo journalctl -u grafana-server -f

Access Grafana at https://your-server:3000 and test login with an Active Directory user account. Check that users are assigned the correct roles based on their group membership.

You can also monitor LDAP authentication in real-time by watching the logs while users log in. This helps verify group mappings are working correctly.

Common issues

SymptomCauseFix
LDAP bind failsIncorrect bind DN or passwordTest with ldapsearch command and verify service account credentials
Users can't authenticateWrong search base or filterCheck search_base_dns matches your domain structure
Wrong permissions assignedGroup DN mismatchUse ldapsearch to find exact group DN and update ldap.toml
SSL/TLS connection failsCertificate issuesSet skip_verify_ssl = true for testing, fix certificates for production
Users not syncingSync schedule not runningCheck sync_cron setting and manually sync with grafana cli admin ldap-sync
Permission denied errorsWrong file ownershipEnsure grafana user owns config files: chown grafana:grafana /etc/grafana/ldap.toml

Next steps

Running this in production?

Want this handled for you? Setting this up once is straightforward. Keeping it patched, monitored, backed up and performant across environments is the harder part. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle infrastructure security hardening for businesses that depend on uptime. From initial setup to ongoing operations.