How to perform token authentication in elasticsearch? How to perform token authentication in elasticsearch? elasticsearch elasticsearch

How to perform token authentication in elasticsearch?


The default X_Pack in docker image has Basic authentication enabled. Which is what your are using. The token for the same is base64(user:password). You can generate the same using http://base64encode.org and inputing :.

In curl there are two ways to call Basic auth URLs

curl -XPUT -u elastic:elasticpassword "http://localhost:9200/movies/movie/1" -d''

which you have already been using

curl -H "Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==" -XPUT "http://localhost:9200/movies/movie/1" -d'....'

Now if your problem is putting in this again and again then you better create a alias in your bash profile like below

alias curles='curl  -u elastic:elasticpassword'

After that you can call your commands as below

curles -XPUT "http://localhost:9200/movies/movie/1" -d''


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