Elasticsearch "missing authentication credentials for REST request" in CI
Elasticsearch 8.x turns X-Pack security on by default, so every REST request must authenticate. A client that connected fine against a 7.x dev cluster now gets "missing authentication credentials". For CI you either disable security or pass the built-in user credentials.
What this error means
Requests return HTTP 401 with "missing authentication credentials for REST request [/...]". It appears immediately after upgrading a service container to Elasticsearch 8.x.
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication
credentials for REST request [/_cluster/health]"}],"type":"security_exception"},"status":401}Common causes
Security is on by default in 8.x
Unlike 7.x dev mode, an 8.x node enforces authentication out of the box, so anonymous requests are rejected with 401.
The client sends no credentials
A test client configured for an open cluster sends no basic-auth header, so the request has no credentials to authenticate.
How to fix it
Disable security for a throwaway test cluster
- Set
xpack.security.enabled=falseon the service container. - This restores open, unauthenticated HTTP for the test cluster.
- Only do this for ephemeral CI clusters, never for anything reachable outside the job.
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4
env:
discovery.type: single-node
xpack.security.enabled: "false"Or authenticate with the elastic user
Keep security on and pass the built-in elastic user password (set via ELASTIC_PASSWORD) on every request.
curl -u elastic:"$ELASTIC_PASSWORD" http://localhost:9200/_cluster/healthHow to prevent it
- Decide per environment: disable security for CI, or wire credentials into the client.
- Set
ELASTIC_PASSWORDexplicitly so it does not vary between runs. - Pin the Elasticsearch major version so security defaults do not change under you.