使用Azure SDK从Azure功能中删除/重新绑定SSL证书

问题描述 投票:0回答:1

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

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

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

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

经过一些研究,我发现如果我用az webapp config ssl list在天蓝色的cli中列出我的证书,门户网站上的列表就会更新,即所有的证书都在那里。但这没有多大帮助。

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

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

c# azure azure-functions azure-sdk-.net
1个回答
0
投票

找到了方法。应该分两步完成:首先,上传证书

        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中执行此操作

© www.soinside.com 2019 - 2024. All rights reserved.