IdentityServer4: How to load Signing Credential from Cert Store when in Docker

后端 未结 2 934
小鲜肉
小鲜肉 2021-02-05 23:25

We have an IdentityServer4-based STS successfully running on Windows, where the Signing Credential has been installed to the Local Computer with .pfx under Personal > Certifi

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 00:16

    When you use Docker containers and IdentityServer basically you have two options:

    • Add the certificate to the container image (COPY certificate.pfx .)
    • Mount certificate to the container (-v /path/to/certificate.pfx:/certificate.pfx)

    Whatever option you choose, the only thing you need is to add the following configuration code to ConfigureServices in Startup

    var identityServerBuilder = services.AddIdentityServer();
    /* store configuration and etc. is omitted */
    if (_hostingEnvironment.IsDevelopment())
    {
        identityServerBuilder.AddDeveloperSigningCredential();
    }
    else
    {
        var certificate = new X509Certificate2("certificate.pfx", "certificate_password");
        identityServerBuilder.AddSigningCredential(certificate);
    }
    

    Also it would be a good idea to read certificate password from configuration, environment variable or secrets storage.

提交回复
热议问题