When an Unsecured Elasticsearch Cluster Becomes an Open Invitation
A few years ago, a colleague asked me to look at a sluggish analytics cluster on a cloud VM. Port 9200 was wide open. Within two minutes, I realized all 3.8 million customer support tickets were readable over plain HTTP without a password. Worse, an automated scanner had already created a ransom note index.
Ever since an SSH brute-force attack hit one of my servers at midnight, I treat security as step zero. Public IPv4 ranges are scanned around the clock. In practice, bots often find and wipe an exposed port 9200 within 15 to 30 minutes of a VM booting.
Hiding Elasticsearch behind a basic firewall isn’t enough anymore. Let’s look at why production clusters leak data, how common defense layers compare, and the exact TLS, RBAC, and audit logging setup I use to lock them down.
Why Production Clusters Leak Data
Zero-day exploits rarely cause Elasticsearch breaches. Most incidents trace back to three predictable configuration gaps that compound each other:
- Unencrypted traffic on the wire: Without TLS, client queries on port 9200 and node-to-node chatter on port 9300 travel in cleartext. Anyone on the same network segment can sniff credentials and payloads.
- All-or-nothing access control: Sharing the built-in
elasticsuperuser account across microservices is a common shortcut. If one API key or app config leaks, attackers can read or drop every index in the cluster. - Zero visibility into who did what: Standard application logs only show that a cluster slowed down or crashed. Without audit logging, you have no record of failed logins, denied permissions, or unauthorized reads.
Lateral movement happens even inside a private VPC. Once an attacker lands on a single web server, an unauthenticated Elasticsearch node is the easiest target to dump.
Comparing Security Approaches: Firewall vs. Proxy vs. Native
Teams usually try one of three ways to protect a cluster. Only one covers the whole stack:
- Network firewalls only: Restricting ports 9200 and 9300 with security groups or
iptablesis mandatory, not sufficient. It blocks external scanners, yet leaves you exposed to compromised internal hosts and traffic sniffing on shared cloud networks. - Reverse proxy in front of port 9200: Putting Nginx with HTTPS and Basic Auth in front of Elasticsearch encrypts client traffic. However, node-to-node transport on port 9300 stays unencrypted, and Nginx cannot enforce index-level permissions or log internal cluster actions.
- Native Elasticsearch security: Built-in TLS, RBAC, and audit logging protect both HTTP and transport layers. You get least-privilege roles per index and security events logged straight from the engine.
Keep your perimeter firewall, and use a reverse proxy if you need rate limiting. Native security is still the only option that encrypts inter-node traffic and enforces granular permissions inside the cluster.
How to Lock Down Elasticsearch with TLS, RBAC, and Audit Logging
Layering native TLS, role-based access control, and targeted audit logs gives you defense in depth without heavy overhead. Here are the exact configs and commands I use on production nodes.
1. Encrypt Both Transport and HTTP Layers with TLS
Many teams enable HTTPS for Kibana and client apps while leaving internal node-to-node traffic unencrypted. Configure both xpack.security.transport.ssl and xpack.security.http.ssl. Use elasticsearch-certutil to create a private Certificate Authority (CA) and signed node certificates:
# Generate a private CA for your cluster
/usr/share/elasticsearch/bin/elasticsearch-certutil ca \
--out /etc/elasticsearch/certs/elastic-stack-ca.p12 \
--pass "StrongCAPassword!"
# Generate node certificates signed by that CA
/usr/share/elasticsearch/bin/elasticsearch-certutil cert \
--ca /etc/elasticsearch/certs/elastic-stack-ca.p12 \
--ca-pass "StrongCAPassword!" \
--out /etc/elasticsearch/certs/elastic-certificates.p12 \
--pass "StrongNodePassword!"
# Export the CA certificate in PEM format for curl and clients
openssl pkcs12 -in /etc/elasticsearch/certs/elastic-stack-ca.p12 \
-cacerts -nokeys -passin pass:"StrongCAPassword!" \
-out /etc/elasticsearch/certs/ca.crt
Lock down permissions before editing your config. Set the certs directory to 750 and the certificate files to 640, owned by root:elasticsearch. Then enable security in /etc/elasticsearch/elasticsearch.yml:
xpack.security.enabled: true
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
Store keystore and truststore passwords in the Elasticsearch keystore rather than leaving plaintext secrets in elasticsearch.yml:
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password
2. Enforce Least-Privilege RBAC Instead of Sharing Superusers
Skip the elastic superuser in application configs and Logstash pipelines. Create dedicated roles that limit each service to specific index patterns and actions. A service writing to app-logs-* has no business deleting indices or reading billing-invoices-*.
Create a scoped role through the REST API over HTTPS:
curl -X POST "https://localhost:9200/_security/role/app_logs_writer" \
--cacert /etc/elasticsearch/certs/ca.crt \
-u elastic:YourSuperuserPassword \
-H "Content-Type: application/json" -d '{
"cluster": ["monitor"],
"indices": [
{
"names": ["app-logs-*"],
"privileges": ["create_index", "write", "read"]
}
]
}'
Next, bind a dedicated service account to that role:
curl -X POST "https://localhost:9200/_security/user/log_ingestor" \
--cacert /etc/elasticsearch/certs/ca.crt \
-u elastic:YourSuperuserPassword \
-H "Content-Type: application/json" -d '{
"password": "AnotherStrongServicePass!99",
"roles": ["app_logs_writer"],
"full_name": "Application Log Ingestor"
}'
For short-lived microservices and CI/CD jobs, issue API keys (POST /_security/api_key) with a 30- or 90-day expiration instead of static passwords. Disable any unused built-in accounts while you are at it.
3. Enable Targeted Audit Logging Without Flooding Disk
Audit logs give you a forensic trail during an incident, but logging every read will sink your storage. On a cluster handling 5,000 requests per second, recording every access_granted event can generate 10–20 GB of logs per node each day. Stick to high-signal events: failed logins, access denials, and admin changes.
Add these settings to /etc/elasticsearch/elasticsearch.yml on every node:
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.include: [
"access_denied",
"authentication_failed",
"anonymous_access_denied",
"tampered_request",
"run_as_denied"
]
xpack.security.audit.logfile.events.emit_request_body: false
Keeping emit_request_body: false strips sensitive payloads and passwords from the log while preserving the source IP, username, timestamp, and target index. Need compliance tracking for privileged users? Selectively include access_granted for specific roles or indices using xpack.security.audit.logfile.events.ignore_filters.
Ship /var/log/elasticsearch/*_audit.json off-host to a separate monitoring cluster or SIEM right away. Local logs are the first thing an attacker wipes after compromising a node.
4. Verify Your Hardening Before Going Live
Run three quick checks from a remote host before sending production traffic to the cluster:
- Confirm plain
http://requests fail or time out once TLS is enforced. - Verify an unauthenticated request to
https://your-node:9200/_cat/indicesreturns401 Unauthorized. - Query an unauthorized index like
billing-invoices-2026usinglog_ingestor. Confirm it returns403 Forbidden, then check_audit.jsonto verify the denial was logged.
Spending 20 minutes on TLS, tight RBAC roles, and lean audit logging at cluster creation beats an emergency response at 2 a.m.

