我已经为内部项目设置了一个内部pypi服务器。
它被托管在https://<USER>:<PASS>@<INTERAL>/pypi
和一个自签名证书。
除了在~/.pip/pip.conf
中使用extra-index-url
的中央pypi服务器外,我还可以让pip使用这个存储库。由于我的服务器的证书是自签名的,并且pip没有使用系统范围的(钥匙链)证书,因此我在配置文件中使用cert = ...
使其意识到这一点:
extra-index-url = https://<USER>:<PASS>@<INTERAL>/pypi
cert = /path/to/cert.pem
现在,每当我使用pip install
安装一些东西时,我都会得到一个警告,即无法为https://pypi.python.org
验证证书:
$ pip install <PACKAGE-NAME>
Collecting <PACKAGE-NAME>
Could not fetch URL https://pypi.python.org/simple/<PACKAGE-NAME>/:
There was a problem confirming the ssl certificate: [SSL:
CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) -
skipping
是否有任何方法可以告诉pip只使用自签名证书仅用于extra-index-url存储库?
Pip使用它的证书包(一个文件),可以通过以下命令找到:
python -m pip._vendor.requests.certs
这个包就是一个文件,一个接一个地把证书连接起来。我们想告诉pip使用这些和我们的证书,因此,使用
生成一个新文件cat $(python -m pip._vendor.requests.certs) /path/to/my/cert.pem > /path/to/my/bundle.pem
并确保您的.pip/pip.conf
文件包含以下内容:
[global]
extra-index-url = https://user:pass@my-pypi.com
cert = /path/to/my/bundle.pem
最后,您可能希望定期更新/path/to/my/bundle.pem
(在cronjob或其他)。
其他备注
我也得到了以下错误:
SubjectAltNameWarning: Certificate for my-pypi.com has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
通常,您将创建如下证书:
openssl req -new -x509 -nodes -key my.key -out cert.csr -days 365
相反,将您的openssl.cnf
(可能在/etc/pki/tls/openssl.cnf
中)复制到您的工作目录,并通过在文件末尾添加以下内容来添加扩展名:
[ san_env ]
subjectAltName=DNS:mypypi.com
并使用
生成证书openssl req -new -x509 -nodes -key my.key -out cert.csr -days 365 -config openssl.cnf -extensions san_env
此外,pip希望您的证书采用不同的格式,该格式可以使用
生成openssl x509 -inform der -in cert.cer -out cert.pem
这个文件cert.pem
可以与上面描述的python ca bundle连接,以生成您的自定义bundle。