# What's Python "best practice" for security certificates with ES8?

**URL:** <https://discuss.elastic.co/t/whats-python-best-practice-for-security-certificates-with-es8/327009>\
**Category:** Elasticsearch\
**Created:** [March 5, 2023, 2:03pm UTC](https://discuss.elastic.co/t/whats-python-best-practice-for-security-certificates-with-es8/327009 "2023-03-05T14:03:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrodent](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mrodent](https://discuss.elastic.co/u/mrodent)\
**Post date:** [March 5, 2023, 2:03pm UTC](https://discuss.elastic.co/t/whats-python-best-practice-for-security-certificates-with-es8/327009/1 "2023-03-05T14:03:15Z")

</div>

I just set up ES 8.6.2 on my machine. This is a single-machine setup. In fact I'm upgrading from 7.10.2, see [previous question](https://discuss.elastic.co/t/run-two-versions-of-es-on-machine/326985).

I've managed to obtain a password for user "elastic"... this means I can get the "You know, for search" page in a browser.

I've worked out how to include the username and password in Postman, so I can do that using a RESTful URL thing.

I've also worked out how to use the Python 'requests' package, using requests.auth.HTTPBasicAuth. But I find that unless I include a keyword pair "'verify' : False" in the kwargs I get an error like this:

```auto
requests.exceptions.SSLError: HTTPSConnectionPool(host='localhost', port=9500): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)')))

```

NB I have deliberately configured ES 8.6.2 to use port 9500. Also I prefer to use the 'requests' package rather than the 'elasticsearch' "thin wrapper" package, for simplicity/visibility.

The thing is, I really understand nothing at all about "security layers" and "certificates" and "certificate authorities". Although I've tried to understand, this whole topic is a complete mystery to me, and I'm just using ES on a single machine, to reverse-index documents.

I have seen [this other question from 2019](https://discuss.elastic.co/t/security-best-practice-when-using-es-with-custom-frontend/202339), but it is obviously by someone who understands about security layers and certificates.

The above workaround (verify: False) by default produces a warning from the urllib3 library: "... Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised... " (!). It's possible to suppress this warning. But bypassing everything like this feels a bit wrong.

I am not sure whether there is a real security issue here: anyone connecting to my machine for nefarious purposes wouldn't for example be able to know the ES server password.

But I would like to know what the recommended best practice is with ES 8 when using Python.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 5, 2023, 4:17pm UTC](https://discuss.elastic.co/t/whats-python-best-practice-for-security-certificates-with-es8/327009/2 "2023-03-05T16:17:08Z")

</div>

The [Python `requests` library docs](https://requests.readthedocs.io/en/latest/user/advanced/#ssl-cert-verification) indicate you should set `verify='/path/to/certfile'` to specify a path to a `CA_BUNDLE` file or directory with certificates of trusted CAs. If you're using the certificates that Elasticsearch auto-generated then I believe it will have stored the CA root cert in `$ES_PATH_CONF/certs/http_ca.crt` in a format that should work as the right `CA_BUNDLE` file.

---

<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:** [April 2, 2023, 4:18pm UTC](https://discuss.elastic.co/t/whats-python-best-practice-for-security-certificates-with-es8/327009/3 "2023-04-02T16:18:01Z")

</div>

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