【发布时间】:2020-09-09 16:33:25
【问题描述】:
我正在尝试使用SSL 从python 连接到Elasticsearch,并使用基本代码:
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'))
来自:https://github.com/elastic/elasticsearch-py
我需要提供cafile.pem 和http_auth 参数。在我的python 运行的服务器上,SSL 连接已经建立,所以我可以对Elasticsearch 进行基本查询。它是使用~/.ssh 目录中的密钥设置的:id_rsa、id_rsa.pub。所以,现在我想知道是否应该提供id_rsa.pub 密钥来代替path/to/cafile.pem,如果是,那么我需要更改~/.ssh 文件夹的权限,从安全角度来看这似乎不是一个好主意。那么,我不确定.pub是否与.pem相同,需要先转换吗?那么,http_auth 是否也应该被省略,因为我在终端中进行简单查询时不使用任何密码?我应该如何根据最佳实践解决这个问题(在 python 中设置对ES 和SSL 的访问) - 这就是问题所在。
更新
我尝试了.pub 并从中生成了pem:
https://serverfault.com/questions/706336/how-to-get-a-pem-file-from-ssh-key-pair
但两者都未能在context.load_verify_locations(cafile, capath, cadata) 中使用unknown error create_default_context。
【问题讨论】:
-
您错过了这些东西,
id_rsa、id_rsa.pub是您的 ssh 密钥,您的用户使用它来连接到您的服务器而无需提供密码,以便与 elasticsearch 建立安全连接使用 SSL 您需要在集群中配置它并使用在configuration process 期间生成的证书。 -
您可以使用search-guard.com在集群中配置 SSL
标签: python elasticsearch ssl