Elasticsearch: read-only user setup
What we scrape: Cluster health, node CPU/heap/GC, thread-pool queues, JVM stats, and cluster settings — all surfaced through the cluster-level read endpoints (`/_cluster/health`, `/_nodes/stats`, `/_cluster/settings`).
The official [`elasticsearch_exporter` upstream](https://github.com/prometheus-community/elasticsearch_exporter#elasticsearch-7x-security-privileges) requires exactly the cluster-level `monitor` privilege for its default collectors plus `collector.clustersettings` — the two collectors the agent enables (`all = true`, `cluster_settings = true`). Nothing more, nothing less: no `read`, no `indices`, no `manage`. Run the two commands below against your cluster as an admin (e.g. `elastic`), then paste the resulting username + password into the Add Exporter form.
1. Create a role with the cluster `monitor` privilege
The role grants the cluster `monitor` privilege — read-only access to cluster health, node stats, hot threads, pending tasks, and cluster settings. No `read`, no `write`, no `manage`, and no per-index access whatsoever.
bashcurl -sS -u elastic:$ES_ADMIN_PASSWORD \ -X POST "$ES_URL/_security/role/prometheus_metrics" \ -H 'Content-Type: application/json' \ -d '{ "cluster": ["monitor"], "indices": [] }'2. Create the user and assign the role
Replace `CHANGE_ME_STRONG_PASSWORD` with a freshly generated value (`openssl rand -base64 24`). Store it in your secret manager — the agent posts it to site-main over TLS and we keep it encrypted at rest.
bashcurl -sS -u elastic:$ES_ADMIN_PASSWORD \ -X POST "$ES_URL/_security/user/prometheus_exporter" \ -H 'Content-Type: application/json' \ -d '{ "password": "CHANGE_ME_STRONG_PASSWORD", "roles": ["prometheus_metrics"], "full_name":"Prometheus metrics exporter (read-only)" }'3. Verify the user can read cluster metrics but nothing else
The first call must return cluster health (200). The second must be rejected (`security_exception`) — proof that the user can never read documents, list indices, or change settings.
bashcurl -sS -u prometheus_exporter:CHANGE_ME_STRONG_PASSWORD \ "$ES_URL/_cluster/health?pretty" curl -sS -u prometheus_exporter:CHANGE_ME_STRONG_PASSWORD \ -X POST "$ES_URL/_security/role/anything" \ -H 'Content-Type: application/json' -d '{"cluster":["all"]}'
That's everything. The agent uses Basic auth with `prometheus_exporter` to call `_cluster/health`, `_nodes/stats`, and `_cluster/settings` — every endpoint covered by the cluster `monitor` privilege, and nothing the user can mutate.