我正在Win10机器中使用LINUX容器运行dotnet core 2.1,并且 我使用openssl创建了一个自签名CA,并安装在docker计算机中。 Docker输出显示已经添加了CA。
当我运行以下命令时,它还会向我显示已安装的证书
awk -v cmd='openssl x509 -noout -subject' '/BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-certificates.crt
但是,无法通过X509Store访问已安装的证书
下面的代码显示计数:0
using (var store = new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadOnly);
Console.WriteLine($"LocalMachine-> CertificateAuthority-> Count: {store.Certificates.Count}");
foreach (var cert in store.Certificates)
{
Console.WriteLine($"cert: {cert}");
}
}
下面的代码显示计数:151
using (var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadOnly);
Console.WriteLine($"LocalMachine-> Root-> Count: {store.Certificates.Count}");
foreach (var cert in store.Certificates)
{
Console.WriteLine($"cert: {cert.IssuerName.Name}");
}
}
但是我认为应该是152。
这是我的docker文件
FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY TestWebApp1/TestWebApp1.csproj TestWebApp1/
RUN dotnet restore TestWebApp1/TestWebApp1.csproj
COPY . .
WORKDIR /src/TestWebApp1
RUN dotnet build TestWebApp1.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish TestWebApp1.csproj -c Release -o /app
RUN ls -l
RUN ls certificate/
COPY TestWebApp1/certificate/ca.crt /usr/share/ca-certificates/ca.crt
RUN echo ca.crt >> /etc/ca-certificates.conf
RUN ls /usr/local/share/ca-certificates/
RUN dpkg-reconfigure -p critical ca-certificates
RUN update-ca-certificates
RUN awk -v cmd='openssl x509 -noout -subject' '/BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-certificates.crt
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TestWebApp1.dll"]
任何帮助将不胜感激。
谢谢。
答案 0 :(得分:2)
这似乎归因于多阶段Dockerfile。
您已将证书安装在publish
映像中,但未安装在final
映像中。另外,base
不包括新安装的证书。
我建议
publish
图像复制到final
图像dpkg-reconfigure ... update-ca-certificates
阶段执行final
base
映像中我的偏好是选项1。