【问题标题】:Does PyNetBox API have an option to verify CA cert for Self Signed Cert?PyNetBox API 是否可以选择验证自签名证书的 CA 证书?
【发布时间】:2020-10-27 14:14:09
【问题描述】:

我一直在尝试使用具有自签名证书的 NetBox 设置的 NetBox Ansible 模块。 [1] 然而,这给了我错误:

无法建立与 Netbox API 的连接

我意识到这是因为我使用了自签名证书:

>>> import pynetbox
>>> nb = pynetbox.api(
... 'https://netbox.url',
... token='XXX'
... )
 
>>> nb.dcim.devices.all()
 
<snipped>
 
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='netbox.url', port=443): Max retries exceeded with url: /api/dcim/devices/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

我想知道是否有办法使用 pynetbox 指定 cacert 文件,就像我们使用 verify="/my/path/to/cacert.crt" 处理请求一样

>>> nb = pynetbox.api(
... 'https://netbox.url',
... token='XXX',
... private_key_file='/my/path/to/key',
... ssl_verify='/my/path/to/cacert.crt'
... )
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
TypeError: __init__() got an unexpected keyword argument 'ssl_verify'

[1]Using Netbox Ansible Modules

Python 版本:Python 3.7.7 pynetbox 版本:'2.8'

【问题讨论】:

  • 这将有助于编辑问题以添加您正在使用的 python / pynetbox 版本。
  • @Baptiste Mille-Mathias 谢谢,已添加。

标签: ansible python-requests self-signed-certificate


【解决方案1】:

这在an issue in their GitHub repo 中进行了讨论,他们声称可以将REQUESTS_CA_BUNDLE 环境变量设置为指向requests 应该用于验证端点(here are the requests docs) 的CA 包

理论上:

import pynetbox
import os

os.environ['REQUESTS_CA_BUNDLE'] = '/path/to/your/ca.pem'
# and off to the races

【讨论】:

【解决方案2】:

您可以像这样禁用 ssl 验证:

nb.http_session.verify = False

这里的文档中提到了https://buildmedia.readthedocs.org/media/pdf/pynetbox/latest/pynetbox.pdf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    • 2012-07-20
    • 2016-07-08
    • 2016-01-22
    • 2016-11-03
    • 2020-07-30
    相关资源
    最近更新 更多