为什么我在Docker(Mac)上安装软件包时会出现SSL错误?

b91juud3  于 2022-12-22  发布在  Docker
关注(0)|答案(3)|浏览(296)

我正在MacOS上通过Docker Desktop运行Docker,在我的容器中安装包时遇到了很多麻烦,因为它无法验证任何SSL证书。
例如,当我运行apk update时,我得到这个错误:

fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
139797308250952:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1914:
ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.14/main: Permission denied

当我尝试bundle install时:

Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification.

甚至一个简单的旋度curl https://google.com.br

curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
  • 最新情况 *

即使我在容器中安装了ca证书(如@β. ε η ο ι τ. β ε所述),我仍然得到相同的错误SSL certificate problem: unable to get local issuer certificate
将此行添加到Dockerfile,如@β. ε η ο ι τ. β ε所述:

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.15/main ca-certificates curl
tv6aics1

tv6aics11#

结果是β.εηοιτ.βε答案很好,但我毕竟没有解决问题所需的所有信息。
我不得不使用openssl调用来跟踪ca证书链,命令如下:

openssl s_client -connect google.com:443

它返回给我这个:

CONNECTED(00000003)
depth=2 C = US, ST = California, O = Zscaler Inc., OU = Zscaler Inc., CN = Zscaler Intermediate Root CA (zscalertwo.net), emailAddress = support@zscaler.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=1 C = US, ST = California, O = Zscaler Inc., OU = Zscaler Inc., CN = "Zscaler Intermediate Root CA (zscalertwo.net) (t) "
verify return:1
depth=0 CN = *.google.com
verify return:1
---

有了这个,就可以看出它试图找到这个Zscaler证书,而不是谷歌证书。我发现这是我们公司用来监视流量的拦截器。有了这个,我能够找到这个post,它导致这个doc,在那里它解释了如何在mac环境中添加证书到docker。
因此,解决方案是将证书添加到系统:

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain <CERTIFICATE>

并将证书添加到docker并安装ca证书,如β.εη ιτ.βε所述:

ADD ./ZscalerRootCertificate.crt /usr/local/share/ca-certificates/
RUN apk add --no-cache \
    --repository http://dl-cdn.alpinelinux.org/alpine/v3.15/main \
    ca-certificates
RUN update-ca-certificates
hpxqektj

hpxqektj2#

这不是Mac相关的问题,您只是缺少容器中的根证书。
为了安装它们,您需要获取Alpine软件包库的http版本,否则在获取此软件包时也会遇到SSL问题:

RUN apk add \
      --no-cache \
      --repository http://dl-cdn.alpinelinux.org/alpine/v3.14/main \
      ca-certificates

从那里,你应该能够安装包再次正常.

agyaoht7

agyaoht73#

我在Alpine和Docker的构建中也遇到了类似的问题。尝试断开VPN或任何互联网安全软件。它会解决这个问题。

相关问题