Setup Elasticsearch 8 authentication with LDAP and Active Directory integration

Advanced 45 min Apr 04, 2026 302 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Configure Elasticsearch 8 with X-Pack security to authenticate users against LDAP and Active Directory servers. This tutorial covers LDAP realm configuration, role-based access control, and troubleshooting authentication issues.

Prerequisites

  • Root or sudo access
  • Active Directory or LDAP server access
  • Java 11 or higher
  • Minimum 4GB RAM
  • Network connectivity to LDAP server

What this solves

Elasticsearch 8's X-Pack security module provides built-in LDAP authentication that integrates with Active Directory and other LDAP servers. This eliminates the need to manage separate user accounts in Elasticsearch while providing centralized authentication and role-based access control. You'll configure secure authentication for your existing corporate directory infrastructure.

Step-by-step configuration

Update system packages and install Java

Elasticsearch requires Java 11 or higher. Update your system and install the required dependencies.

sudo apt update && sudo apt upgrade -y
sudo apt install -y openjdk-11-jdk curl wget gnupg
sudo dnf update -y
sudo dnf install -y java-11-openjdk-devel curl wget

Add Elasticsearch repository and install

Add the official Elasticsearch repository to install the latest version 8 with X-Pack security enabled by default.

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
sudo apt update
sudo apt install -y elasticsearch
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat << 'EOF' | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
EOF
sudo dnf install --enablerepo=elasticsearch -y elasticsearch

Configure basic Elasticsearch settings

Set up basic cluster configuration and memory settings for optimal performance. This configuration works for both single-node and multi-node setups.

cluster.name: production-cluster
node.name: node-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
http.port: 9200
discovery.type: single-node

Security settings

xpack.security.enabled: true xpack.security.enrollment.enabled: false xpack.security.http.ssl.enabled: false xpack.security.transport.ssl.enabled: false

Set JVM heap size

Configure JVM memory based on your system resources. Set heap size to half of available RAM, maximum 32GB.

-Xms2g
-Xmx2g

Start Elasticsearch and set built-in user passwords

Enable and start Elasticsearch, then configure passwords for built-in users including the elastic superuser.

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
sudo systemctl status elasticsearch

Wait for Elasticsearch to start, then set passwords for built-in users:

sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
Note: Save the passwords securely. You'll need the elastic user password for administrative tasks.

Configure LDAP authentication realm

Add LDAP realm configuration to authenticate against your Active Directory or LDAP server. This configuration supports both Active Directory and standard LDAP servers.

# LDAP Authentication Configuration
xpack.security.authc.realms.ldap.ldap1:
  order: 0
  url: "ldaps://ldap.example.com:636"
  bind_dn: "cn=elasticsearch,ou=service-accounts,dc=example,dc=com"
  bind_password: "ServiceAccountPassword123!"
  user_search:
    base_dn: "ou=users,dc=example,dc=com"
    filter: "(cn={0})"
    attribute: cn
  group_search:
    base_dn: "ou=groups,dc=example,dc=com"
    filter: "(member={0})"
  unmapped_groups_as_roles: false
  ssl.verification_mode: certificate
  ssl.certificate_authorities: ["/etc/elasticsearch/certs/ca.crt"]
  cache.ttl: 20m
  cache.max_users: 100000

Active Directory specific configuration

xpack.security.authc.realms.ldap.ad1: order: 1 url: "ldaps://ad.example.com:636" bind_dn: "elasticsearch@example.com" bind_password: "ADServicePassword123!" user_search: base_dn: "CN=Users,DC=example,DC=com" filter: "(&(objectClass=user)(sAMAccountName={0}))" attribute: sAMAccountName group_search: base_dn: "CN=Users,DC=example,DC=com" filter: "(&(objectClass=group)(member={0}))" unmapped_groups_as_roles: false ssl.verification_mode: certificate ssl.certificate_authorities: ["/etc/elasticsearch/certs/ad-ca.crt"] cache.ttl: 20m cache.max_users: 100000

Download and configure SSL certificates

Download SSL certificates from your LDAP servers to enable secure connections. Create the certificate directory and set proper permissions.

sudo mkdir -p /etc/elasticsearch/certs
sudo chown elasticsearch:elasticsearch /etc/elasticsearch/certs
sudo chmod 750 /etc/elasticsearch/certs

Download certificates from your LDAP servers:

# For standard LDAP server
echo -n | openssl s_client -connect ldap.example.com:636 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee /etc/elasticsearch/certs/ca.crt

For Active Directory server

echo -n | openssl s_client -connect ad.example.com:636 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee /etc/elasticsearch/certs/ad-ca.crt

Set proper ownership and permissions

sudo chown elasticsearch:elasticsearch /etc/elasticsearch/certs/*.crt sudo chmod 644 /etc/elasticsearch/certs/*.crt
Never use chmod 777. It gives every user on the system full access to your certificates. The elasticsearch user needs read access (644), and the certs directory should be accessible only to elasticsearch (750).

Create role mapping configuration

Map LDAP groups to Elasticsearch roles to implement role-based access control (RBAC). This defines what permissions users from each LDAP group will have.

# Map LDAP groups to Elasticsearch roles
superuser:
  - "CN=Elasticsearch-Admins,OU=Groups,DC=example,DC=com"
  - "cn=elasticsearch-admins,ou=groups,dc=example,dc=com"

kibana_admin:
  - "CN=Kibana-Admins,OU=Groups,DC=example,DC=com"
  - "cn=kibana-admins,ou=groups,dc=example,dc=com"

kibana_user:
  - "CN=Kibana-Users,OU=Groups,DC=example,DC=com"
  - "cn=kibana-users,ou=groups,dc=example,dc=com"

logstash_writer:
  - "CN=Logstash-Writers,OU=Groups,DC=example,DC=com"
  - "cn=logstash-writers,ou=groups,dc=example,dc=com"

reading_user:
  - "CN=Elasticsearch-Readers,OU=Groups,DC=example,DC=com"
  - "cn=elasticsearch-readers,ou=groups,dc=example,dc=com"

Custom roles for specific indices

log_reader: - "CN=Log-Analysts,OU=Groups,DC=example,DC=com" - "cn=log-analysts,ou=groups,dc=example,dc=com" metrics_reader: - "CN=Metrics-Team,OU=Groups,DC=example,DC=com" - "cn=metrics-team,ou=groups,dc=example,dc=com"

Define custom roles with specific permissions

Create custom roles that define specific permissions for different user groups. This provides fine-grained access control over indices and operations.

curl -X POST "localhost:9200/_security/role/log_reader" -H 'Content-Type: application/json' -u elastic -d'
{
  "cluster": ["monitor"],
  "indices": [
    {
      "names": ["logs-", "filebeat-"],
      "privileges": ["read", "view_index_metadata"]
    }
  ]
}'

curl -X POST "localhost:9200/_security/role/metrics_reader" -H 'Content-Type: application/json' -u elastic -d'
{
  "cluster": ["monitor"],
  "indices": [
    {
      "names": ["metrics-", "metricbeat-"],
      "privileges": ["read", "view_index_metadata"]
    }
  ]
}'

curl -X POST "localhost:9200/_security/role/reading_user" -H 'Content-Type: application/json' -u elastic -d'
{
  "cluster": ["monitor"],
  "indices": [
    {
      "names": ["*"],
      "privileges": ["read", "view_index_metadata"]
    }
  ]
}'

Restart Elasticsearch and test configuration

Restart Elasticsearch to apply the LDAP configuration and verify that the service starts correctly with the new authentication settings.

sudo systemctl restart elasticsearch
sudo systemctl status elasticsearch

Check Elasticsearch logs for any configuration errors:

sudo tail -f /var/log/elasticsearch/production-cluster.log

Test LDAP authentication

Test authentication using LDAP credentials to verify the configuration is working correctly.

# Test authentication with LDAP user
curl -X GET "localhost:9200/_security/_authenticate" -u ldapuser:ldappassword

Test role mapping

curl -X GET "localhost:9200/_security/user/_has_privileges" -H 'Content-Type: application/json' -u ldapuser:ldappassword -d' { "cluster": ["monitor"], "index": [ { "names": ["logs-*"], "privileges": ["read"] } ] }'

List current user privileges

curl -X GET "localhost:9200/_security/_authenticate" -u ldapuser:ldappassword

Verify your setup

Confirm that LDAP authentication is working correctly and users can access Elasticsearch with their directory credentials.

# Check Elasticsearch cluster health
curl -X GET "localhost:9200/_cluster/health" -u elastic

Verify LDAP realm is active

curl -X GET "localhost:9200/_security/_authenticate" -u elastic

Test LDAP user authentication

curl -X GET "localhost:9200/_security/_authenticate" -u your-ldap-username:your-ldap-password

Check role mappings

curl -X GET "localhost:9200/_security/role_mapping" -u elastic

Verify user can access permitted indices

curl -X GET "localhost:9200/logs-*/_search?size=1" -u ldap-user:ldap-password

Common issues

Symptom Cause Fix
Authentication fails with LDAP users Wrong bind DN or search base Use ldapsearch to test: ldapsearch -H ldaps://ldap.example.com:636 -D "bind_dn" -W -b "base_dn" "(cn=testuser)"
SSL/TLS connection errors Missing or invalid SSL certificates Verify certificate: openssl x509 -in /etc/elasticsearch/certs/ca.crt -text -noout
Users have no roles assigned Group mappings don't match LDAP groups Check user's groups: curl -X GET "localhost:9200/_security/_authenticate" -u ldap-user
Elasticsearch won't start after config changes YAML syntax errors in configuration Check logs: sudo journalctl -u elasticsearch -n 50
LDAP authentication very slow DNS resolution issues or network latency Add IP addresses to /etc/hosts or increase cache TTL in config
Permission denied accessing certificate files Wrong file ownership or permissions Fix ownership: sudo chown elasticsearch:elasticsearch /etc/elasticsearch/certs/*

Next steps

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.