How to setup a basic authentication for Elasticsearch?

I have a docker image of elasticsearch, version=7.0.1, I used the command to run the image

docker run -d -p 9200:9200 -p 9301:9301 --name elastic_search -e "discovery.type=single-node" -e "xpack.security.enabled=true" -e "ELASTICSEARCH_USERNAME=john" -e "ELASTICSEARCH_PASSWORD=deer" -v elastic_search_volume:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch:7.0.1

Without porviding any credentials for my curl command, curl localhost:9200

I got the following output,

$ curl localhost:9200
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
100   508  100   508    0     0  26736      0 --:--:-- --:--:-- --:--:-- 28222{
"name" : "f1a397cdc93b",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "sBiiYUlsSM6e-RzJJcTvvg",
"version" : {
"number" : "7.0.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "e4efcb5",
"build_date" : "2019-04-29T12:56:03.145736Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.7.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

Although, I have provided the credentials for the docker image while starting in the form of environmental variables, still I am able to access the database without providing the credentials.
Even for the Kibana, without any configuration, still its able to access the database.

Can anyone help me on this?
Thanks

The problem is here: 7.0.1

With this old version, you need a commercial license.
Just use the latest version we released instead, 7.5.0 and you should be all set.
At least use 7.1.x to have access to this free security feature.

1 Like

Thanks @dadoonet. Can you please share some information such that I can setup a basic username and password to the elasticsearch container.

If I update my Es version, is the docker command is correct for setting up the username which I was doing earlier?

Thanks

I think you need to use ELASTIC_PASSWORD instead.
I shared an example (docker-compose) here: Create user in elasticsearch

@dadoonet Thanks a lot, it worked. I wasn't able to find any documentation for the same, which cause such delay.

Thanks.