【问题标题】:Signing binaries while deploying automatically to Azure App Service from github在从 github 自动部署到 Azure 应用服务时签署二进制文件
【发布时间】:2016-08-28 19:40:07
【问题描述】:

我想在通过 github 部署到 Azure 应用服务时签署我的二进制文件(使用下面的 Kudu)。我知道我可以运行自定义脚本来构建项目。也许我可以在构建过程中使用这种方法对二进制文件进行签名并部署签名位?我想我可以将我的证书放在 Azure Key Vault 中。如何在不将任何秘密签入 github 的情况下访问它?

有人有这方面的经验吗?

【问题讨论】:

    标签: azure azure-web-app-service kudu


    【解决方案1】:

    你在正确的轨道上。自定义部署脚本应该可以做到这一点:
    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 PrincipalLogin-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 中存储的值进行比较来自行实现。

    【讨论】:

      猜你喜欢
      • 2020-07-30
      • 2016-12-05
      • 2011-11-10
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 2021-03-09
      • 2020-05-18
      相关资源
      最近更新 更多