簡體   English   中英

使用 deploymentScript 運行 Azure 命令的 ARM/Bicep 模板出錯

[英]Error in ARM/Bicep template using deploymentScript running Azure command

我有一個 Bicep 模板,其中包含一個部署腳本 deploymentScript,它應該執行某個 Azure 命令。

但是當我運行我的模板時,它會在運行 deploymentScript 時返回此錯誤:

該服務無權訪問“/subscriptions/3449f684-xxxx-xxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.KeyVault/vaults/my-vault-name”Key Vault。 請確保您已授予該服務執行請求操作所需的權限

我已經設置了一個托管身份並為 KeyVault 添加了管理員角色。

在此處輸入圖像描述

在 KeyVault 中,我啟用了 RBAC。 當我檢查 KeyVault 中的訪問策略時,我確實看到托管身份已鏈接到它。

在此處輸入圖像描述

我會說它甚至是添加到其中的角色的矯枉過正。

最后,我的 deploymentScript 是這樣設置的:

resource siteCertificatesScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
  name: 'siteCertificates'
  location: location
  kind: 'AzurePowerShell'
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '/subscriptions/3449f684-xxxx-xxxx/resourceGroups/MyResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-vault-name': {}
    }
  }
  properties: {
    azPowerShellVersion: '8.3'
    scriptContent: '$Secure_String_Pwd = ConvertTo-SecureString "MyPassword" -AsPlainText -Force; 
         Import-AzKeyVaultCertificate -VaultName "${keyVaultName}" -Name "${resourcePrefix}-cert-signing" -CertificateString "${certSigningBase64}" -Password $Secure_String_Pwd'
    timeout: 'PT1H'
    cleanupPreference: 'OnSuccess'
    retentionInterval: 'P1D'
  }
}

但為什么我的 deploymentScript 失敗並顯示它沒有足夠權限的消息?

我不明白我忘記了什么。

您可能需要向正在部署 arm/bicep 模板的標識授予Microsoft.KeyVault/vaults/deploy/action權限。 我認為 Key Vault 管理員角色沒有此權限:

在此處輸入圖像描述

這是 keyvault 提供程序權限,它與其他microsoft.resources權限分開。

請查看: https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/key-vault-parameter?tabs=azure-cli#grant-deployment-access-to-秘密

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM