Azure Powershell:Get-AzureKeyVaultSecret:不允许操作"get"

use*_*643 7 powershell azure

我使用带有证书的服务原则登录到azure powershell,如下所示:

Add-AzureRmAccount -ServicePrincipal -CertificateThumbprint  $thumbprint -ApplicationId   $applicationid -TenantId $tenant
Run Code Online (Sandbox Code Playgroud)

然后我试图得到一个天蓝色的秘密:

$b = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name 'AccountKey'
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误:

不允许"获取"

我以为我给了读取权限,如下所示:

New-AzureRmRoleAssignment -RoleDefinitionName Reader -ServicePrincipalName $azureAdApplication.ApplicationId.Guid 
Run Code Online (Sandbox Code Playgroud)

有什么建议?

Pet*_*ter 1

您没有正确的访问策略,请使用 Set-AzureRmKeyVaultAccessPolicy 向服务原则授予获取权限:

Set-AzureRmKeyVaultAccessPolicy -VaultName 'Contoso03Vault' -ServicePrincipalName 'http://payroll.contoso.com' -PermissionsToSecrets Get
Run Code Online (Sandbox Code Playgroud)