How to Secure Elasticsearch Cluster
How to Secure Elasticsearch Cluster Elasticsearch is a powerful, distributed search and analytics engine used by organizations worldwide to store, search, and analyze vast volumes of data in near real time. From e-commerce product catalogs to log monitoring systems and cybersecurity threat detection, Elasticsearch powers critical infrastructure. However, its popularity also makes it a prime target
How to Secure Elasticsearch Cluster
Elasticsearch is a powerful, distributed search and analytics engine used by organizations worldwide to store, search, and analyze vast volumes of data in near real time. From e-commerce product catalogs to log monitoring systems and cybersecurity threat detection, Elasticsearch powers critical infrastructure. However, its popularity also makes it a prime target for attackers. 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 an Elasticsearch cluster is not optionalit is a fundamental requirement for operational integrity and compliance.
This comprehensive guide walks you through every critical aspect of securing an Elasticsearch clusterfrom foundational configurations to advanced authentication and network hardening. Whether you're deploying Elasticsearch on-premises, in the cloud, or in a hybrid environment, this tutorial provides actionable, production-ready steps to protect your data and ensure compliance with industry standards such as GDPR, HIPAA, and PCI-DSS.
Step-by-Step Guide
1. Disable Public Exposure and Enforce Network Isolation
The most common cause of Elasticsearch breaches is accidental public exposure. By default, Elasticsearch binds to all network interfaces (0.0.0.0), making it accessible from anywhere on the internet if no firewall rules are in place. The first and most critical step is to restrict network access.
Open your Elasticsearch configuration filetypically located at /etc/elasticsearch/elasticsearch.ymland locate the network.host setting. Change it to bind only to internal interfaces:
network.host: 192.168.1.10
Replace 192.168.1.10 with the internal IP address of your Elasticsearch node. If you're running a multi-node cluster, ensure each node binds to its private IP and can communicate over the internal network.
Additionally, disable HTTP transport binding to external interfaces by setting:
http.host: 192.168.1.10
transport.host: 192.168.1.10
After making these changes, restart the Elasticsearch service:
sudo systemctl restart elasticsearch
Verify the binding using:
curl -X GET "http://192.168.1.10:9200"
Use tools like nmap or online port scanners to confirm port 9200 (HTTP) and 9300 (transport) are not reachable from external networks. If they are, review your cloud providers security groups (AWS Security Groups, Azure NSGs, GCP Firewall Rules) and ensure inbound traffic from the internet is blocked on these ports.
2. Enable Transport Layer Security (TLS/SSL)
Unencrypted communication between Elasticsearch nodes and clients exposes sensitive data to eavesdropping and man-in-the-middle attacks. Enabling TLS encrypts all traffic at the transport and HTTP layers.
Elasticsearch includes a built-in tool called elasticsearch-certutil to generate certificates. Run the following command on one of your nodes:
cd /usr/share/elasticsearch
bin/elasticsearch-certutil cert -out config/certs/elastic-certificates.p12
This generates a PKCS
12 keystore containing both the certificate and private key. Distribute this file to all nodes in the cluster. Then, update elasticsearch.yml with:
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: certs/elastic-certificates.p12
Ensure the file permissions are restrictive:
chmod 600 config/certs/elastic-certificates.p12
chown elasticsearch:elasticsearch config/certs/elastic-certificates.p12
Restart Elasticsearch. Verify TLS is active by accessing the cluster via HTTPS:
curl -k https://192.168.1.10:9200
For production environments, consider using certificates issued by a trusted Certificate Authority (CA) rather than self-signed ones. This avoids browser and client warnings and improves trust across integrated systems.
3. Enable and Configure X-Pack Security (Elasticsearch Security)
Elasticsearchs built-in security features, part of X-Pack, provide authentication, authorization, encryption, and auditing. These are essential for enterprise-grade security.
First, ensure X-Pack security is enabled in elasticsearch.yml:
xpack.security.enabled: true
xpack.security.authc.realms.file.file1.order: 0
xpack.security.authc.realms.native.native1.order: 1
After enabling, initialize the built-in users with:
bin/elasticsearch-setup-passwords auto
This generates random passwords for the built-in users: elastic, kibana, logstash_system, beats_system, apm_system, and remote_monitoring_user. Save these passwords securely.
Connect to Kibana (if used) and update its configuration (kibana.yml) to authenticate with the elastic user:
elasticsearch.username: "elastic"
elasticsearch.password: "your-generated-password"
Restart Kibana after making changes.
4. Implement Role-Based Access Control (RBAC)
With authentication enabled, enforce least-privilege access using roles. Avoid using the superuser elastic account for daily operations.
Use Kibanas Security UI or the Elasticsearch REST API to create custom roles. For example, create a role called log_writer that only allows indexing into specific indices:
POST /_security/role/log_writer
{
"indices": [
{
"names": [ "logs-*" ],
"privileges": [ "write", "create_index" ]
}
],
"applications": []
}
Then assign this role to a user:
POST /_security/user/logstash_user
{
"password": "strong-password-123",
"roles": [ "log_writer" ],
"full_name": "Logstash Service Account"
}
Similarly, create roles for read-only analysts, cluster administrators, and monitoring agents. Never assign the superuser role to service accounts.
Use Kibanas Role Mapping feature to integrate with external identity providers like LDAP, Active Directory, or SAML. This centralizes user management and reduces credential sprawl.
5. Secure Kibana and Other Clients
Kibana, Logstash, Filebeat, and other Elasticsearch clients must also be secured. Kibana should always be accessed over HTTPS and behind a reverse proxy with authentication.
Configure Kibana to enforce HTTPS:
server.ssl.enabled: true
server.ssl.certificate: /etc/kibana/certs/kibana.crt
server.ssl.key: /etc/kibana/certs/kibana.key
Use a reverse proxy like Nginx or HAProxy to add an additional layer of authentication:
location / {
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
}
Generate the password file using htpasswd:
htpasswd -c /etc/nginx/.htpasswd admin
For Beats agents (Filebeat, Metricbeat), configure them to use TLS and authenticate with a dedicated user:
output.elasticsearch:
hosts: ["https://192.168.1.10:9200"]
username: "metricbeat_user"
password: "secure-metricbeat-password"
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
6. Enable Audit Logging
Audit logging records all security-related eventsauthentication attempts, authorization failures, index modifications, and configuration changes. 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, authentication_success, granted_privilege, revoked_privilege, index, delete, search, cluster_health, cluster_settings
xpack.security.audit.logfile.events.exclude:
xpack.security.audit.logfile.format: json
Audit logs are written to /var/log/elasticsearch/ by default. Use a log aggregation tool like Filebeat or Fluentd to forward these logs to a centralized SIEM system such as Elasticsearch itself (in a separate secure cluster), Splunk, or Graylog.
Regularly review audit logs for anomalies: repeated failed logins, access from unusual IPs, or unauthorized index deletions.
7. Protect Indices with Index-Level Security
Not all data has the same sensitivity. Use index templates and index-level permissions to enforce granular access control.
Create an index template that applies specific settings and permissions:
PUT _index_template/secure_logs_template
{
"index_patterns": ["logs-*"],
"template": {
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2
},
"aliases": {
"logs-current": {}
}
},
"priority": 500
}
Then, define a role that restricts access to this template:
POST /_security/role/secure_logs_reader
{
"indices": [
{
"names": [ "logs-*" ],
"privileges": [ "read", "view_index_metadata" ]
}
],
"run_as": [],
"metadata": {}
}
Combine this with index lifecycle management (ILM) policies to automatically move older, less sensitive data to less restrictive indices or cold storage.
8. Harden the Underlying Operating System
Elasticsearch runs on Linux. A secure cluster starts with a secure OS.
- Disable root login via SSH and enforce key-based authentication.
- Use a non-root user to run Elasticsearch (default:
elasticsearch). - Install and configure a host-based firewall (e.g.,
ufworfirewalld) to allow only necessary ports: 9200 (internal), 9300 (internal), and 22 (SSH). - Apply OS security patches regularly.
- Disable unnecessary services and daemons.
- Use SELinux or AppArmor to restrict Elasticsearchs file system access.
- Mount filesystems with
noexec,nodev, andnosuidflags where possible.
Example UFW configuration:
sudo ufw allow from 192.168.1.0/24 to any port 9200
sudo ufw allow from 192.168.1.0/24 to any port 9300
sudo ufw allow 22
sudo ufw enable
9. Implement Backup and Disaster Recovery
Security includes protecting data from loss. Regular, encrypted backups are essential.
Register a repository for snapshots:
PUT /_snapshot/my_backup_repo
{
"type": "fs",
"settings": {
"location": "/mnt/backups/elasticsearch",
"compress": true
}
}
Ensure the backup directory is on a separate storage volume, encrypted, and not accessible from the Elasticsearch nodes directly. Use filesystem-level encryption (LUKS) or cloud-native encryption (AWS EBS encryption, Azure Disk Encryption).
Take a snapshot:
PUT /_snapshot/my_backup_repo/snapshot_1
{
"indices": "logs-*",
"ignore_unavailable": true,
"include_global_state": false
}
Automate snapshots using a cron job or Kibanas Snapshot Lifecycle Management (SLM) feature:
PUT /_slm/policy/daily-logs-backup
{
"schedule": "0 30 2 * * ?",
"name": "",
"repository": "my_backup_repo",
"config": {
"indices": [ "logs-*" ],
"ignore_unavailable": true
},
"retention": {
"expire_after": "30d",
"min_count": 5
}
}
Test restoration procedures quarterly. A backup is useless if you cannot restore from it.
10. Monitor and Alert on Security Events
Proactive monitoring detects threats before they escalate. Use Elasticsearchs built-in monitoring or integrate with external tools like Prometheus and Grafana.
Enable monitoring in elasticsearch.yml:
xpack.monitoring.enabled: true
xpack.monitoring.collection.enabled: true
Set up alerts for:
- Multiple failed authentication attempts from a single IP
- Unexpected index deletions
- High CPU or memory usage on nodes
- Unusual search patterns (e.g., wildcard searches on sensitive indices)
Create alerts using Kibanas Alerting and Actions UI or via the Watcher API (deprecated in newer versions; use Watcher replacement: Alerting). For example, create a threshold alert for failed logins:
- Trigger: > 5 failed authentication events in 5 minutes
- Action: Send email or webhook to security team
Integrate with SIEM tools like Elastic Security (formerly SIEM) for behavioral analytics, threat detection, and automated response.
Best Practices
Use the Principle of Least Privilege
Every user, service, and application should have the minimum permissions required to function. Avoid assigning broad roles like superuser or all. Create granular roles for specific tasks and assign them only where needed.
Rotate Credentials Regularly
Automate password rotation for service accounts and API keys. Use secrets management tools like HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault to store and retrieve credentials dynamically. Never hardcode credentials in configuration files.
Keep Elasticsearch Updated
Elasticsearch releases security patches regularly. Subscribe to Elastics security advisories and apply updates promptly. Never run end-of-life versions. As of 2024, only versions 8.x are supported.
Disable Unused Features
Disable unused X-Pack features to reduce the attack surface:
xpack.watcher.enabled: false
xpack.ml.enabled: false
xpack.graph.enabled: false
xpack.ingest.geoip.enabled: false
Only enable features you actively use.
Separate Environments
Isolate development, staging, and production clusters. Never use production credentials or data in non-production environments. Use data masking or synthetic data in dev environments.
Implement Zero Trust Architecture
Treat every request as untrusted, even if it originates inside your network. Enforce mutual TLS (mTLS) between nodes and clients. Use service accounts with short-lived tokens where possible.
Regular Security Audits
Perform quarterly security reviews. Use tools like elasticsearch-security-check (community scripts) or Elastics own Security Assessment Tool to scan for misconfigurations.
Document Your Security Policy
Create and maintain a security policy document covering:
- Access control procedures
- Incident response plan
- Backup and recovery protocols
- Role definitions and assignments
- Change management process for security configurations
Ensure all team members are trained on this policy.
Use Infrastructure as Code (IaC)
Manage your Elasticsearch security configuration using IaC tools like Terraform, Ansible, or Puppet. This ensures consistency, auditability, and repeatability across environments.
Example Terraform snippet for AWS Elasticsearch:
resource "aws_elasticsearch_domain" "secure_es" {
domain_name = "secure-cluster"
elasticsearch_version = "8.10"
cluster_config {
instance_type = "r6g.large.search"
instance_count = 3
}
domain_endpoint_options {
enforce_https = true
tls_security_policy = "Policy-Min-TLS-1-2-2019-07"
}
advanced_security_options {
enabled = true
internal_user_database_enabled = true
master_user_options {
master_user_arn = aws_iam_user.elastic_user.arn
}
}
tags = {
Environment = "production"
Security = "compliant"
}
}
Tools and Resources
Official Elasticsearch Security Tools
- Elasticsearch Security Documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html
- elasticsearch-certutil: Built-in certificate generator
- Elastic Security (SIEM): Threat detection, endpoint protection, and UEBA
- Snapshot Lifecycle Management (SLM): Automated backup policies
- Alerting and Actions: Real-time alerting based on query triggers
Third-Party Tools
- HashiCorp Vault: Secrets management and dynamic credential issuance
- OWASP ZAP: Security testing for HTTP endpoints
- Nmap: Network scanning to detect open ports
- Shodan: Search engine for exposed devicesuse to check if your cluster is publicly accessible
- Fail2Ban: Blocks IPs after repeated failed login attempts
- Graylog / Splunk: Centralized log aggregation and analysis
- Terraform / Ansible: Infrastructure automation for secure deployments
Community Resources
- Elastic Discuss Forum: https://discuss.elastic.co
- GitHub Security Advisories: https://github.com/elastic/elasticsearch/security/advisories
- ELK Stack Security Best Practices (Elastic Blog): https://www.elastic.co/blog/category/security
- OWASP Top 10 for Elasticsearch: Community-maintained checklist for common vulnerabilities
Compliance Frameworks
Align your Elasticsearch security posture with:
- GDPR: Data minimization, encryption at rest and in transit, access logs
- HIPAA: Audit trails, authentication, and data integrity controls
- PCI-DSS: Secure network architecture, access control, regular testing
- NIST SP 800-53: Comprehensive security controls for federal systems
- ISO/IEC 27001: Information security management system requirements
Real Examples
Example 1: Ransomware Attack on an Exposed Cluster
In 2021, a healthcare providers Elasticsearch cluster was found publicly accessible with no authentication. Attackers indexed a ransom note and encrypted data, demanding $50,000 in Bitcoin. The organization had no backups and lost six months of patient records.
Post-incident, they implemented:
- Network isolation using VPC peering and security groups
- TLS encryption for all communications
- Role-based access with audit logging
- Daily encrypted snapshots stored in a separate AWS account
- Automated alerts for any write access to patient indices
They recovered data from backups and avoided paying the ransom.
Example 2: Insider Threat via Overprivileged Service Account
A financial firm used a single elastic user for all internal applications. An employee with access to the application server used the credentials to delete a month of transaction logs to cover up fraud.
After detection, the firm:
- Created dedicated service accounts with minimal privileges
- Enabled audit logging and monitored for index deletions
- Integrated with Active Directory for centralized user management
- Implemented data retention policies to prevent permanent deletion
The fraudster was identified via audit logs and terminated.
Example 3: Cloud Misconfiguration in AWS
A startup deployed Elasticsearch on EC2 and forgot to restrict the security group. Shodan reported 12,000 exposed clusters globallyincluding theirs. Attackers mined cryptocurrency using their clusters CPU.
They resolved the issue by:
- Blocking all inbound traffic except from their VPC
- Enabling TLS and X-Pack security
- Switching to Amazon OpenSearch Service (managed Elasticsearch) with built-in IAM integration
- Running a monthly security scan using AWS Security Hub
FAQs
Is Elasticsearch secure by default?
No. Elasticsearch does not enable authentication, encryption, or access control by default. A fresh installation is publicly accessible and vulnerable to exploitation.
Can I use Elasticsearch without X-Pack security?
Technically yes, but it is strongly discouraged. Without security features, your cluster is exposed to data theft, ransomware, and unauthorized modification. X-Pack security is free in Elasticsearch 8.x.
How do I know if my Elasticsearch cluster is exposed?
Use Shodan.io or Censys.io and search for port:9200. If your public IP appears in results, your cluster is exposed. Use nmap -p 9200 <your-ip> to verify from outside your network.
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 (Kibana, Beats, apps) and the cluster. Both should be enabled for full protection.
Can I use LDAP or Active Directory with Elasticsearch?
Yes. Elasticsearch supports LDAP, Active Directory, SAML, and Kerberos via X-Pack security. Configure realms in elasticsearch.yml to integrate with your existing identity provider.
How often should I rotate certificates?
For internal PKI, rotate certificates every 612 months. For externally issued certificates, follow the CAs validity period. Automate renewal using tools like cert-manager (Kubernetes) or HashiCorp Vault.
Does Elasticsearch support multi-tenancy?
Yes, through index-level permissions and role-based access. You can isolate data for different departments or customers using separate indices and roles, even within a single cluster.
What should I do if my cluster is compromised?
Immediately isolate the cluster from the network. Disable all external access. Review audit logs to determine the scope of the breach. Restore from a clean backup. Rebuild the cluster with proper security enabled. Conduct a post-mortem and update your security policy.
Is it safe to run Elasticsearch in a container?
Yes, if secured properly. Use Docker or Kubernetes with network policies, read-only filesystems, and minimal privileges. Never expose container ports to the internet. Use service meshes (Istio, Linkerd) for mTLS between services.
Can I use Elasticsearch in a hybrid cloud environment securely?
Absolutely. Use VPNs or private links (AWS PrivateLink, Azure Private Endpoint) to connect on-premises and cloud nodes. Apply the same security controls across all environments. Centralize logging and monitoring.
Conclusion
Securing an Elasticsearch cluster is not a one-time taskit is an ongoing discipline that requires vigilance, automation, and adherence to best practices. From network isolation and TLS encryption to role-based access control and audit logging, every layer of your deployment must be hardened against modern threats. The consequences of neglecting security are severe: data breaches, regulatory fines, reputational damage, and operational downtime.
This guide has provided a comprehensive, step-by-step roadmap to secure your Elasticsearch environment. Implement these measures methodically. Test your configurations. Automate where possible. Train your team. Monitor continuously.
Remember: security is not a featureits the foundation. In a world where data is the new currency, protecting your Elasticsearch cluster isnt just technical best practiceits a business imperative.