【问题标题】:Azure KeyVaultAccessForbidden - "not enabled for deployment"Azure KeyVaultAccessForbidden - “未启用部署”
【发布时间】:2018-05-27 17:08:14
【问题描述】:

我正在构建一组脚本和模板以在 Azure 中创建 Service Fabric 群集。我有一个脚本,可以创建一个密钥库和一个自签名证书,并成功地将其上传到库中。另一个脚本创建集群,但在证书链接到虚拟机时遇到错误。 New-AzureRmResourceGroupDeployment 命令的错误是:-

{
  "status": "Failed",
  "error": {
  "code": "ResourceDeploymentFailure",
  "message": "The resource operation completed with terminal provisioning state 'Failed'.",
  "details": [
    {
      "code": "KeyVaultAccessForbidden",
      "message": "Key Vault https://VAULT-NAME.vault.azure.net/secrets/clusterCert/SECRET-ID either has not been enabled for deployment or the vault id provided, /subscriptions/SUBSCRIPTION-ID/resourceGroups/jg-sf/providers/Microsoft.KeyVault/vaults/VAULTNAME, does not match the Key Vault's true resource id."
    }
  ]
}

}

VAULT-NAME、SUBSCRIPTION-ID 和 SECRET-ID 都是正确的。已使用参数 "enabledForTemplateDeployment": true 创建了密钥保管库,如以下屏幕截图所示。

我的脚本和模板可以在 GitHub 上看到 - https://github.com/goochjs/azure-testbed

如何诊断问题?

谢谢,

杰里米。

【问题讨论】:

  • 我怀疑这可能与该消息的第二部分有关 - 你能分享模板吗? SF 集群有点奇怪,因为它们需要一个 resourceId 和一个 uri,而且它们必须精确匹配。
  • 感谢您的回复。我在上面添加了一个指向源代码的链接(以及这里 -> github.com/goochjs/azure-testbed
  • 看看你是否可以用你的 keyvault 部署这个模板......这至少应该告诉你问题的根源:github.com/Azure/azure-quickstart-templates/tree/master/…

标签: azure azure-service-fabric azure-resource-manager azure-keyvault azure-template


【解决方案1】:

如何创建密钥库,我使用以下脚本创建密钥库并获取 CertificateURL。

New-AzureRmKeyVault -VaultName $KeyVaultName -ResourceGroupName $ResourceGroup -Location $Location -sku standard -EnabledForDeployment 

#Creates a new selfsigned cert and exports a pfx cert to a directory on disk
$NewCert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -DnsName $CertDNSName 
Export-PfxCertificate -FilePath $CertFileFullPath -Password $SecurePassword -Cert $NewCert
Import-PfxCertificate -FilePath $CertFileFullPath -Password $SecurePassword -CertStoreLocation Cert:\LocalMachine\My 

#Reads the content of the certificate and converts it into a json format
$Bytes = [System.IO.File]::ReadAllBytes($CertFileFullPath)
$Base64 = [System.Convert]::ToBase64String($Bytes)

$JSONBlob = @{
    data = $Base64
    dataType = 'pfx'
    password = $Password
} | ConvertTo-Json

$ContentBytes = [System.Text.Encoding]::UTF8.GetBytes($JSONBlob)
$Content = [System.Convert]::ToBase64String($ContentBytes)

#Converts the json content a secure string
$SecretValue = ConvertTo-SecureString -String $Content -AsPlainText -Force

#Creates a new secret in Azure Key Vault
$NewSecret = Set-AzureKeyVaultSecret -VaultName $KeyVaultName -Name $KeyVaultSecretName -SecretValue $SecretValue -Verbose

#Writes out the information you need for creating a secure cluster
Write-Host
Write-Host "Resource Id: "$(Get-AzureRmKeyVault -VaultName $KeyVaultName).ResourceId
Write-Host "Secret URL : "$NewSecret.Id
Write-Host "Thumbprint : "$NewCert.Thumbprint

更多相关信息,请参考这个blog

我建议你可以检查你的Resource Id 格式。正确的格式类似于/subscriptions/***************/resourceGroups/westus-mykeyvault/providers/Microsoft.KeyVault/vaults/shuisfsvault。您可以先在 Azure Portal 上创建 SF 集群。

如果还是不行,建议你检查一下你的key vault,你给的权限够吗?

注意:为了测试,您可以将所有权限授予用户。

【讨论】:

  • 感谢您的回复。我有一个稍微不同但可比较的证书和密钥库创建脚本,部分原因是在 Windows 7 上,因此并非所有 Windows 10 的证书创建好东西都可用。我已将脚本和模板放入 GitHub -> github.com/goochjs/azure-testbed
  • 您知道了 - 这是密钥保管库资源 ID 的错误格式。我在代码中构建它,它在路径中引用了错误的资源组。不幸的是,我现在遇到了另一个错误(!),但这个问题已经解决了。
猜你喜欢
  • 2012-09-16
  • 2020-11-12
  • 1970-01-01
  • 2012-03-23
  • 2020-05-03
  • 1970-01-01
  • 2012-11-03
  • 1970-01-01
  • 2015-03-11
相关资源
最近更新 更多