【发布时间】:2019-10-02 09:59:19
【问题描述】:
我正在从 ARM 模板迁移到 C# Azure SDK 部署选项,并且在将现有证书的使用转换为新资源组时遇到问题。 我将 SSL 证书存储到特定的资源组和 Keyvault 中。 我有 3 个环境到 3 个使用此证书(webapps ssl 绑定)的 ARM 模板创建的其他资源组中。 当我从 azure 门户进入我的证书时,我可以看到私有证书链接到我的 3 个资源组
这块 JSON 将 ssl 证书导入到新的资源组中
{
"type": "Microsoft.Web/certificates",
"name": "MyCert",
"apiVersion": "2016-03-01",
"location": "[variables('Location')]",
"properties": {
"keyVaultId": "[parameters('keyvaultId')]",
"keyVaultSecretName": "[parameters('KeyvaultSecretName')]",
"thumbprint": "[parameters('certThumbprint')]"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', variables('WebAppAppPlanName'))]"
],
},
使用这块 json 通过其指纹创建 ssl 绑定:
{
"name": "[concat(variables('WebAppName'),'/',variables('subDomain'), '.domain.fr')]",
"apiVersion": "2016-08-01",
"type": "Microsoft.Web/sites/hostNameBindings",
"location": "[variables('Location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('WebAppName'))]"
],
"tags": {
"displayName": "HostName"
},
"properties": {
"siteName": "[variables('WebAppName')]",
"customHostNameDnsRecordType": "CName",
"hostNameType": "Verified",
"sslState": "SniEnabled",
"thumbprint": "[reference(resourceId('Microsoft.Web/certificates', 'CertName')).Thumbprint]"
}
},
现在我正在尝试使用 Azure SDK 创建相同的东西:
webApp = webApp.Update()
.DefineHostnameBinding()
.WithThirdPartyDomain(domain)
.WithSubDomain(subdomain)
.WithDnsRecordType(CustomHostNameDnsRecordType.CName)
.Attach()
.Apply();
webApp = webApp.Update()
.WithThirdPartyHostnameBinding(domain, subdomain)
.DefineSslBinding()
.ForHostname(hostName)
.WithExistingCertificate(certificateThumbPrint)
.WithSniBasedSsl()
.Attach()
.Apply();
此代码不起作用,因为在我新创建的资源组中找不到 certificateThumbprint。 缺少的是将我的证书链接到我的资源组的第一个 json 块的等价物。 使用 azure 门户并手动执行此操作称为“导入应用服务证书”
如何使用 C# 中的 azure SDK 以编程方式将我现有的应用服务证书导入我的新资源组?
【问题讨论】:
-
我认为您需要先创建证书。看看BeginCreateOrUpdateCertificate的方法。
-
我已将证书放入我的密钥库。在创建 ssl 绑定之前,我需要通过将此应用证书导入我的新资源组来重用它(最后一个代码块有两个更新)
-
看看吧。该方法意味着创建一个类型为 Microsoft.Web/certificates 的资源。
-
我检查了您的链接,但我并不真正了解此功能的真正目的。它会创建一个新证书吗?它只创建一个“链接”吗?没有如何实施它的例子。它只说“创建或更新证书并与密钥保管库机密相关联。”。你能补充一点解释吗?我尝试搜索此方法的一些文档、示例、用例,但没有结果
-
我认为在我的新资源组中创建 appcertificate 的方法在这里:
var certificate = azure.AppServices.AppServiceCertificates .Define($"CertName") .WithRegion(ResourcesHelper.Location) .WithExistingResourceGroup(RG) .WithPfxByteArray(pfx) .WithPfxPassword(pwd) .Create();现在的困难是从我的密钥库中获取 PFX 和密码......我尝试了很多东西,但没有任何效果
标签: c# azure ssl sdk certificate