I am trying to connect to Elasticsearch from python with SSL and using the basic code for that:
from elasticsearch import Elasticsearch
from ssl import create_default_context
context = create_default_context(cafile="path/to/cafile.pem")
es = Elasticsearch("https://elasticsearch.url:port", ssl_context=context, http_auth=('elastic','yourpassword'))
from: https://github.com/elastic/elasticsearch-py
I need to supply cafile.pem, and http_auth parameters. On the server where my python is running SSL connection is already set up, so I can do basic queries to Elasticsearch. It was set up using keys in ~/.ssh directory: id_rsa, id_rsa.pub. So, now I am wondering whether I should supply id_rsa.pub key in place of path/to/cafile.pem, and if yes, then I would need to change permissions of ~/.ssh folder which seems like not a good idea from security perspective. Then, I am not sure that .pub is the same as .pem, do I need to convert it first? Then, also should http_auth just be omitted since I do not use any password when I do simple queries in terminal? How should I go about this issue (setting up access in python to ES with SSL) according to best practices - thats the question.
Update
I tried both .pub and generated from it pem:
https://serverfault.com/questions/706336/how-to-get-a-pem-file-from-ssh-key-pair
But both failed to create_default_context with an unknown error in context.load_verify_locations(cafile, capath, cadata).