【问题标题】:Connect to Elasticsearch with python using SSL使用 SSL 使用 python 连接到 Elasticsearch
【发布时间】:2020-09-09 16:33:25
【问题描述】:

我正在尝试使用SSLpython 连接到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.pemhttp_auth 参数。在我的python 运行的服务器上,SSL 连接已经建立,所以我可以对Elasticsearch 进行基本查询。它是使用~/.ssh 目录中的密钥设置的:id_rsaid_rsa.pub。所以,现在我想知道是否应该提供id_rsa.pub 密钥来代替path/to/cafile.pem,如果是,那么我需要更改~/.ssh 文件夹的权限,从安全角度来看这似乎不是一个好主意。那么,我不确定.pub是否与.pem相同,需要先转换吗?那么,http_auth 是否也应该被省略,因为我在终端中进行简单查询时不使用任何密码?我应该如何根据最佳实践解决这个问题(在 python 中设置对ESSSL 的访问) - 这就是问题所在。

更新

我尝试了.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_rsaid_rsa.pub 是您的 ssh 密钥,您的用户使用它来连接到您的服务器而无需提供密码,以便与 elasticsearch 建立安全连接使用 SSL 您需要在集群中配置它并使用在configuration process 期间生成的证书。
  • 您可以使用search-guard.com在集群中配置 SSL

标签: python elasticsearch ssl


【解决方案1】:

我的具体案例的答案非常简单。我在这里找到了它:

https://elasticsearch-py.readthedocs.io/en/master/

es = Elasticsearch(['https://user:secret@localhost:443'])

刚刚在里面指定了httpsurl,它马上就解决了。

【讨论】:

  • 谢谢,这很简单,但在 Elasticsearch 中从 HTTP 切换到 HTTPS 时很有帮助。
猜你喜欢
  • 2020-02-11
  • 2021-05-24
  • 1970-01-01
  • 2016-11-26
  • 2012-10-03
  • 1970-01-01
  • 1970-01-01
  • 2019-06-30
  • 2016-12-24
相关资源
最近更新 更多