HTTP/REST clients and security

The Elasticsearch security features work with standard HTTP basic authentication headers to authenticate users. Since Elasticsearch is stateless, this header must be sent with every request:

  1. Authorization: Basic <TOKEN>

The <TOKEN> is computed as base64(USERNAME:PASSWORD)

Alternatively, you can use token-based authentication services.

Client examples

This example uses curl without basic auth to create an index:

  1. curl -XPUT 'localhost:9200/idx'
  1. {
  2. "error": "AuthenticationException[Missing authentication token]",
  3. "status": 401
  4. }

Since no user is associated with the request above, an authentication error is returned. Now we’ll use curl with basic auth to create an index as the rdeniro user:

  1. curl --user rdeniro:taxidriver -XPUT 'localhost:9200/idx'
  1. {
  2. "acknowledged": true
  3. }

Secondary authorization

Some APIs support secondary authorization headers for situations where you want tasks to run with a different set of credentials. For example, you can send the following header in addition to the basic authentication header:

  1. es-secondary-authorization: Basic <TOKEN>

The <TOKEN> is computed as base64(USERNAME:PASSWORD)

The es-secondary-authorization header has the same syntax as the Authorization header. It therefore also supports the use of token-based authentication services. For example:

  1. es-secondary-authorization: ApiKey <TOKEN>

The <TOKEN> is computed as base64(API key ID:API key)

Client libraries over HTTP

For more information about using security features with the language specific clients, refer to: