代码之家  ›  专栏  ›  技术社区  ›  Nikita Vlasenko

使用SSL通过python连接到Elasticsearch

  •  0
  • Nikita Vlasenko  · 技术社区  · 4 年前

    Elasticsearch python 具有 SSL 使用基本代码:

    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连接已经设置好,所以我可以对 弹性搜索 . 它是用钥匙设置的 ~/.ssh id_rsa id_rsa.pub 身份证_rsa.pub公司 钥匙代替 path/to/cafile.pem ~/.ssh文件 从安全角度看,这似乎不是一个好主意。那么,我不确定 .pub 与相同 .pem ,需要先转换吗?那么,也应该 http\U身份验证 ES 具有 )根据最佳实践-这就是问题所在。

    更新

    我两个都试过了 并由此产生 pem

    https://serverfault.com/questions/706336/how-to-get-a-pem-file-from-ssh-key-pair

    但两人都失败了 create_default_context 带着一个 unknown error context.load_verify_locations(cafile, capath, cadata) .

    0 回复  |  直到 4 年前
        1
  •  1
  •   Nikita Vlasenko    4 年前

    我的特殊情况的答案很简单。我在这里找到的:

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

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

    刚刚指定的 https url