如何在Docker容器中运行的Windows服务中访问本地计算机证书?

时间:2019-08-07 01:47:12

标签: azure docker windows-services

我在docker容器中运行的Windows服务中无法通过指纹找到证书。我是Docker的新手,如果有人能指出正确的方向,我将不胜感激。

确认要搜索的指纹正确。

我尝试将证书手动安装到容器中

    Import-PfxCertificate -FilePath C:\cert.pfx  -CertStoreLocation Cert:\LocalMachine\Root -Exportable -Password $Secure_String_Pwd

确认它已安装在正确的位置。

我尝试授予“每个人” FullControl访问私钥的权限。

这是Windows服务中试图找到证书的代码。我从certStore.Certificates.Find()函数得到的结果为0。在安装了相同证书的VM中运行时,这将返回一个结果。


    X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                certStore.Open(OpenFlags.ReadOnly);
    var certs = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, true);
    if (certs.Count == 0)
        throw new CryptographicException("Could not find requested certificate.");

DockerFile:

    FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.1-windowsservercore-ltsc2016

    COPY ["Services", "C:/Services"]
    COPY ["Cert.pfx", "C:/"]
    COPY ["AddUserToCert.ps1", "C:/"]

    RUN sc create NLPEngineService binpath= "c:/Services/Service.exe c:/Services/Service.exe.config" start= auto

Docker命令:

    docker build -t testservice-docker .\
    docker run -it testservice-docker cmd

0 个答案:

没有答案