8

我正在构建一组脚本和模板以在 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中看到。

如何诊断问题?

谢谢,

杰里米。

4

1 回答 1

7

如何创建密钥保管库,我使用以下脚本创建密钥保管库并获取 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

有关此的更多信息,请参阅此博客

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

如果它仍然不起作用,我建议你可以检查你的密钥库,你是否给予足够的权限?

在此处输入图像描述

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

于 2017-12-14T02:24:20.743 回答