从 Key Vault 机密部署 Web 应用程序证书并将其用于创建 SSL 绑定 - LinkedAuthorizationFailed

Deploy a Web App certificate from Key Vault secret and use it for creating SSL binding - LinkedAuthorizationFailed

我正在尝试将带有 SSL 绑定的自定义域添加到带有 ARM 模板的 Web 应用程序。我可以在 Azure 门户中手动执行此操作,但我希望它与 ARM 模板一起使用。

证书位于密钥保管库中,该保管库与 Web 应用不在同一资源组中。我可以毫无问题地从我的发布管道中的密钥保管库访问普通机密,例如数据库连接字符串。问题是当我尝试访问证书时。我对 keyvault 证书有 GET 权限。

我正在使用这个 github 模板 https://github.com/Azure/azure-quickstart-templates/tree/master/201-web-app-certificate-from-key-vault

这是我在尝试使用发布管道部署 ARM 模板时遇到的错误。

"error": {
  "code": "LinkedAuthorizationFailed",
  "message": "The client 'xxxx' with object id 'xxxx' has permission to perform action 'Microsoft.Web/certificates/write' on scope '***/providers/Microsoft.Web/certificates/xxxxx'; however, it does not have permission to perform action 'write' on the linked scope(s) '/subscriptions/xxxx/resourceGroups/xxx/providers/Microsoft.KeyVault/vaults/xxxxx'."
}

您可以尝试增加 Azure DevOps 服务连接对访问策略下的密钥保管库证书的权限,也许从所有证书权限开始作为故障排除步骤以确认它与权限相关,然后根据需要减少,可能只需要获取并创建?

我通过在ARM模板中创建4个资源解决了这个问题。证书、应用程序服务计划、Web 应用程序和主机名绑定。就这样 github azure-quickstart-template https://github.com/Azure/azure-quickstart-templates/tree/master/201-web-app-custom-domain-and-ssl.

我的关键是通过添加 pxfBlob 和删除密钥保管库属性来修改证书资源,请参阅下面的代码。 certificatePfx 是一个安全字符串,在 keyVault 的发布管道中设置。

{
  "type": "Microsoft.Web/certificates",
  "name": "[parameters('certificateName')]",
  "apiVersion": "2016-03-01",
  "location": "[resourceGroup().location]",
  "properties": {
    "name": "[parameters('webAppName')]",
    "serverFarmId": "[concat(resourceId('Microsoft.Web/serverFarms', parameters('appServicePlanName')))]",
    "hostNames": [
      "parameters('hostname_wildcard')",
      "parameters('hostname_domain')"
    ],
    "pfxBlob": "[parameters('certificatePfx')]"
  },
  "dependsOn": [
    "[concat('Microsoft.Web/sites/',parameters('webAppName'))]"
  ]
},