将根 CA 添加到 Azure 应用服务以进行客户端证书身份验证

Add Root CA to Azure App Service for Client Certificate Authentication

我正在构建一个依赖客户端证书进行身份验证的网络应用程序。尽管我必须将客户端证书的根 CA 添加到证书存储区,但我已经能够通过 IIS 在 Windows VM 上成功获得它 运行。

当我想将同一个应用程序部署到 Azure 应用程序服务时,我似乎找不到执行类似操作的地方。我错过了什么?

谢谢!

Unfortunately, it is not possible to add Root certificates to an App Service.

更详细的可以参考本post的回答。

Adding trust to root certificate store on an App Service

cannot install custom root certificates for the App Service,但这不是必须的。

Azure Web App 前端不进行任何证书验证。验证仅由用户代码处理。在 Asp.Net Core 中,您通常将验证卸载到 Microsoft.AspNetCore.Authentication.Certificate,它支持自定义证书。

Asp.Net核心5

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseAuthentication();
    
    // other items omitted
}

public void ConfigureServices(IServiceCollection services)
{
    services
        .AddAuthentication()
        .AddCertificate(options =>
        {
            options.ChainTrustValidationMode = X509ChainTrustMode.CustomRootTrust;
            options.CustomTrustStore = new X509Certificate2Collection(
                new[]
                {
                    new X509Certificate2(Convert.FromBase64String(myRootCertificate)),
                });
        })
        
        // other items omitted
}

请注意,使用此设置 支持自定义根证书。所有默认的操作系统根证书都将被忽略。

Asp.Net 核心 6

PR 29828介绍了一种添加链证书的方法:

public class CertificateAuthenticationOptions : AuthenticationSchemeOptions
{

   /// <summary>
   /// Collection of X509 certificates which are added to the X509Chain.ChainPolicy.ExtraStore of the certificate chain.
   /// </summary>
   public X509Certificate2Collection AdditionalChainCertificates { get; set; } = new X509Certificate2Collection();

}

除了操作系统支持的证书之外,还将使用这些证书 - 在本例中为 Azure Web App。