A 2:00 AM Incident: 300GB Log Cluster Exposed Naked on Port 9200
The on-call PagerDuty alarm blared relentlessly in the middle of the night. CPU usage on the master node hit 100%, while outbound network traffic suddenly spiked to 450 Mbps. I booted up my laptop and quickly SSHed into the bastion host to investigate. I ran a quick curl command:
curl -X GET "http://10.0.3.15:9200/_cat/indices?v"
The terminal immediately dumped all 42 stored indices. From e-wallet transaction histories to customer JWT refresh tokens, everything was laid bare in plain text. No password required. No security certificates.
The root cause was all too familiar: configuring network.host: 0.0.0.0 in the configuration file to let workers ship logs conveniently. When the infrastructure expanded with a VPC peering subnet, port 9200 was accidentally exposed to the entire internal workstation network. Any malware-infected laptop could have vacuumed up all 300GB of logs within 15 minutes.
Security Architecture: 3 Defense Layers for the Elastic Stack
To lock down the cluster, we need to implement three defense layers simultaneously:
- Mutual TLS Encryption: Covers both the Transport layer (port 9300 between ES nodes) and the HTTP layer (port 9200 for REST clients, Logstash, and Kibana). Without a valid CA certificate, unknown nodes are immediately rejected from joining the cluster. Man-in-the-middle packet sniffers only intercept encrypted gibberish.
- RBAC (Role-Based Access Control): Enforces the principle of least privilege strictly. For example, Filebeat only has write access to
app-logs-*. L1 on-call operators can only read logs from the last 7 days. Never use theelasticsuperuser for routine daily applications. - Audit Logging: Traces all suspicious activities. Security events such as unauthorized queries, brute-force password attempts, or privilege tampering are streamed to a dedicated log file for forensic investigations.
Step-by-Step Implementation
Step 1: Set Up a Custom CA and Issue Digital Certificates with elasticsearch-certutil
Before proceeding, stop the services to ensure a clean setup:
sudo systemctl stop elasticsearch kibana
Elasticsearch includes a built-in utility named elasticsearch-certutil, which generates standard certificates without messy OpenSSL commands. Generate the root Certificate Authority (CA):
cd /usr/share/elasticsearch
sudo bin/elasticsearch-certutil ca --pem --out /etc/elasticsearch/elastic-stack-ca.zip
sudo unzip /etc/elasticsearch/elastic-stack-ca.zip -d /etc/elasticsearch/cert/
Define the IP/DNS list of your nodes and Kibana in /etc/elasticsearch/instances.yml:
instances:
- name: "es-node1"
ip:
- "127.0.0.1"
- "10.0.3.15"
- name: "kibana"
ip:
- "127.0.0.1"
- "10.0.3.16"
Sign certificates for each service using the newly generated CA:
sudo bin/elasticsearch-certutil cert --pem \
--ca-cert /etc/elasticsearch/cert/ca/ca.crt \
--ca-key /etc/elasticsearch/cert/ca/ca.key \
--in /etc/elasticsearch/instances.yml \
--out /etc/elasticsearch/certs.zip
sudo unzip /etc/elasticsearch/certs.zip -d /etc/elasticsearch/certs/
sudo chown -R root:elasticsearch /etc/elasticsearch/cert*
sudo chmod 750 /etc/elasticsearch/cert*
Step 2: Configure TLS Encryption in elasticsearch.yml
Open /etc/elasticsearch/elasticsearch.yml and enable the security module for both port 9300 and port 9200:
# Enable X-Pack Security feature
xpack.security.enabled: true
# 1. Transport Layer (Inter-node communication on port 9300)
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.key: /etc/elasticsearch/certs/es-node1/es-node1.key
xpack.security.transport.ssl.certificate: /etc/elasticsearch/certs/es-node1/es-node1.crt
xpack.security.transport.ssl.certificate_authorities: [ "/etc/elasticsearch/cert/ca/ca.crt" ]
# 2. HTTP Layer (REST API on port 9200)
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.key: /etc/elasticsearch/certs/es-node1/es-node1.key
xpack.security.http.ssl.certificate: /etc/elasticsearch/certs/es-node1/es-node1.crt
xpack.security.http.ssl.certificate_authorities: [ "/etc/elasticsearch/cert/ca/ca.crt" ]
Save the file and restart the service:
sudo systemctl start elasticsearch
sudo systemctl status elasticsearch
Step 3: Initialize Passwords for Built-in System Accounts
Once security is enabled, Elasticsearch immediately shuts down anonymous access. You must configure passwords for default system accounts. On ES 7.x clusters, run the interactive setup tool:
sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
(Note: If running Elasticsearch 8.x or later, use bin/elasticsearch-reset-password -u <user> instead).
The utility will prompt you to set passwords for elastic, kibana_system, logstash_system, and beats_system. Make sure to back up the credentials for elastic and kibana_system into Vault or KeePass immediately.
Verify the HTTPS connection using curl:
curl --cacert /etc/elasticsearch/cert/ca/ca.crt -u elastic:NewlyCreatedPassword https://localhost:9200/
An HTTP 200 response with the cluster name verifies that TLS is functioning properly.
Step 4: Establish a Secure Kibana Connection to Elasticsearch
A frequent mistake is using the elastic superuser for Kibana. This violates key security practices. Kibana must use its dedicated service account, kibana_system.
Copy the appropriate certificates into Kibana’s configuration directory:
sudo mkdir -p /etc/kibana/certs
sudo cp /etc/elasticsearch/cert/ca/ca.crt /etc/kibana/certs/
sudo cp /etc/elasticsearch/certs/kibana/* /etc/kibana/certs/
sudo chown -R root:kibana /etc/kibana/certs
sudo chmod 750 /etc/kibana/certs
Update /etc/kibana/kibana.yml:
server.port: 5601
server.host: "0.0.0.0"
# Connect to Elasticsearch over HTTPS
elasticsearch.hosts: ["https://10.0.3.15:9200"]
elasticsearch.username: "kibana_system"
elasticsearch.password: "ConfiguredKibanaSystemPassword"
elasticsearch.ssl.certificateAuthorities: [ "/etc/kibana/certs/ca.crt" ]
# Enable HTTPS for Kibana Web UI (prevents in-transit credential sniffing)
server.ssl.enabled: true
server.ssl.certificate: /etc/kibana/certs/kibana.crt
server.ssl.key: /etc/kibana/certs/kibana.key
Start Kibana and access the web UI via https://10.0.3.16:5601:
sudo systemctl start kibana
Step 5: Tighten Permissions with RBAC and Enable Audit Logging
Log shippers (such as Fluent Bit or Logstash) do not need cluster-admin privileges. Create a dedicated role limited to writing to the app-logs-* index prefix:
curl --cacert /etc/elasticsearch/cert/ca/ca.crt -u elastic:NewlyCreatedPassword \
-X POST "https://localhost:9200/_security/role/log_shipper_role" \
-H 'Content-Type: application/json' -d'{
"cluster": ["monitor"],
"indices": [{
"names": [ "app-logs-*" ],
"privileges": ["write", "create_index"]
}]
}'
Assign this role to a dedicated shipper account:
curl --cacert /etc/elasticsearch/cert/ca/ca.crt -u elastic:NewlyCreatedPassword \
-X POST "https://localhost:9200/_security/user/app_shipper" \
-H 'Content-Type: application/json' -d'{
"password" : "ComplexShipperPassword#2026",
"roles" : [ "log_shipper_role" ],
"full_name" : "Production Shipper Agent"
}'
Finally, enable Audit Logging in /etc/elasticsearch/elasticsearch.yml to capture suspicious access events:
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.include: access_denied, anonymous_access_denied, authentication_failed, tampering_attempt
Restart Elasticsearch. Any unauthorized queries or password brute-force attempts will be recorded in /var/log/elasticsearch/<cluster-name>_audit.log in JSON format, ready for direct ingestion into Wazuh or your SOC team’s SIEM.
Conclusion
Log clusters often store the most sensitive data in your entire infrastructure. Skipping baseline security configurations might save 20 minutes during initial setup, but the fallout from a data breach is devastating. By implementing mutual TLS, locking down accounts with RBAC, and enabling Audit Logging, your Elasticsearch cluster will be fortified against both internal insider threats and external attacks.

