How to perform token authentication in elasticsearch?

Viewed 47530

I'm testing Elasticsearch in development mode with docker official image.

The basic install is based on X_pack and basic authentication.

Everything works fine by performing curl like:

curl -XPUT -u elastic:elasticpassword "http://localhost:9200/movies/movie/1" -d'
{
  "title": "The Godfather",
  "director": "Francis Ford Coppola",
  "year": 1972, "user":"elastic", "password":"changeme"
}'

But is there a way to perform a token request (with user and password) and then query Elasticsearch with the token. Instead of having to specify user/password every time I perform a query?

4 Answers

Cutting out a lot of my original answer because you could argue it's all local, but leaving one major complaint about security here:

  1. Definitely don't go to base64encode.org and enter your username:password. The very fact that it is suggested here on StackOverflow makes that site now (sadly for the owners) and incredibly juicy hacking target to compromise since they know people are going there.

Further to Taran's answer, if you want to generate base64 token, you can do so by the following command:

echo -n 'username:pass' | openssl base64
curl -X GET --user myuser:mypassword "http://elasticsearch:9200/_cluster/health?pretty"

In my case above curl helped

    {
  "cluster_name" : "elasticsearch",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 16,
  "active_shards" : 16,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}
Related