azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Set-AzureRmKeyVaultAccessPolicy used in the pipeline breaks when multiple resource groups are present

Open tonybendis opened this issue 8 years ago • 2 comments

DESCRIPTION

"Get-AzureRmKeyVault | Set-AzureRmKeyVaultAccessPolicy ..." breaks if current subscription contains vaults in multiple resource groups. This was working in version 5.7 and was probably introduced with pipeline changes in 6.0.1. It seems that the code grabs the resource group from the first vault and tries to use it for all vaults in the list. Should the ResourceGroupName be set in "else if (ResourceId != null)" block in SetAzureKeyVaultAccessPolicy.cs (around line 477)?

REPRO STEPS

Before running, make sure the current subscription contains vaults in different resource groups.

Get-AzureRmKeyVault | Set-AzureRmKeyVaultAccessPolicy -UserPrincipalName (Get-AzureRmContext).Account.Id -PermissionsToSecrets "get"

Set-AzureRmKeyVaultAccessPolicy : Cannot find vault 'VaultInResGrp2' in resource group 'ResGrp1'.
At line:1 char:23
+ ... mKeyVault | Set-AzureRmKeyVaultAccessPolicy -UserPrincipalName (Get-A ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmKeyVaultAccessPolicy], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.SetAzureKeyVaultAccessPolicy

ENVIRONMENT

Get-Module -Name AzureRM -ListAvailable

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     6.4.0      AzureRM

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17134.48
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.48
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

tonybendis avatar Jul 13 '18 19:07 tonybendis

@tonybendis Good catch, thanks for opening this issue! I fixed this here: https://github.com/Azure/azure-powershell/pull/6666, and will hopefully have it merged and released in about two weeks. In the meantime, you can use this workaround:

get-azurermkeyvault | foreach-object { get-azurermkeyvault -ResourceGroupName $_.ResourceGroupName -VaultName $_.VaultName } | Set-AzureRmKeyVaultAccessPolicy

maddieclayton avatar Jul 13 '18 22:07 maddieclayton

Fixed!

maddieclayton avatar Jul 17 '18 00:07 maddieclayton