将上传到 Azure 门户的 TLS 证书加载到 Linux 应用服务容器中
Loading a TLS certificate uploaded to the Azure portal into a Linux app service container
一段时间以来,我们在 Azure 应用服务上有一个 ASP.NET 核心网络应用程序 运行。作为升级到 netcoreapp2.2 的一部分,我们决定将其 Dockerize 并 运行 在 Linux 容器中,仍然在应用程序服务中。
此应用程序所做的一件事是加载 TLS 证书以进行令牌签名。以前,此证书已上传到应用程序服务,应用程序将通过 new X509Store(StoreName.My, StoreLocation.CurrentUser)
中的指纹找到它。这可以通过添加配置设置 WEBSITE_LOAD_CERTIFICATES
并将值设置为证书的指纹来启用。
对 Linux 容器尝试了相同的方法后,我们发现证书存储区中不存在该证书。
我从今年早些时候发现 this issue on Github,这表明在 Linux 上是不可能的。现在还是这样吗?如果是这样,有人知道不涉及将证书本身存储在图像中的变通方法吗?
该功能现在适用于 Linux。
Load certificate in Linux apps
The WEBSITE_LOAD_CERTIFICATES app settings makes the specified certificates accessible to your Linux hosted apps (including custom container apps) as files. The files are found under the following directories:
- Private certificates - /var/ssl/private ( .p12 files)
- Public certificates - /var/ssl/certs ( .der files)
The certificate file names are the certificate thumbprints. The following C# code shows how to load a public certificate in a Linux app.
using System;
using System.Security.Cryptography.X509Certificates;
var bytes = System.IO.File.ReadAllBytes("/var/ssl/certs/<thumbprint>.der");
var cert = new X509Certificate2(bytes);
一段时间以来,我们在 Azure 应用服务上有一个 ASP.NET 核心网络应用程序 运行。作为升级到 netcoreapp2.2 的一部分,我们决定将其 Dockerize 并 运行 在 Linux 容器中,仍然在应用程序服务中。
此应用程序所做的一件事是加载 TLS 证书以进行令牌签名。以前,此证书已上传到应用程序服务,应用程序将通过 new X509Store(StoreName.My, StoreLocation.CurrentUser)
中的指纹找到它。这可以通过添加配置设置 WEBSITE_LOAD_CERTIFICATES
并将值设置为证书的指纹来启用。
对 Linux 容器尝试了相同的方法后,我们发现证书存储区中不存在该证书。
我从今年早些时候发现 this issue on Github,这表明在 Linux 上是不可能的。现在还是这样吗?如果是这样,有人知道不涉及将证书本身存储在图像中的变通方法吗?
该功能现在适用于 Linux。
Load certificate in Linux apps
The WEBSITE_LOAD_CERTIFICATES app settings makes the specified certificates accessible to your Linux hosted apps (including custom container apps) as files. The files are found under the following directories:
- Private certificates - /var/ssl/private ( .p12 files)
- Public certificates - /var/ssl/certs ( .der files)
The certificate file names are the certificate thumbprints. The following C# code shows how to load a public certificate in a Linux app.
using System; using System.Security.Cryptography.X509Certificates; var bytes = System.IO.File.ReadAllBytes("/var/ssl/certs/<thumbprint>.der"); var cert = new X509Certificate2(bytes);