【问题标题】:Hashicorp python client hvac issue:- "bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed'Hashicorp python客户端hvac问题:-“握手错误:错误([('SSL例程','tls_process_server_certificate','证书验证失败'
【发布时间】:2018-10-17 11:09:08
【问题描述】:

我正在为我的 Hashicorp 服务器使用以下 config.hcl,

disable_mlock = true

storage "file" {
  path = "/etc/secrets"
}

listener "tcp" {
 address     = "10.xx.xx.xx:8200"
 tls_cert_file = "/etc/certs/selfsigned.crt"
 tls_key_file  = "/etc/certs/selfsigned.key"
}

当我执行保管库操作时,它工作正常, 但是当我尝试使用 hvac python 库访问它时,我收到了 SSL 错误。 我用来从 python 连接到 hashcorp 服务器的代码是,

import hvac
client = hvac.Client(url='https://10.xx.xx.xx:8200', cert=('/etc/certs/selfsigned.crt', '/etc/certs/selfsigned.key'))
client.token = 'd460cb82-08aa-4b97-8655-19b6593b262d'
client.is_authenticated() 

我得到的完整错误跟踪如下:-

Traceback(最近一次调用最后一次):文件“”,第 1 行 , 在 文件 “/usr/local/lib/python2.7/dist-packages/hvac/v1/init.py”,行 第552章 self.lookup_token() 文件“/usr/local/lib/python2.7/dist-packages/hvac/v1/init.py”,行 460,在lookup_token中 return self._get('/v1/auth/token/lookup-self', wrap_ttl=wrap_ttl).json() 文件 “/usr/local/lib/python2.7/dist-packages/hvac/v1/init.py”,行 第1236章 return self.request('get', url, **kwargs) 文件“/usr/local/lib/python2.7/dist-packages/hvac/v1/__init.py”,行 第1264章 allow_redirects=False, **_kwargs) 文件“/usr/local/lib/python2.7/dist-packages/requests/sessions.py”,行 512,请求中 resp = self.send(prep, **send_kwargs) 文件“/usr/local/lib/python2.7/dist-packages/requests/sessions.py”,行 622,在发送中 r = adapter.send(request, **kwargs) 文件“/usr/local/lib/python2.7/dist-packages/requests/adapters.py”,行 511,在发送中 引发 SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='10.xx.xx.xx', port=8200): Max retries 超出 url:/v1/auth/token/lookup-self(由 SSLError(SSLError("错误的握手:错误([('SSL 例程', 'tls_process_server_certificate', '证书验证 失败')],)",),))

【问题讨论】:

    标签: python ssl tls1.2 hashicorp-vault


    【解决方案1】:

    根据hvac文档Using TLS with client-side certificate authentication,需要指定verify=server_cert_path参数。

    测试如下,我可以得到预期的结果。顺便说一句,不管有没有token 参数,它都可以成功运行。

    import hvac
    
    client = hvac.Client(url='https://127.0.0.1:8200',
                         token='xxxxxxxx',
                         cert=('server.crt',
                               'server.key'),
                         verify='ca.crt')
    
    res = client.is_authenticated()
    print("res:", res)
    

    【讨论】:

      猜你喜欢
      • 2019-04-08
      • 2018-12-21
      • 2019-12-12
      • 2021-09-04
      • 1970-01-01
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多