你在正确的轨道上。自定义部署脚本应该可以做到这一点:
http://blog.amitapple.com/post/38417491924/azurewebsitecustomdeploymentpart1
https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script
在 Kudu 中,您不会安装 Azure PowerShell,因此您必须通过 REST 从 Key Vault 中提取您的证书。
更新:Azure Functions 确实安装了 Azure RM cmdlet。您可以在 PowerShell 中编写一个从 Key Vault 提取证书的函数应用程序。使用 Service Principal 到 Login-AzureRmAccount 无人值守。
完成此操作所需的秘密应保存在应用程序设置中。它们在 Kudu 中作为环境变量暴露给您:https://azure.microsoft.com/en-gb/documentation/articles/web-sites-configure/
应用设置
此部分包含您的网络应用程序将在启动时加载的名称/值对。
对于 .NET 应用,这些设置会在运行时注入到您的 .NET 配置 AppSettings 中,覆盖现有设置。
PHP、Python、Java 和 Node 应用程序可以在运行时将这些设置作为环境变量访问。对于每个应用程序设置,都会创建两个环境变量;一个具有应用程序设置条目指定的名称,另一个具有 APPSETTING_ 前缀。两者都包含相同的值。
或者,您可以从应用服务商店(“我的”商店)中提取证书。方法如下:
来自https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/:
添加一个名为 WEBSITE_LOAD_CERTIFICATES 的应用设置,并将其值设置为证书的指纹,这样您的 Web 应用程序就可以访问它。您可以有多个以逗号分隔的指纹值,也可以将此值设置为 *,在这种情况下,您的所有证书都将加载到您的 Web 应用程序个人证书存储中。
using System;
using System.Security.Cryptography.X509Certificates;
namespace UseCertificateInAzureWebsiteApp
{
class Program
{
static void Main(string[] args)
{
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
// Replace below with your cert's thumbprint
“E661583E8FABEF4C0BEF694CBC41C28FB81CD870”,
false);
// Get the first cert with the thumbprint
if (certCollection.Count > 0)
{
X509Certificate2 cert = certCollection[0];
// Use certificate
Console.WriteLine(cert.FriendlyName);
}
certStore.Close();
}
}
}
没有为您完成证书验证。您需要通过与应用设置或 Key Vault 中存储的值进行比较来自行实现。