# How can I use kerberos under python elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-can-i-use-kerberos-under-python-elasticsearch/302981>\
**Category:** Elasticsearch\
**Created:** [April 22, 2022, 6:21am UTC](https://discuss.elastic.co/t/how-can-i-use-kerberos-under-python-elasticsearch/302981 "2022-04-22T06:21:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![papi1992](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/papi1992/32/104677_2.png) [@papi1992](https://discuss.elastic.co/u/papi1992)\
**Post date:** [April 22, 2022, 6:21am UTC](https://discuss.elastic.co/t/how-can-i-use-kerberos-under-python-elasticsearch/302981/1 "2022-04-22T06:21:14Z")

</div>

I checked the documentation of [elasticsearch:7.x](https://elasticsearch-py.readthedocs.io/en/7.x/api.html) but still didn't find the way how I can force the python `ES` package to use my kerberos token.

I can reach the `ES` through a browser, `curl` _( `curl --negotiate -u` )_ and `requests` with `requests_kerberos` _( with mutual `OPTIONAL` config )_ but with the `python-es` package calling a simple `es.cat.health()` I get `401` `AuthenticationException`.

My questions are:

- Where was I wrong? What did I miss?
- Is it even possible to force the ES python lib to use kerberos or does it work under the hood?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![papi1992](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/papi1992/32/104677_2.png) [@papi1992](https://discuss.elastic.co/u/papi1992)\
**Post date:** [April 22, 2022, 8:06am UTC](https://discuss.elastic.co/t/how-can-i-use-kerberos-under-python-elasticsearch/302981/2 "2022-04-22T08:06:35Z")

</div>

It seems We've found a solution, but basically not from the docs.

I've read in the doc about the `Elasticsearch` object can receive `http_auth` input, but unfortunately I didn't find what it exactly waits for.

So, you can force the `Elasticsearch` to use the `HTTPKerberosAuth` class from the `requests_kerberos` lib in same way as you can use that for a simple get request \>

```
es = Elasticsearch(<host>, http_auth=HTTPKerberosAuth(mutual_authentication=OPTIONAL))

```

It works well, but any other suggestions, knowledge share or comments are welcomed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 20, 2022, 8:07am UTC](https://discuss.elastic.co/t/how-can-i-use-kerberos-under-python-elasticsearch/302981/3 "2022-05-20T08:07:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
