You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Q: My subscription was moved from tenant A to tenant B. How do I change the tenant ID for my existing key vault and set correct ACLs for principals in tenant B?
20
19
21
-
When you create a new key vault in a subscription, it is automatically tied to the default Azure Active Directory tenant ID for that subscription. All access policy entries are also tied to this tenant ID. When you move your Azure subscription from tenant A to tenant B, your existing key vaults are inaccessible by the principals (users and applications) in tenant B. To fix this issue, you need to:
20
+
When you create a new key vault in a subscription, it is automatically tied to the default Azure Active Directory tenant ID for that subscription. All access policy entries are also tied to this tenant ID.
22
21
23
-
* Change the tenant ID associated with all existing key vaults in this subscription to tenant B.
22
+
If you move your Azure subscription from tenant A to tenant B, your existing key vaults are inaccessible by the principals (users and applications) in tenant B. To fix this issue, you need to:
23
+
24
+
* Change the tenant ID associated with all existing key vaults in the subscription to tenant B.
24
25
* Remove all existing access policy entries.
25
-
* Add new access policy entries that are associated with tenant B.
26
+
* Add new access policy entries associated with tenant B.
26
27
27
-
For example, if you have key vault 'myvault' in a subscription that has been moved from tenant A to tenant B, here's how to change the tenant ID for this key vault and remove old access policies.
28
+
For example, if you have key vault 'myvault' in a subscription that has been moved from tenant A to tenant B, you can use Azure PowerShell to to change the tenant ID and remove old access policies.
28
29
29
-
<pre>
30
-
Select-AzSubscription -SubscriptionId YourSubscriptionID # Select your Azure Subscription
31
-
$vaultResourceId = (Get-AzKeyVault -VaultName myvault).ResourceId # Get your Keyvault's Resource ID
32
-
$vault = Get-AzResource –ResourceId $vaultResourceId -ExpandProperties # Get the properties for your Keyvault
33
-
$vault.Properties.TenantId = (Get-AzContext).Tenant.TenantId # Change the Tenant that your Keyvault resides in
34
-
$vault.Properties.AccessPolicies = @() # Accesspolicies can be updated with real
35
-
# applications/users/rights so that it does not need to be # done after this whole activity. Here we are not setting
30
+
```azurepowershell
31
+
Select-AzSubscription -SubscriptionId <your-subscriptionId> # Select your Azure Subscription
32
+
$vaultResourceId = (Get-AzKeyVault -VaultName myvault).ResourceId # Get your key vault's Resource ID
33
+
$vault = Get-AzResource –ResourceId $vaultResourceId -ExpandProperties # Get the properties for your key vault
34
+
$vault.Properties.TenantId = (Get-AzContext).Tenant.TenantId # Change the Tenant that your key vault resides in
35
+
$vault.Properties.AccessPolicies = @() # Access policies can be updated with real
36
+
# applications/users/rights so that it does not need to be # done after this whole activity. Here we are not setting
36
37
# any access policies.
37
-
Set-AzResource -ResourceId $vaultResourceId -Properties $vault.Properties # Modifies the kevault's properties.
az account set <your-subscriptionId> # Select your Azure Subscription
45
+
tenantId=$(az account show --query tenantId) # Get your tenantId
46
+
az keyvault update -n myvault --remove Properties.accessPolicies # Remove the access policies
47
+
az keyvault update -n myvault --set Properties.tenantId=$tenantId # Update the key vault tenantId
48
+
```
49
+
50
+
Now that your vault is associated with the correct tenant ID and old access policy entries are removed, set new access policy entries with the Azure PowerShell [Set-AzKeyVaultAccessPolicy](https://powershell/module/az.keyvault/Set-azKeyVaultAccessPolicy) cmdlet or the Azure CLI [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest#az-keyvault-set-policy) command.
39
51
40
-
Because this vault was in tenant A before the move, the original value of **$vault.Properties.TenantId** is tenant A, while **(Get-AzContext).Tenant.TenantId** is tenant B.
52
+
If you are using a managed identity for Azure resources, you will need to update it to the new Azure AD tenant as well. For more information on managed identities, see [Provide Key Vault authentication with a managed identity](managed-identity.md).
41
53
42
-
Now that your vault is associated with the correct tenant ID and old access policy entries are removed, set new access policy entries with [Set-AzKeyVaultAccessPolicy](https://docs.microsoft.com/powershell/module/az.keyvault/Set-azKeyVaultAccessPolicy).
43
54
44
55
If you are using MSI, you'll also have to update the MSI identity since the old identity will no longer be in the correct AAD tenant.
0 commit comments