X509Chain构建在具有Istio的Azure Kubernetes群集中的Alpine linux容器上失败

问题描述

我有一个正在使用X509Chain(chain.Build(certificate))进行验证的证书。该证书具有一个中间CA X和一个根Y,这两个证书当前都安装在我正在测试的Windows计算机上。

在我的Windows机器上,chain.Build()成功(假定因为这两个CA都在我的机器上),但是相同的验证代码未能验证我的linux容器上的证书。

这是我的dockerfile的样子:

# pull down the build container
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine3.10

workdir /app

# expose ports
EXPOSE 443
EXPOSE 80

# Install cultures (same approach as Alpine SDK image)
RUN apk add --no-cache icu-libs

# disable the invariant mode (set in base image)
ENV DOTNET_SYstem_GLOBALIZATION_INVARIANT=false

# copy build output
copY . /app

copY ./Configuration/X.cer /usr/share/ca-certificates/X.crt
copY ./Configuration/Y.cer /usr/share/ca-certificates/Y.crt

RUN echo "X.crt" >> /etc/ca-certificates.conf
RUN echo "Y.crt" >> /etc/ca-certificates.conf

RUN update-ca-certificates

# start the service
ENTRYPOINT ["dotnet","ValidationService.dll"]

我已经从我的机器中导出了base64编码的X509证书,并使用该证书复制到/ usr / share / ca-certificates /。 我手动输入etc文件夹中的ca-certificates.conf文件,然后运行update-ca-certificates。 部署后,我在容器的conf文件以及ssl文件夹中看到正确的条目,并在其中添加了我的证书。但是我的验证仍然失败。

不确定在这里是否缺少任何步骤?请指教。

解决方法

我在您的Dockerfile中看到了几个问题。

  1. 尝试使用OpenSSL将证书转换为CRT格式:
openssl x509 -inform DER -in certificate.cer -out certificate.crt
  1. 将证书复制到/usr/local/share/ca-certificates/路径