How to Secure Elasticsearch Cluster

How to Secure Elasticsearch Cluster Elasticsearch is a powerful, distributed search and analytics engine widely used across industries for real-time data indexing, log analysis, business intelligence, and application search functionality. However, its popularity also makes it a prime target for cyberattacks. In recent years, thousands of unsecured Elasticsearch clusters have been exposed to the pu

Nov 10, 2025 - 12:08
Nov 10, 2025 - 12:08
 1

How to Secure Elasticsearch Cluster

Elasticsearch is a powerful, distributed search and analytics engine widely used across industries for real-time data indexing, log analysis, business intelligence, and application search functionality. However, its popularity also makes it a prime target for cyberattacks. In recent years, thousands of unsecured Elasticsearch clusters have been exposed to the public internet, leading to data breaches, ransomware attacks, and service disruptions. Securing your Elasticsearch cluster is not optionalit is a critical requirement for maintaining data integrity, regulatory compliance, and operational continuity.

This comprehensive guide walks you through the complete process of securing an Elasticsearch clusterfrom foundational configurations to advanced authentication, encryption, and monitoring strategies. Whether youre managing a small development cluster or a large-scale production deployment, this tutorial provides actionable, step-by-step instructions grounded in industry best practices and real-world scenarios.

Step-by-Step Guide

1. Understand Your Deployment Architecture

Before implementing security controls, you must understand your Elasticsearch deployment topology. Clusters typically consist of three types of nodes:

  • Master-eligible nodes: Manage cluster-wide operations like index creation and node discovery.
  • Data nodes: Store and process data, handling search and indexing requests.
  • Ingest nodes: Preprocess data before indexing (e.g., parsing, enriching).

Additionally, you may have coordinating nodes (client nodes) that handle client requests and route them appropriately. Each node type should be configured with appropriate security policies. Isolate master nodes from public access, restrict data nodes to internal networks, and use firewalls to limit inbound traffic.

2. Disable Public Exposure

One of the most common security failures is exposing Elasticsearch to the public internet. By default, Elasticsearch binds to 0.0.0.0, making it accessible from any network. This is extremely dangerous.

To fix this, edit the elasticsearch.yml configuration file on each node:

network.host: 192.168.0.10

http.port: 9200

Replace 192.168.0.10 with a private IP address within your internal network. Never use 0.0.0.0 in production. If you need external access, use a reverse proxy (e.g., Nginx or HAProxy) with strict access controls.

Verify the change by running:

curl http://192.168.0.10:9200

If the response returns cluster information, your configuration is correct. If you can reach it from an external IP, your firewall or network settings are misconfigured.

3. Enable Transport Layer Security (TLS/SSL)

Encrypting communication between nodes and clients prevents eavesdropping, man-in-the-middle attacks, and data tampering. Elasticsearch supports TLS for both HTTP and transport layers.

Generate certificates using the built-in elasticsearch-certutil tool:

bin/elasticsearch-certutil cert --out certs.zip

Extract the archive and copy the certificates to each nodes config directory:

unzip certs.zip

cp certs/ca/ca.crt /etc/elasticsearch/certs/

cp certs/instance/instance.crt /etc/elasticsearch/certs/

cp certs/instance/instance.key /etc/elasticsearch/certs/

Update elasticsearch.yml to enable TLS:

xpack.security.enabled: true

xpack.security.transport.ssl.enabled: true

xpack.security.transport.ssl.verification_mode: certificate

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

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

xpack.security.http.ssl.enabled: true

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

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

Restart Elasticsearch after making these changes. Test TLS connectivity:

curl -k https://192.168.0.10:9200

You should receive a 401 Unauthorized response (expected, since authentication is not yet configured), but no SSL errors.

4. Enable and Configure X-Pack Security

X-Pack Security (now part of the basic license) provides authentication, authorization, role-based access control, and audit logging. It is the cornerstone of Elasticsearch security.

Ensure the following is set in elasticsearch.yml:

xpack.security.enabled: true

Then, generate initial passwords for built-in users:

bin/elasticsearch-setup-passwords auto

This command generates random passwords for users like elastic, kibana, logstash_system, and others. Save these passwords securelypreferably in a password manager or encrypted vault.

After generating passwords, test access:

curl -u elastic:your-generated-password https://192.168.0.10:9200

You should receive a JSON response with cluster information.

5. Implement Role-Based Access Control (RBAC)

Never use the elastic superuser account for applications or daily operations. Instead, create granular roles and assign them to users.

For example, create a role for a data ingestion service:

POST /_security/role/ingest_role

{

"cluster": ["monitor"],

"indices": [

{

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

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

"field_security": {

"grant": ["@timestamp", "message", "source"]

}

}

]

}

Then create a user assigned to this role:

POST /_security/user/logstash_user

{

"password": "strong_password_123!",

"roles": ["ingest_role"],

"full_name": "Logstash Ingest Service"

}

Repeat this process for other services: Kibana, application users, analytics teams. Assign minimal privileges required for each function.

6. Configure API Key Authentication

For automated systems (e.g., CI/CD pipelines, microservices), use API keys instead of username/password credentials. API keys are revocable, time-limited, and do not require password storage.

Generate an API key:

POST /_security/api_key

{

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

"role_descriptors": {

"app_role": {

"cluster": ["monitor"],

"indices": [

{

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

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

}

]

}

}

}

Response includes an id and api_key. Store the API key securely (e.g., in a secrets manager). Use it in requests:

curl -H "Authorization: ApiKey your-api-key-here" https://192.168.0.10:9200/app-*/_search

To revoke a key:

DELETE /_security/api_key?id=your-key-id

7. Secure Kibana Integration

Kibana requires secure access to Elasticsearch. Configure kibana.yml:

elasticsearch.hosts: ["https://192.168.0.10:9200"]

elasticsearch.username: "kibana_system"

elasticsearch.password: "your-kibana-password"

elasticsearch.ssl.certificateAuthorities: ["/etc/kibana/certs/ca.crt"]

server.ssl.enabled: true

server.ssl.certificate: /etc/kibana/certs/kibana.crt

server.ssl.key: /etc/kibana/certs/kibana.key

Ensure Kibana uses HTTPS and validates the Elasticsearch certificate. Disable anonymous access in Kibana:

xpack.security.loginAssistanceMessage: "Contact your administrator for access."

Enable Kibanas built-in user management to assign roles to internal users (e.g., analysts, admins).

8. Implement Network Segmentation and Firewalls

Even with TLS and authentication, network-level protection is essential. Use firewalls (iptables, UFW, or cloud-based security groups) to restrict access:

  • Allow only internal IPs to access port 9200 (HTTP) and 9300 (transport).
  • Block all public access to Elasticsearch ports.
  • Allow only your Kibana server to connect to Elasticsearch.
  • Allow only trusted CI/CD servers to use API keys.

Example iptables rule:

iptables -A INPUT -p tcp --dport 9200 -s 192.168.0.0/24 -j ACCEPT

iptables -A INPUT -p tcp --dport 9200 -j DROP

For cloud deployments (AWS, Azure, GCP), use Security Groups or Network ACLs to restrict ingress. Never rely on IP whitelisting alonecombine it with authentication and encryption.

9. Enable Audit Logging

Audit logs track who accessed what, when, and from where. This is critical for compliance (GDPR, HIPAA, SOC 2) and forensic investigations.

In elasticsearch.yml, enable audit logging:

xpack.security.audit.enabled: true

xpack.security.audit.logfile.events.include: ["access_denied", "access_granted", "authentication_failed", "privilege_granted", "privilege_denied", "login_success", "login_failure"]

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

xpack.security.audit.logfile.format: json

Logs are written to logs/elasticsearch_audit.log. Forward these logs to a centralized SIEM system (e.g., ELK Stack, Splunk, Graylog) for aggregation and alerting.

10. Harden Operating System and Container Security

Elasticsearch should run under a dedicated, non-root user:

useradd elasticsearch

chown -R elasticsearch:elasticsearch /usr/share/elasticsearch

Set restrictive file permissions:

chmod 600 /etc/elasticsearch/certs/*

chmod 644 /etc/elasticsearch/elasticsearch.yml

If running in Docker, avoid running as root:

docker run -u elasticsearch ...

Use minimal base images (e.g., Alpine Linux), scan for vulnerabilities with Trivy or Clair, and disable unnecessary kernel features (e.g., swap memory, which can degrade performance and security).

Best Practices

1. Follow the Principle of Least Privilege

Every user, service, and application should have the minimum permissions required to function. Avoid assigning the superuser role to any non-administrative entity. Regularly review role assignments and revoke unused privileges.

2. Rotate Credentials and Keys Regularly

Set a policy to rotate passwords, API keys, and TLS certificates every 90 days. Automate this process using scripts or CI/CD pipelines. Use tools like HashiCorp Vault or AWS Secrets Manager to manage secrets securely.

3. Keep Elasticsearch Updated

Always run the latest stable version of Elasticsearch. Older versions contain known vulnerabilities (e.g., CVE-2019-7609, CVE-2020-7008). Subscribe to Elastics security advisories and apply patches immediately.

4. Use a Reverse Proxy for External Access

If external access is unavoidable (e.g., for mobile apps), place a reverse proxy (Nginx, Traefik) in front of Elasticsearch. Configure the proxy to handle TLS termination, rate limiting, and IP whitelisting. Never expose Elasticsearch directly to the internet.

5. Disable Unused Features

Disable features you dont use to reduce the attack surface:

  • Disable Groovy scripting (vulnerable to RCE): script.groovy.sandbox.enabled: false
  • Disable Painless scripting if not needed: script.painless.enabled: false
  • Disable the Dev Tools UI in Kibana for non-admin users.

6. Monitor for Anomalies

Set up alerts for suspicious activity:

  • Multiple failed login attempts from a single IP
  • Unusual data volume spikes
  • Access from unexpected geographic locations
  • Unauthorized index creation or deletion

Use Elasticsearchs built-in Machine Learning features or integrate with external monitoring tools like Prometheus + Grafana or Datadog.

7. Backup and Disaster Recovery

Secure backups are part of security. Enable snapshot repositories and store them in encrypted, offsite locations (e.g., S3 with server-side encryption). Test restores regularly.

PUT /_snapshot/my_backup_repo

{

"type": "s3",

"settings": {

"bucket": "my-es-backups",

"region": "us-west-2",

"base_path": "production-cluster"

}

}

8. Conduct Regular Security Audits

Perform quarterly security reviews:

  • Scan for open ports using Nmap or Shodan
  • Review user and role assignments
  • Validate certificate expiration dates
  • Check audit logs for anomalies

Use automated tools like Elastics Security Solution (formerly SIEM) to generate compliance reports.

9. Educate Your Team

Security is not just technicalits cultural. Train developers, DevOps engineers, and analysts on secure Elasticsearch practices:

  • Never hardcode credentials in code or configs
  • Use environment variables or secrets managers
  • Understand the risks of unsecured clusters

10. Implement Zero Trust Architecture

Treat every request as untrusted, even if it originates inside your network. Enforce mutual TLS (mTLS) between nodes, require API key validation for all endpoints, and use service meshes (e.g., Istio) for service-to-service authentication.

Tools and Resources

1. Elasticsearch Security Features

Elastics built-in security suite includes:

  • X-Pack Security: Authentication, RBAC, audit logging
  • SSL/TLS: Transport and HTTP layer encryption
  • API Keys: Temporary, revocable access tokens
  • Role-Based Access Control: Fine-grained permissions
  • Security Solution (SIEM): Threat detection and monitoring

Available in Basic, Standard, and Enterprise licenses. Basic license includes all core security features.

2. Certificate Management Tools

  • elasticsearch-certutil: Built-in tool for generating TLS certificates
  • Lets Encrypt: Free TLS certificates for public-facing proxies
  • Vault by HashiCorp: Centralized secrets and certificate management
  • Cert-Manager (Kubernetes): Automates certificate issuance and renewal

3. Network Security Tools

  • iptables / nftables: Linux firewall rules
  • Cloud Security Groups (AWS/Azure/GCP): Network ACLs for cloud deployments
  • Fail2Ban: Blocks repeated malicious login attempts
  • Wireshark / tcpdump: Network traffic analysis for debugging

4. Monitoring and Alerting

  • Elasticsearch Monitoring: Built-in metrics dashboard
  • Prometheus + Exporters: Custom metrics collection
  • Graylog: Centralized log aggregation
  • Splunk: Enterprise SIEM with Elasticsearch integration

5. Vulnerability Scanners

  • Shodan: Search for exposed Elasticsearch instances
  • Nmap: Scan for open ports and services
  • Trivy: Container image vulnerability scanning
  • OpenVAS: Comprehensive network vulnerability assessment

6. Official Documentation and References

Real Examples

Example 1: Healthcare Data Breach Due to Unsecured Cluster

In 2021, a healthcare provider left an Elasticsearch cluster exposed on port 9200 with no authentication. Attackers accessed 2.7 million patient records, including medical histories and social security numbers. The breach was discovered when a security researcher reported it on Shodan. The organization faced regulatory fines under HIPAA and lost customer trust.

What went wrong? No TLS, no authentication, public exposure.

How it couldve been prevented: Enable X-Pack Security, bind to private IP, use firewall rules, enable audit logs.

Example 2: Ransomware Attack on E-Commerce Platform

An e-commerce company used Elasticsearch to store product catalogs and user preferences. A developer accidentally pushed a Docker container with Elasticsearch bound to 0.0.0.0. Attackers encrypted the data and demanded a ransom in Bitcoin.

What went wrong? Misconfigured container, no network isolation, no backups.

How it couldve been prevented: Use Docker Compose with network restrictions, enable encryption, implement automated snapshots, scan containers before deployment.

Example 3: Secure Financial Services Deployment

A global bank deployed Elasticsearch across 12 data centers with strict security controls:

  • All nodes use mTLS with custom CA-signed certificates
  • Users authenticated via SAML integration with Active Directory
  • API keys generated for microservices with 30-day expiration
  • Network segmentation: Elasticsearch nodes in private subnets, only accessible via internal API gateway
  • Audit logs forwarded to SIEM with real-time alerting for data export attempts
  • Quarterly penetration tests and automated compliance checks

Result: Zero security incidents in 3 years. Passed SOC 2 Type II audit with no findings.

Example 4: DevOps Team Misconfiguration

A startup team used the elastic superuser password in a CI/CD pipeline script. The script was accidentally committed to a public GitHub repository. Attackers used the credentials to delete all indices and inject malicious data.

What went wrong? Hardcoded secrets, no secrets management, no audit logging.

How it couldve been prevented: Use environment variables, integrate with Vault, enable audit logs, scan repositories for secrets using GitGuardian or TruffleHog.

FAQs

Can Elasticsearch be secured without a paid license?

Yes. The Basic license (free) includes X-Pack Security, TLS encryption, API keys, audit logging, and role-based access control. You do not need a Standard or Enterprise license to secure your cluster effectively.

Is it safe to expose Elasticsearch to the internet if I use a strong password?

No. Passwords can be brute-forced, leaked, or intercepted. Always restrict network access. Never rely on password strength alone. Assume any publicly exposed service is compromised.

How often should I rotate TLS certificates?

Best practice is every 90 days. Use automation (e.g., cert-manager, Ansible scripts) to renew and deploy certificates without downtime. Monitor expiration dates using tools like Prometheus + ssl_exporter.

Whats the difference between transport and HTTP layer security?

Transport layer security (port 9300) encrypts communication between Elasticsearch nodes in the cluster. HTTP layer security (port 9200) encrypts communication between clients (e.g., Kibana, apps) and the cluster. Both should be enabled in production.

Can I use LDAP or Active Directory with Elasticsearch?

Yes. Elasticsearch supports LDAP, Active Directory, SAML, and Kerberos for authentication. Configure this under xpack.security.authc.realms in elasticsearch.yml. This is recommended for enterprise environments with centralized identity management.

How do I test if my cluster is still exposed?

Use Shodan.io or Censys.io to search for your public IP or domain. Look for responses containing "elasticsearch" in the HTTP headers. You can also use Nmap:

nmap -p 9200 your-ip-address

If the port is open and returns cluster info, your cluster is exposed.

What should I do if my cluster is already compromised?

Immediately:

  • Disconnect the cluster from the network
  • Take a forensic snapshot if possible
  • Reset all passwords and API keys
  • Rebuild the cluster from a clean backup
  • Review audit logs to determine the attack vector
  • Apply all security patches and hardening steps in this guide

Does Elasticsearch support multi-tenancy for secure multi-team access?

Yes. Use role-based access control to assign different roles to teams (e.g., analytics_team, dev_team). Combine with index patterns and field-level security to restrict access to specific data subsets. For example, the finance team can only access indices with finance-* prefix.

Is it safe to run Elasticsearch on Kubernetes?

Yes, but only with proper security configuration. Use Helm charts with security context enabled, enforce pod security policies, enable network policies, and integrate with service meshes for mTLS. Never run as root. Use operators like Elastic Cloud on Kubernetes (ECK) for automated security best practices.

Conclusion

Securing an Elasticsearch cluster is a multi-layered effort that requires attention to network configuration, authentication, encryption, access control, and continuous monitoring. The consequences of neglecting securitydata breaches, regulatory fines, operational downtime, and reputational damageare severe and avoidable.

This guide has provided a comprehensive roadmap: from disabling public exposure and enabling TLS, to implementing RBAC, API keys, audit logging, and network segmentation. You now understand how to apply these controls in real-world scenarios, backed by best practices and documented failures.

Remember: Security is not a one-time setup. Its an ongoing discipline. Regularly audit your configuration, rotate credentials, update software, and educate your team. By treating Elasticsearch security as a core component of your infrastructurenot an afterthoughtyou protect not just your data, but your organizations integrity and trust.

Start implementing these steps today. Your future selfand your userswill thank you.