Skip to content

Commit 9803549

Browse files
committed
tweaks
1 parent f801adc commit 9803549

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

articles/storage/common/customer-managed-keys-configure-key-vault.md

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -202,43 +202,23 @@ To configure customer-managed keys with automatic updating of the key version wi
202202

203203
You can use either a system-assigned managed identity or a user-assigned managed identity to authenticate access to the key vault. To learn more about each type of managed identity, see [Managed identity types](../../active-directory/managed-identities-azure-resources/overview.md#managed-identity-types).
204204

205-
#### Authenticate with a system-assigned managed identity
206-
207-
To use a system-assigned managed identity to authenticate access to the key vault, first determine whether a system-assigned managed identity is assigned to the storage account. Use the [Get-AzStorageAccount](/powershell/module/az.storage/get-azstorageaccount) command to get the storage account object, and then check the `Identity` property of storage account object to get the ID of the system-assigned managed identity. Remember to replace the placeholder values in brackets with your own values and to use the variables defined in the previous examples.
208-
209-
```powershell
210-
$storageAccount = Get-AzStorageAccount -ResourceGroupName <resource_group> `
211-
-AccountName <storage-account>
212-
$storageAccount.Identity
213-
```
214-
215-
If the `identity` property doesn't return a value, then you'll need to assign a system-assigned assigned managed identity to your storage account. To assign a system-assigned managed identity using PowerShell, call [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount):
205+
To authenticate access to the key vault with a system-assigned managed identity, assign the system-assigned managed identity to the storage account by calling [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount):
216206

217207
```powershell
218208
$storageAccount = Set-AzStorageAccount -ResourceGroupName <resource_group> `
219209
-Name <storage-account> `
220210
-AssignIdentity
211+
$objectId = $storageAccount.Identity.PrincipalId
221212
```
222213

223-
Next, to set the access policy for the key vault, call [Set-AzKeyVaultAccessPolicy](/powershell/module/az.keyvault/set-azkeyvaultaccesspolicy), providing the identifier for the system-assigned managed identity. For more information about assigning the key vault access policy, see [Assign a Key Vault access policy using Azure PowerShell](../../key-vault/general/assign-access-policy-powershell.md)).
224-
225-
```powershell
226-
Set-AzKeyVaultAccessPolicy `
227-
-VaultName $keyVault.VaultName `
228-
-ObjectId $storageAccount.Identity.PrincipalId `
229-
-PermissionsToKeys wrapkey,unwrapkey,get
230-
```
231-
232-
#### Authenticate with a user-assigned managed identity
233-
234-
To use a system-assigned managed identity to authenticate access to the key vault, first find the object ID of the user-assigned managed identity. To run this script, you'll need the resource ID of the user-assigned managed identity.
214+
To authenticate access to the key vault with a user-assigned managed identity, first find the object ID of the user-assigned managed identity. To run this example, you'll need the resource ID of the user-assigned managed identity.
235215

236216
```powershell
237217
$userManagedIdentityResourceId = '/subscriptions/{my subscription ID}/resourceGroups/{my resource group name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{my managed identity name}'
238218
$objectId = (Get-AzResource -ResourceId $userManagedIdentityResourceId).Properties.PrincipalId
239219
```
240220

241-
To set the access policy for the key vault, call [Set-AzKeyVaultAccessPolicy](/powershell/module/az.keyvault/set-azkeyvaultaccesspolicy):
221+
Next, to set the access policy for the key vault, call [Set-AzKeyVaultAccessPolicy](/powershell/module/az.keyvault/set-azkeyvaultaccesspolicy), providing the identifier for the system-assigned managed identity. For more information about assigning the key vault access policy, see [Assign a Key Vault access policy using Azure PowerShell](../../key-vault/general/assign-access-policy-powershell.md)).
242222

243223
```powershell
244224
Set-AzKeyVaultAccessPolicy `
@@ -249,8 +229,6 @@ Set-AzKeyVaultAccessPolicy `
249229

250230
For more information, see [Assign a Key Vault access policy using Azure PowerShell](../../key-vault/general/assign-access-policy-powershell.md)).
251231

252-
253-
254232
Finally, configure the customer-managed key. To automatically update the key version for the customer-managed key, omit the key version when you configure encryption with customer-managed keys for the storage account. Call [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount) to update the storage account's encryption settings, as shown in the following example, and include the **-KeyvaultEncryption** option to enable customer-managed keys for the storage account.
255233

256234
```powershell
@@ -261,12 +239,40 @@ Set-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName `
261239
-KeyVaultUri $keyVault.VaultUri
262240
```
263241

264-
265242
# [Azure CLI](#tab/azure-cli)
266243

267244
To configure customer-managed keys with automatic updating of the key version with Azure CLI, install [Azure CLI version 2.4.0](/cli/azure/release-notes-azure-cli#april-21-2020) or later. For more information, see [Install the Azure CLI](/cli/azure/install-azure-cli).
268245

269-
To automatically update the key version for a customer-managed key, omit the key version when you configure encryption with customer-managed keys for the storage account. Call [az storage account update](/cli/azure/storage/account#az_storage_account_update) to update the storage account's encryption settings, as shown in the following example. Include the `--encryption-key-source` parameter and set it to `Microsoft.Keyvault` to enable customer-managed keys for the account.
246+
You can use either a system-assigned managed identity or a user-assigned managed identity to authenticate access to the key vault. To learn more about each type of managed identity, see [Managed identity types](../../active-directory/managed-identities-azure-resources/overview.md#managed-identity-types).
247+
248+
To authenticate access to the key vault with a system-assigned managed identity, assign the system-assigned managed identity to the storage account by calling [az storage account update](/cli/azure/storage/account#az_storage_account_update):
249+
250+
```azurecli-interactive
251+
az storage account update \
252+
--name <storage-account> \
253+
--resource-group <resource_group> \
254+
--assign-identity
255+
```
256+
257+
To authenticate access to the key vault with a user-assigned managed identity, first find the object ID of the user-assigned managed identity.
258+
259+
```azurecli-interactive
260+
az identity show \
261+
--name <name-of-user-assigned-managed-identity> \
262+
--resource-group <resource-group>
263+
```
264+
265+
Next, to set the access policy for the key vault, call [az keyvault set-policy](/cli/azure/keyvault#az_keyvault_set_policy) and provide the object ID of the managed identity:
266+
267+
```azurecli-interactive
268+
az keyvault set-policy \
269+
--name <key-vault> \
270+
--resource-group <resource_group>
271+
--object-id <object-id> \
272+
--key-permissions get unwrapKey wrapKey
273+
```
274+
275+
Finally, configure the customer-managed key. To automatically update the key version for a customer-managed key, omit the key version when you configure encryption with customer-managed keys for the storage account. Call [az storage account update](/cli/azure/storage/account#az_storage_account_update) to update the storage account's encryption settings, as shown in the following example. Include the `--encryption-key-source` parameter and set it to `Microsoft.Keyvault` to enable customer-managed keys for the account.
270276

271277
Remember to replace the placeholder values in brackets with your own values.
272278

@@ -305,6 +311,7 @@ To configure customer-managed keys with manual updating of the key version in th
305311
![Screenshot showing how to enter key URI](./media/customer-managed-keys-configure-key-vault/portal-specify-key-uri.png)
306312

307313
1. Specify the subscription that contains the key vault.
314+
1. Specify either a system-assigned or user-assigned managed identity.
308315
1. Save your changes.
309316

310317
# [PowerShell](#tab/powershell)

0 commit comments

Comments
 (0)