pythondjangoelasticsearchhttp-authenticationelasticutils

Python elasticutils http authentication or api key?


Hello I'm currently using elasticutils in django to search indexed documents but my cluster doesn't have any authentication method so anyone can access to my ES server from internet, is there any way to set a key o auth method with elasticutils in order to the only servers with the key can query to the ES server?

Something likely searchly or amazon keys api's


Solution

  • There are several ways of protecting your ES cluster.

    The easiest way would be to install a plugin such as elasticsearch-http-basic in order to protect your cluster. You can configure it with a BASIC username/password combo and then it's just a matter of configuring elasticutils to pass those BASIC credentials along to the underlying ES client provided by the elasticsearch-py library.

    When calling get_es(...) you simply need to add the http_auth parameter which will be passed along to the Elasticsearch constructor like this:

    es_client = get_es(urls=['localhost:9200'], http_auth="username:password")
    

    Another way is to hide your ES cluster behind a web server like Apache or Nginx, but it's more involved than the above solution.

    You can also use Shield, just know it is a commercial product.