python-3.x - pip install with cert 工作,但全局配置文件中的引用证书失败
问题描述
我在公司网络后面,目前可以Python
通过两种方式安装包Dockerfile
。
(1) 参考证书
RUN pip3 install --cert=/usr/local/share/ca-certificates/zscaler-root.crt <SOME-PYTHON-PACKAGE>
(2) 通过将 repos/URLs 添加到受信任的主机
RUN touch /etc/pip.conf
RUN echo "[global] \n trusted-host = pypi.python.org pypi.org files.pythonhosted.org" >> /etc/pip.conf
RUN pip3 install <SOME-PYTHON-PACKAGE>
而不是选项#2,我宁愿在全球范围内设置证书。
RUN touch /etc/pip.conf
RUN echo "[global] \n cert=/usr/local/share/ca-certificates/zscaler-root.crt" >> /etc/pip.conf
但这不起作用。
导致 SSLError(SSLCertVerificationError.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)'))': /simple/flask/
为什么选项 #1 可以引用证书但将其添加到全局配置文件失败?
编辑:
根据@phd 的建议,尝试了以下方法。
RUN pip3 config --global set global.cert /usr/local/share/ca-certificates/zscaler-root.crt
RUN pip3 config set global.cert /usr/local/share/ca-certificates/zscaler-root.crt
但没有喜悦。
还尝试SSL_CERT_DIR
按照https://stackoverflow.com/a/24353642/6265370进行设置。
ENV SSL_CERT_DIR="/usr/local/share/ca-certificates/"
再次没有雪茄。
这里有更多信息
pip 21.1.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
pip3 config list -v
For variant 'global', will try loading '/etc/xdg/pip/pip.conf'
For variant 'global', will try loading '/etc/pip.conf'
For variant 'user', will try loading '/root/.pip/pip.conf'
For variant 'user', will try loading '/root/.config/pip/pip.conf'
For variant 'site', will try loading '/usr/local/pip.conf'
解决方案
最好在系统范围内安装 ZScaler 证书,而不是限制使用 pip。在 openssl 上的 Linx 发行版中继。首先检查openssl版本和certs目录:
openssl version -d
你会得到类似的东西:
OPENSSLDIR: "/usr/lib/ssl"
然后将证书复制到其中的 certs 目录中。
在这种情况下,它将是:
/usr/lib/ssl/certs
或者,您可以通过 ca trust authority 来完成。在 Ubuntu 中:
sudo mkdir /usr/local/share/ca-certificates/zscaler
sudo cp <certfile.crt> /usr/local/share/ca-certificates/zscaler/
sudo chmod 755 /usr/local/share/ca-certificates/zscaler/
sudo chmod 644 /usr/local/share/ca-certificates/zscaler/<certfile.crt>
sudo update-ca-certificates
推荐阅读
- python-3.x - 将单列内容分成多列?
- javascript - data-id 单击时向下滚动到项目
- ios - Apple 应用程序站点关联不适用于 AWS CloudFront 和 S3
- shell - 将非 PNG 图像复制到 X 剪贴板
- android - 底部溢出 164 像素,在尝试修复热重新加载后,出现未实现的丢失静态目标的处理
- string - 如何在kotlin中将字符串转换为实体
- mysql - 如何将数据表列名称和值重命名为从 infyom laravel 生成器生成的岛名称?
- c++ - CUDA 的性能取决于声明变量
- php - 如何在不刷新页面的情况下将文本和图像文件数据同时发送到 MySQL 数据库
- python-2.7 - 让谷歌计算引擎实例以 64 位运行 Python 2.7.xx?