【问题标题】:Remove / rebind SSL certificate from an Azure function using Azure SDK使用 Azure SDK 从 Azure 函数中删除/重新绑定 SSL 证书
【发布时间】:2018-08-27 07:07:34
【问题描述】:

我正在尝试自动化在我的 Azure 门户上获取 SSL 证书的过程。为此,我编写了一个 Azure 函数,该函数下载新证书,然后将其上传/绑定到我的 Web 应用程序。代码如下所示:

        app.Update()
            .DefineSslBinding()
                .ForHostname("*.my.domain")
                .WithPfxCertificateToUpload(Path.Combine(executionContext.FunctionDirectory, "cert.pfx"), "pwd")
                .WithSniBasedSsl()
                .Attach()
            .Apply();

应该上传一个新的证书并创建一个新的绑定。它在没有现有证书/绑定的网络应用程序上按预期工作,但如果我再次运行该函数,我会遇到一些问题:

  1. 新证书未出现在 Azure 门户中
  2. 绑定保持不变
  3. 如果我手动删除绑定并再次运行我的代码,它将使用我拥有的第一个证书创建相同的绑定,即再次变得相同
  4. 有趣的事情:我没有收到任何失败

经过一番研究,我发现如果我在 azure cli 中使用az webapp config ssl list 列出我的证书,则门户上的列表会更新,即所有证书都在那里。但这并没有多大帮助。

我的一般问题是:有没有其他方法可以重新绑定证书?

或者,一个明显的解决方法是提前删除现有绑定和证书:如何使用 .NET SDK 在 azure 函数中删除 SSL 证书?

【问题讨论】:

    标签: c# azure azure-functions azure-sdk-.net


    【解决方案1】:

    找到了路。应该分两步执行此操作:首先,上传证书

            var certificate = await azure.AppServices.AppServiceCertificates
                    .Define($"some-name")
                    .WithRegion(app.Region)
                    .WithExistingResourceGroup(app.ResourceGroupName)
                    .WithPfxByteArray(pfxBytes)
                    .WithPfxPassword("test")
                    .CreateAsync();
    

    然后使用WithExistingCertificate:

            await app.Update()
                .DefineSslBinding()
                    .ForHostname("*.my.domain")
                    .WithExistingCertificate(certificate.Thumbprint)
                    .WithSniBasedSsl()
                    .Attach()
                .ApplyAsync();
    

    有一个待处理的拉取请求,以便在单个调用中执行此操作https://github.com/Azure/azure-libraries-for-net/pull/208

    统一更新: PR 已合并,因此您可以简单地使用单个而不是 2 个调用:

    var certBytes = certificateService.RetreiveCertificate();
    webapp
        .Update()
        .DefineSslBinding()
        .ForHostname("my.hostname")
        .WithPfxByteArrayToUpload(certBytes, "password")
        .WithSniBasedSsl()
        .Attach()
        .Apply();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 1970-01-01
      相关资源
      最近更新 更多