gpt4 book ai didi

docker - 如何将受信任的根 CA 添加到 Docker alpine

转载 作者:行者123 更新时间:2023-12-04 22:34:23 26 4
gpt4 key购买 nike

假设我在有 MITM SSL 交换防火墙的网络(google.com 不是由 Google 发布,而是由自定义 CA 根权限重新发布)这里有更多详细信息 https://security.stackexchange.com/questions/107542/is-it-common-practice-for-companies-to-mitm-https-traffic .
我有简单的 Dockerfile:

FROM alpine:latest
RUN apk --no-cache add curl
它因 SSL 错误而严重失败
 => ERROR [2/2] RUN apk --no-cache add curl                                                                                                                                    1.0s
------
> [2/2] RUN apk --no-cache add curl:
#5 0.265 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
#5 0.647 140037857143624:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1913:
#5 0.649 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/main: Permission denied
#5 0.649 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
#5 0.938 140037857143624:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1913:
#5 0.940 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/community: Permission denied
#5 0.941 ERROR: unable to select packages:
#5 0.942 curl (no such package):
#5 0.942 required by: world[curl]
------
executor failed running [/bin/sh -c apk --no-cache add curl]: exit code: 1
Internet 上的每个教程都说我可以添加自己的“受信任”根证书并运行 update-ca-certificates .
但只能通过“apt add”添加。这种情况在我看来是“鸡蛋问题”。
FROM alpine:latest
USER root
RUN apk --no-cache add ca-certificates \
&& update-ca-certificates
错误类似
=> ERROR [2/2] RUN apk --no-cache add ca-certificates   && update-ca-certificates                                                                                             1.0s
------
> [2/2] RUN apk --no-cache add ca-certificates && update-ca-certificates:
#5 0.269 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
#5 0.662 140490932583240:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1913:
#5 0.663 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
#5 0.663 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/main: Permission denied
#5 0.929 140490932583240:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1913:
#5 0.931 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/community: Permission denied
#5 0.932 ERROR: unable to select packages:
#5 0.933 ca-certificates (no such package):
#5 0.933 required by: world[ca-certificates]
------
executor failed running [/bin/sh -c apk --no-cache add ca-certificates && update-ca-certificates]: exit code: 1
是否有其他解决方案如何安装 update-ca-certificates工具?还是我错过了什么?
谢谢
有关工作解决方案,请参阅@kthompso 答案。
基于@kthompso 答案和来自 unable to add certificates to alpine linux container 的信息的工作解决方案(带有 update-ca-certificates commnad)
FROM alpine:latest

USER root

# To be able to download `ca-certificates` with `apk add` command
COPY my-root-ca.crt /root/my-root-ca.crt
RUN cat /root/my-root-ca.crt >> /etc/ssl/certs/ca-certificates.crt

# Add again root CA with `update-ca-certificates` tool
RUN apk --no-cache add ca-certificates \
&& rm -rf /var/cache/apk/*
COPY my-root-ca.crt /usr/local/share/ca-certificates
RUN update-ca-certificates

RUN apk --no-cache add curl
编辑:我想到的一种解决方案是将 curl docker 图像与 -k 一起使用选项和下载 .apk使用这些证书和工具。将其安装为本地文件。添加我的根 CA 证书并运行 update-ca-certificates .听起来 super 疯狂,所以我认为这必须是更好的解决方案:)

最佳答案

将您的自签名证书附加到 /etc/ssl/certs/ca-certificates.crt手动。
假设您在构建目录中名为 my-cert.pem 的文件中拥有自签名证书。 :

FROM alpine:latest

COPY my-cert.pem /usr/local/share/ca-certificates/my-cert.crt

RUN cat /usr/local/share/ca-certificates/my-cert.crt >> /etc/ssl/certs/ca-certificates.crt && \
apk --no-cache add \
curl
注:当您使用 update-ca-certificates ,您需要将您的证书文件放入 /usr/local/share/ca-certificates/第一的。

关于docker - 如何将受信任的根 CA 添加到 Docker alpine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67231714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com