How to Secure Elasticsearch Cluster

How to Secure Elasticsearch Cluster Elasticsearch is a powerful, distributed search and analytics engine used by organizations worldwide to index, search, and analyze massive volumes of data in real time. From e-commerce product catalogs to log aggregation systems, Elasticsearch powers mission-critical applications that often handle sensitive information—user behavior, financial records, healthcar

Nov 6, 2025 - 10:40
Nov 6, 2025 - 10:40
 1

How to Secure Elasticsearch Cluster

Elasticsearch is a powerful, distributed search and analytics engine used by organizations worldwide to index, search, and analyze massive volumes of data in real time. From e-commerce product catalogs to log aggregation systems, Elasticsearch powers mission-critical applications that often handle sensitive informationuser behavior, financial records, healthcare data, and more. However, its default configuration prioritizes ease of use over security, leaving clusters exposed to unauthorized access, data breaches, ransomware attacks, and denial-of-service threats. Securing an Elasticsearch cluster is not optional; it is a fundamental requirement for any production deployment. This comprehensive guide walks you through the essential steps, best practices, tools, and real-world examples to harden your Elasticsearch environment against modern cyber threats.

Step-by-Step Guide

1. Enable Transport Layer Security (TLS/SSL)

By default, Elasticsearch communicates over unencrypted HTTP ports (9200 for REST, 9300 for node-to-node communication). This exposes all dataqueries, responses, authentication credentialsto network sniffing and man-in-the-middle attacks. The first step in securing your cluster is to enforce TLS/SSL encryption across all communication channels.

Generate or obtain certificates for your cluster. You can use a Certificate Authority (CA) like Lets Encrypt, or create a private CA using OpenSSL. For internal clusters, a self-signed CA is acceptable as long as its trusted across all nodes.

Place your certificates in the config/certs directory on each node. Configure the following settings in elasticsearch.yml:

xpack.security.transport.ssl.enabled: true

xpack.security.transport.ssl.verification_mode: certificate

xpack.security.transport.ssl.keystore.path: certs/transport-keystore.p12

xpack.security.transport.ssl.truststore.path: certs/transport-truststore.p12

xpack.security.http.ssl.enabled: true

xpack.security.http.ssl.keystore.path: certs/http-keystore.p12

xpack.security.http.ssl.truststore.path: certs/http-truststore.p12

Restart each node after applying these settings. Verify TLS is active by visiting https://your-node:9200 in a browser or using curl -k https://localhost:9200. You should receive a valid JSON response without SSL warnings.

2. Enable X-Pack Security (Elasticsearch Security Features)

Elasticsearchs built-in security features, part of the X-Pack suite, provide authentication, authorization, role-based access control (RBAC), and audit logging. These are disabled by default in open-source versions prior to 8.0, but are now included in all distributions under the basic license.

To enable security, add this line to elasticsearch.yml on every node:

xpack.security.enabled: true

After restarting the cluster, run the following command to set up built-in users and generate initial passwords:

bin/elasticsearch-setup-passwords auto

This generates random passwords for built-in users such as elastic, kibana, logstash_system, and others. Save these passwords securelythey are required for future administrative tasks.

Once enabled, all API requests must include authentication credentials. Requests without a valid username/password or API key will be rejected with a 401 Unauthorized response.

3. Configure Role-Based Access Control (RBAC)

Never grant the elastic superuser role to applications or users. Instead, define granular roles with minimal permissions using the Elasticsearch Security API or Kibanas Security UI.

For example, create a role called logs_writer that allows write access only to log indices:

POST /_security/role/logs_writer

{

"indices": [

{

"names": [ "logs-*" ],

"privileges": [ "write", "create_index" ]

}

],

"run_as": []

}

Then assign this role to a user:

PUT /_security/user/logstash_user

{

"password": "strong_password_123",

"roles": [ "logs_writer" ],

"full_name": "Logstash Service Account"

}

Similarly, create read-only roles for analysts, monitoring roles for observability tools, and application-specific roles for your microservices. Always follow the principle of least privilege: grant only the permissions necessary to perform a task.

4. Implement API Key Authentication for Applications

Instead of embedding usernames and passwords in application configuration files, use API keys. API keys are short-lived, revocable, and scoped to specific roles and indices. They eliminate the risk of credential leakage through source code repositories or misconfigured environments.

Generate an API key for a service account:

POST /_security/api_key

{

"name": "my-app-api-key",

"role_descriptors": {

"app_role": {

"indices": [

{

"names": [ "app-data-*" ],

"privileges": [ "read", "search" ]

}

]

}

}

}

Store the generated API key (ID and API key value) in your applications secure secrets manager (e.g., HashiCorp Vault, AWS Secrets Manager). Use it in HTTP headers:

Authorization: ApiKey

API keys can be listed, rotated, or revoked at any time without affecting other services:

GET /_security/api_key

DELETE /_security/api_key/

5. Restrict Network Exposure with Firewall Rules

Even with authentication enabled, exposing Elasticsearch directly to the public internet is a severe security risk. Use network-level controls to limit access.

Configure your firewall (iptables, firewalld, AWS Security Groups, Azure NSGs) to allow traffic only from trusted sources:

  • Allow inbound traffic on port 9200 (HTTP) only from application servers or Kibana instances.
  • Allow inbound traffic on port 9300 (transport) only between Elasticsearch nodes in the same private network.
  • Block all other inbound traffic.

In cloud environments, never assign public IPs to Elasticsearch nodes. Use private subnets and access via a bastion host, API gateway, or reverse proxy with authentication.

Additionally, bind Elasticsearch to internal interfaces only:

network.host: 192.168.0.10

http.port: 9200

transport.port: 9300

Never use 0.0.0.0 or _local_ unless you are certain of your network isolation.

6. Secure Kibana Access

Kibana serves as the primary interface for data visualization and administration. If compromised, it can become a gateway to your entire cluster. Secure Kibana by enabling TLS and integrating it with Elasticsearchs authentication system.

In kibana.yml:

server.ssl.enabled: true

server.ssl.certificate: /path/to/cert.pem

server.ssl.key: /path/to/key.pem

elasticsearch.hosts: ["https://elasticsearch-node:9200"]

elasticsearch.username: "kibana_system"

elasticsearch.password: "your_kibana_password"

elasticsearch.ssl.certificateAuthorities: [ "/path/to/ca.crt" ]

Ensure Kibana communicates with Elasticsearch over HTTPS using the same CA that signed the Elasticsearch certificates.

Enable Kibanas built-in user management and role mapping. Assign roles like kibana_admin or kibana_user based on user responsibilities. Avoid giving users direct access to Elasticsearch APIs via Dev Tools unless absolutely necessary.

7. Enable Audit Logging

Audit logging records all security-related events: successful and failed logins, permission changes, API key creation, index deletions, and more. This is critical for forensic analysis and compliance.

Enable audit logging in elasticsearch.yml:

xpack.security.audit.enabled: true

xpack.security.audit.logfile.events.include: [ "access_denied", "authentication_failed", "privilege_granted", "privilege_revoked", "api_key_created", "api_key_deleted" ]

xpack.security.audit.logfile.events.exclude: []

xpack.security.audit.logfile.path: /var/log/elasticsearch/audit.log

Set appropriate file permissions so only the Elasticsearch user can read or write the log file:

chown elasticsearch:elasticsearch /var/log/elasticsearch/audit.log

chmod 600 /var/log/elasticsearch/audit.log

Forward audit logs to a centralized logging system (e.g., Logstash + Elasticsearch, Splunk, Datadog) for long-term retention and correlation with other system events.

8. Disable Dangerous Features

Elasticsearch includes several features that are useful in development but pose serious risks in production:

  • Scripting: Groovy scripting (deprecated) and Painless scripting can be exploited for remote code execution. Disable inline scripting unless required:

script.painless.inline.max_size: 10000

script.painless.inline.max_depth: 10

script.painless.inline.max_statements: 100

script.painless.inline.enabled: false

script.painless.regex.enabled: false

  • Index templates with dynamic mappings: Allow users to create indices with arbitrary field types? This can lead to mapping explosions and performance degradation. Use strict mappings and index templates with predefined schemas.
  • HTTP PUT with auto-create index: Disable automatic index creation to prevent unauthorized users from creating malicious indices:

action.auto_create_index: .security,-*,+logs-*,-audit-*

This allows only the .security index and indices starting with logs- to be auto-created. All others must be explicitly created by admins.

9. Implement Index-Level Security and Data Masking

For compliance with regulations like GDPR or HIPAA, you may need to restrict access to sensitive fields within documents. Use Elasticsearchs field-level security to mask or hide specific fields based on user roles.

Define a role that excludes sensitive fields:

POST /_security/role/analyst

{

"indices": [

{

"names": [ "users-*" ],

"privileges": [ "read", "search" ],

"field_security": {

"grant": [ "name", "email", "department" ],

"except": [ "ssn", "phone", "address" ]

}

}

]

}

Users assigned this role will see all fields except SSN, phone, and address, which will appear as null or omitted in search results.

10. Regularly Rotate Credentials and Certificates

Static credentials and long-lived certificates are a major attack vector. Establish a policy to rotate:

  • API keys every 3090 days
  • User passwords every 6090 days
  • TLS certificates before expiration (typically 90 days for Lets Encrypt)

Use automation tools like Ansible, Terraform, or custom scripts to rotate certificates and update configurations across nodes without downtime. Schedule certificate renewal using cron jobs or Kubernetes operators.

Monitor certificate expiration dates using tools like openssl x509 -in cert.pem -noout -enddate or integrate with monitoring systems like Prometheus and Grafana.

Best Practices

Adopt the Principle of Least Privilege

Every user, service, and application should operate with the minimum permissions required. Avoid assigning superuser roles unless absolutely necessary. Use role templates and automation to enforce consistent permission assignments across teams and environments.

Use a Zero Trust Architecture

Assume that threats exist both inside and outside your network. Authenticate and authorize every request, regardless of origin. Use mutual TLS (mTLS) between nodes and services to verify identity on both ends. Implement service-to-service authentication using certificates or short-lived tokens.

Keep Elasticsearch Updated

Elasticsearch releases security patches regularly. Subscribe to the official Elastic Security Advisories and apply updates within 30 days of release. Never run outdated versionsolder releases may contain unpatched vulnerabilities exploitable by automated scanners.

Separate Roles and Environments

Use separate Elasticsearch clusters for development, staging, and production. Never share a cluster across environments. Isolate production data with strict network policies and audit trails. Use different user directories or LDAP groups for each environment.

Encrypt Data at Rest

While TLS secures data in transit, encrypt data stored on disk. Use filesystem-level encryption (e.g., LUKS on Linux, BitLocker on Windows) or Elasticsearchs native encryption features (available in Platinum+ licenses). Ensure encryption keys are stored separately from the data and rotated regularly.

Monitor and Alert on Anomalous Activity

Use Elasticsearchs built-in monitoring or integrate with external tools like Elastic SIEM, Splunk, or Wazuh. Set alerts for:

  • Multiple failed login attempts from a single IP
  • Deletion of indices or snapshots
  • Creation of new API keys by non-admin users
  • Unusual query patterns (e.g., full index scans from a service account)

Automate responses where possiblefor example, block an IP after 5 failed logins using a firewall rule triggered by a log parser.

Backup and Test Recovery

Regularly snapshot your indices to a secure, offline location (e.g., S3, NFS, or encrypted tape). Test recovery procedures quarterly. A secure cluster is useless if you cannot restore data after a ransomware attack or hardware failure.

Disable Unused Features

Turn off unused modules to reduce the attack surface:

  • Disable Marvel (deprecated)
  • Disable Watcher if not used
  • Disable SQL if not needed
  • Disable CCR (Cross-Cluster Replication) unless actively replicating data

Remove unnecessary plugins. Only install plugins from trusted sources and verify their integrity using checksums.

Conduct Regular Security Audits

Perform quarterly security reviews using tools like elasticsearch-security-check or custom scripts that validate:

  • All nodes have TLS enabled
  • Superuser credentials are not used in applications
  • API keys are rotated
  • Firewall rules are up to date
  • Users have appropriate roles

Document findings and remediation steps. Assign ownership for each action item.

Tools and Resources

Elasticsearch Security Tools

  • Elastic Security (SIEM): Built-in security analytics platform for threat detection, endpoint monitoring, and compliance reporting.
  • Elasticsearch Security Check: Open-source CLI tool that scans a cluster for misconfigurations and security gaps.
  • elasticsearch-security-plugin: Community-maintained plugin for enhanced authentication via LDAP, SAML, and OAuth2.

Third-Party Tools

  • HashiCorp Vault: Securely store and manage API keys, passwords, and certificates.
  • Ansible: Automate configuration deployment across clusters.
  • Terraform: Provision secure Elasticsearch infrastructure in AWS, Azure, or GCP.
  • Fail2ban: Block brute-force attacks by monitoring authentication logs and updating firewall rules.
  • Prometheus + Grafana: Monitor cluster health, authentication rates, and certificate expiration.
  • OpenSCAP: Scan systems for compliance with CIS benchmarks for Elasticsearch.

Official Documentation and Guides

Training and Certifications

  • Elastic Certified Engineer: Covers deployment, scaling, and securing Elasticsearch clusters.
  • Elastic Security Analyst: Focuses on threat detection and incident response using Elastic SIEM.
  • Certified Information Systems Security Professional (CISSP): General security knowledge applicable to Elasticsearch environments.

Real Examples

Example 1: Healthcare Provider Secures Patient Records

A U.S.-based healthcare provider uses Elasticsearch to store and analyze electronic health records (EHR). To comply with HIPAA, they:

  • Enabled TLS between all nodes and clients
  • Created roles for doctors, nurses, and administrators with field-level security to mask patient identifiers
  • Disabled all scripting and auto-index creation
  • Enabled audit logging and forwarded logs to a SIEM system
  • Used API keys for their EHR application, rotated every 60 days
  • Restricted network access to only their internal VPC and a single Kibana instance

After implementation, they passed a third-party HIPAA audit with zero findings.

Example 2: E-Commerce Platform Prevents Data Breach

An online retailer experienced a credential leak from a developers GitHub repository. The exposed password granted full access to their Elasticsearch cluster. Within hours, attackers attempted to delete indices and exfiltrate customer data.

After the incident, they:

  • Migrated all applications to use API keys
  • Disabled password-based authentication for service accounts
  • Implemented mandatory MFA for all human users via SAML integration
  • Enabled audit logging and set up real-time alerts for index deletion
  • Conducted a full security review and found 3 other misconfigured clusters

They avoided data loss and strengthened their security posture significantly.

Example 3: Financial Institution Implements Zero Trust

A global bank runs Elasticsearch clusters across multiple data centers. They implemented a zero-trust model:

  • All node-to-node communication uses mTLS with certificate-based authentication
  • Every API request requires a JWT token issued by their internal identity provider
  • Access to Kibana is gated through a reverse proxy with SSO and IP whitelisting
  • Indices are encrypted at rest using LUKS
  • Automated scans run daily using Ansible to verify compliance

They have not experienced a single security incident in over two years.

FAQs

Can I run Elasticsearch without security enabled?

Technically, yesbut it is strongly discouraged in any environment connected to a network. Unsecured Elasticsearch clusters are frequently targeted by automated bots that exploit them for cryptocurrency mining, data exfiltration, or ransomware. Many public clusters have been compromised within minutes of being exposed.

What happens if I forget my elastic password?

If you lose the superuser password, you can reset it by temporarily disabling security, restarting Elasticsearch in safe mode, and then re-enabling it. However, this requires access to the server and may cause downtime. Always store passwords securely using a secrets manager.

Is Elasticsearch secure by default?

No. Default installations are designed for ease of use in development environments. All security features must be explicitly enabled and configured. Never assume Elasticsearch is secure out of the box.

How do I secure Elasticsearch in Docker or Kubernetes?

Use Helm charts or operators that support security configuration. Mount TLS certificates as secrets. Set environment variables for authentication. Use network policies to restrict pod-to-pod communication. Enable RBAC in Kubernetes and map roles to Elasticsearch roles.

Can I use LDAP or Active Directory with Elasticsearch?

Yes. Elasticsearch supports LDAP, Active Directory, and SAML authentication through X-Pack. Configure the realm in elasticsearch.yml and map LDAP groups to Elasticsearch roles for centralized user management.

How often should I rotate API keys?

Every 30 to 90 days is recommended. Shorter rotations (30 days) are ideal for high-risk environments. Use automation to rotate keys without disrupting services.

Does Elasticsearch support multi-factor authentication (MFA)?

Yes, via SAML or OpenID Connect integrations with identity providers like Okta, Azure AD, or Google Workspace. MFA is required for human users accessing Kibana or administrative interfaces.

What are the most common Elasticsearch security mistakes?

Common mistakes include:

  • Leaving the cluster exposed to the public internet
  • Using the elastic user for applications
  • Not enabling TLS
  • Ignoring audit logs
  • Running outdated versions
  • Allowing dynamic index creation

Can I use a reverse proxy to secure Elasticsearch?

Yes. A reverse proxy like NGINX or Traefik can add an additional layer of authentication, rate limiting, and TLS termination. However, it should complementnot replaceElasticsearchs built-in security. Always ensure the proxy forwards client IP addresses and does not strip authentication headers.

What should I do if my cluster is compromised?

Immediately isolate the cluster from the network. Disable all access. Review audit logs to determine the scope of the breach. Reset all passwords and API keys. Rebuild indices from clean backups. Patch vulnerabilities. Conduct a post-mortem and update security policies.

Conclusion

Securing an Elasticsearch cluster is not a one-time taskit is an ongoing discipline that requires vigilance, automation, and adherence to security best practices. From enabling TLS and RBAC to enforcing API key rotation and audit logging, each step contributes to a resilient, trustworthy data infrastructure. The consequences of neglecting security can be catastrophic: data breaches, regulatory fines, reputational damage, and operational downtime.

By following the steps outlined in this guide, you transform Elasticsearch from a vulnerable, default-configured service into a hardened, enterprise-grade system capable of protecting your most sensitive data. Remember: security is not a featureits a foundation. Build it right from the start, and maintain it with discipline.

Start by auditing your current cluster configuration. Enable security today. Rotate credentials this week. Monitor your logs tomorrow. These small, consistent actions compound into a robust security posture that withstands evolving threats.