将证书安装到 Jupyter notebook docker 图片中
Installing certs into a Jupyter notebook docker image
在工作中,我们有一堆使用自签名证书的内部服务器。我正在尝试将这些证书安装到 Jupyter Notebook 映像中,以便它可以访问服务器,但由于某种原因找不到它们。这是一个最小的 Dockerfile:
FROM jupyter/datascience-notebook:notebook-6.4.2
USER root
RUN echo 'Acquire::http::proxy "http://proxy.internal.server";' >> /etc/apt/apt.conf.d/99proxy
ENV http_proxy http://proxy.internal.server
ENV https_proxy http://proxy.internal.server
ENV NO_PROXY internal.server
COPY certificates/* /usr/local/share/ca-certificates/
RUN update-ca-certificates
执行此操作后,当我尝试复制文件时,例如使用 curl -O https://internal.server/file
,它会失败并显示证书无效的消息。我必须添加 -k
标志以关闭 SSL 验证才能成功。
如果我按照相同的步骤但从原始 Ubuntu 图像开始,则没有问题。 (我必须安装 ca 证书和 curl。)
是否有关于 Jupyter 映像的问题干扰了证书存储?安装证书的正确步骤是什么?
原因是 Jupyter 镜像使用了 conda and conda is shipped with openssl and it's own CA certificates through the ca-certificates
包。
你可以在图片中看到它
python -c "import ssl; print(ssl.get_default_verify_paths())"
# DefaultVerifyPaths(cafile='/opt/conda/ssl/cert.pem', capath=None,
# openssl_cafile_env='SSL_CERT_FILE',
# openssl_cafile='/opt/conda/ssl/cert.pem',
# openssl_capath_env='SSL_CERT_DIR',
# openssl_capath='/opt/conda/ssl/certs')
我没有使用自定义 CA 证书的理想解决方案。您可以尝试使用各种环境变量。
export SSL_CERT_DIR=/etc/ssl/certs
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
万不得已,您可以尝试
- 将证书添加到conda ca文件
openssl x509 -in /path/to/custom/ca.crt -outform PEM >> $CONDA_PREFIX/ssl/cacert.pem
- 使用指向系统位置的符号链接覆盖 conda CA 文件。
但是,如果更新 ca-certificate
软件包,这些修复将失效。
在工作中,我们有一堆使用自签名证书的内部服务器。我正在尝试将这些证书安装到 Jupyter Notebook 映像中,以便它可以访问服务器,但由于某种原因找不到它们。这是一个最小的 Dockerfile:
FROM jupyter/datascience-notebook:notebook-6.4.2
USER root
RUN echo 'Acquire::http::proxy "http://proxy.internal.server";' >> /etc/apt/apt.conf.d/99proxy
ENV http_proxy http://proxy.internal.server
ENV https_proxy http://proxy.internal.server
ENV NO_PROXY internal.server
COPY certificates/* /usr/local/share/ca-certificates/
RUN update-ca-certificates
执行此操作后,当我尝试复制文件时,例如使用 curl -O https://internal.server/file
,它会失败并显示证书无效的消息。我必须添加 -k
标志以关闭 SSL 验证才能成功。
如果我按照相同的步骤但从原始 Ubuntu 图像开始,则没有问题。 (我必须安装 ca 证书和 curl。)
是否有关于 Jupyter 映像的问题干扰了证书存储?安装证书的正确步骤是什么?
原因是 Jupyter 镜像使用了 conda and conda is shipped with openssl and it's own CA certificates through the ca-certificates
包。
你可以在图片中看到它
python -c "import ssl; print(ssl.get_default_verify_paths())"
# DefaultVerifyPaths(cafile='/opt/conda/ssl/cert.pem', capath=None,
# openssl_cafile_env='SSL_CERT_FILE',
# openssl_cafile='/opt/conda/ssl/cert.pem',
# openssl_capath_env='SSL_CERT_DIR',
# openssl_capath='/opt/conda/ssl/certs')
我没有使用自定义 CA 证书的理想解决方案。您可以尝试使用各种环境变量。
export SSL_CERT_DIR=/etc/ssl/certs
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
万不得已,您可以尝试
- 将证书添加到conda ca文件
openssl x509 -in /path/to/custom/ca.crt -outform PEM >> $CONDA_PREFIX/ssl/cacert.pem
- 使用指向系统位置的符号链接覆盖 conda CA 文件。
但是,如果更新 ca-certificate
软件包,这些修复将失效。