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
Copy file name to clipboardExpand all lines: articles/storage/common/customer-managed-keys-configure-existing-account.md
+65-96Lines changed: 65 additions & 96 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ author: tamram
7
7
8
8
ms.service: storage
9
9
ms.topic: how-to
10
-
ms.date: 08/31/2022
10
+
ms.date: 09/29/2022
11
11
ms.author: tamram
12
12
ms.reviewer: ozgun
13
13
ms.subservice: common
@@ -39,112 +39,70 @@ The managed identity that authorizes access to the key vault may be either a use
39
39
40
40
### Use a user-assigned managed identity to authorize access
41
41
42
-
A user-assigned is a standalone Azure resource. You must create the user-assigned identity before you configure customer-managed keys. To learn how to create and manage a user-assigned managed identity, see [Manage user-assigned managed identities](../../active-directory/managed-identities-azure-resources/how-manage-user-assigned-managed-identities.md).
43
-
44
-
#### [Azure portal](#tab/azure-portal)
45
-
46
-
When you configure customer-managed keys with the Azure portal, you can select an existing user-assigned identity through the portal user interface. For details, see [Configure customer-managed keys for an existing account](#configure-customer-managed-keys-for-an-existing-account).
47
-
48
-
#### [PowerShell](#tab/azure-powershell)
49
-
50
-
To authorize access to the key vault with a user-assigned managed identity, you'll need the resource ID and principal ID of the user-assigned managed identity. Call [Get-AzUserAssignedIdentity](/powershell/module/az.managedserviceidentity/get-azuserassignedidentity) to get the user-assigned managed identity and assign it to a variable that you'll reference in subsequent steps:
To authorize access to the key vault with a user-assigned managed identity, you'll need the resource ID and principal ID of the user-assigned managed identity. Call [az identity show](/cli/azure/identity#az-identity-show) command to get the user-assigned managed identity, then save the resource ID and principal ID to variables. You'll need these values in subsequent steps:
60
-
61
-
```azurecli
62
-
userIdentityId=$(az identity show --name sample-user-assigned-identity --resource-group storagesamples-rg --query id)
63
-
principalId=$(az identity show --name sample-user-assigned-identity --resource-group storagesamples-rg --query principalId)
### Use a system-assigned managed identity to authorize access
69
45
70
46
A system-assigned managed identity is associated with an instance of an Azure service, in this case an Azure Storage account. You must explicitly assign a system-assigned managed identity to a storage account before you can use the system-assigned managed identity to authorize access to the key vault that contains your customer-managed key.
71
47
72
48
Only existing storage accounts can use a system-assigned identity to authorize access to the key vault. New storage accounts must use a user-assigned identity, if customer-managed keys are configured on account creation.
73
49
50
+
The system-assigned managed identity must have permissions to access the key in the key vault. Assign the **Key Vault Crypto Service Encryption User** role to the system-assigned managed identity with key vault scope to grant these permissions.
51
+
74
52
#### [Azure portal](#tab/azure-portal)
75
53
76
-
When you configure customer-managed keys with the Azure portal with a system-assigned managed identity, the system-assigned managed identity is assigned to the storage account for you under the covers. For details, see [Configure customer-managed keys for an existing account](#configure-customer-managed-keys-for-an-existing-account).
54
+
Before you can configure customer-managed keys with a system-assigned managed identity, you must assign the **Key Vault Crypto Service Encryption User** role to the system-assigned managed identity, scoped to the key vault. This role grants the system-assigned managed identity permissions to access the key in the key vault. For more information on assigning Azure RBAC roles with the Azure portal, see [Assign Azure roles using the Azure portal](../../role-based-access-control/role-assignments-portal.md).
55
+
56
+
When you configure customer-managed keys with the Azure portal with a system-assigned managed identity, the system-assigned managed identity is assigned to the storage account for you under the covers.
77
57
78
58
#### [PowerShell](#tab/azure-powershell)
79
59
80
-
To assign a system-assigned managed identity to your storage account, call [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount):
60
+
To assign a system-assigned managed identity to your storage account, first call [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount):
Next, get the principal ID for the system-assigned managed identity, and save it to a variable. You'll need this value in the next step to create the key vault access policy:
70
+
Next, assign to the system-assigned managed identity the required RBAC role, scoped to the key vault. Remember to replace the placeholder values in brackets with your own values and to use the variables defined in the previous examples:
-RoleDefinitionName "Key Vault Crypto Service Encryption User" `
77
+
-Scope $keyVault.ResourceId
92
78
```
93
79
94
80
#### [Azure CLI](#tab/azure-cli)
95
81
96
-
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):
82
+
To authenticate access to the key vault with a system-assigned managed identity, first assign the system-assigned managed identity to the storage account by calling [az storage account update](/cli/azure/storage/account#az-storage-account-update):
97
83
98
84
```azurecli
85
+
accountName="<storage-account>"
86
+
99
87
az storage account update \
100
-
--name <storage-account> \
101
-
--resource-group <resource_group> \
88
+
--name $accountName \
89
+
--resource-group $rgName \
102
90
--assign-identity
103
91
```
104
92
105
-
Next, get the principal ID for the system-assigned managed identity, and save it to a variable. You'll need this value in the next step to create the key vault access policy:
93
+
Next, assign to the system-assigned managed identity the required RBAC role, scoped to the key vault. Remember to replace the placeholder values in brackets with your own values and to use the variables defined in the previous examples:
The next step is to configure the key vault access policy. The key vault access policy grants permissions to the managed identity that will be used to authorize access to the key vault. To learn more about key vault access policies, see [Azure Key Vault Overview](../../key-vault/general/overview.md#securely-store-secrets-and-keys) and [Azure Key Vault security overview](../../key-vault/general/security-features.md#key-vault-authentication-options).
116
-
117
-
### [Azure portal](#tab/azure-portal)
118
-
119
-
To learn how to configure the key vault access policy with the Azure portal, see [Assign an Azure Key Vault access policy](../../key-vault/general/assign-access-policy.md).
120
-
121
-
### [PowerShell](#tab/azure-powershell)
122
-
123
-
To configure the key vault access policy with PowerShell, call [Set-AzKeyVaultAccessPolicy](/powershell/module/az.keyvault/set-azkeyvaultaccesspolicy), providing the variable for the principal ID that you previously retrieved for the managed identity.
124
-
125
-
```azurepowershell
126
-
Set-AzKeyVaultAccessPolicy `
127
-
-VaultName $keyVault.VaultName `
128
-
-ObjectId $principalId `
129
-
-PermissionsToKeys wrapkey,unwrapkey,get
130
-
```
131
-
132
-
To learn more about assigning the key vault access policy with PowerShell, see [Assign an Azure Key Vault access policy](../../key-vault/general/assign-access-policy.md).
133
-
134
-
### [Azure CLI](#tab/azure-cli)
135
-
136
-
To configure the key vault access policy with PowerShell, call [az keyvault set-policy](/cli/azure/keyvault#az-keyvault-set-policy), providing the variable for the principal ID that you previously retrieved for the managed identity.
96
+
principalId=$(az storage account show --name $accountName \
97
+
--resource-group $rgName \
98
+
--query identity.principalId \
99
+
--output tsv)
137
100
138
-
```azurecli
139
-
az keyvault set-policy \
140
-
--name <key-vault> \
141
-
--resource-group <resource_group>
142
-
--object-id $principalId \
143
-
--key-permissions get unwrapKey wrapKey
101
+
az role assignment create --assignee-object-id $principalId \
102
+
--role "Key Vault Crypto Service Encryption User" \
103
+
--scope $kvResourceId
144
104
```
145
105
146
-
To learn more about assigning the key vault access policy with Azure CLI, see [Assign an Azure Key Vault access policy](../../key-vault/general/assign-access-policy.md).
147
-
148
106
---
149
107
150
108
## Configure customer-managed keys for an existing account
@@ -200,8 +158,10 @@ To configure customer-managed keys for an existing account with automatic updati
200
158
Next, call [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount) to update the storage account's encryption settings, omitting the key version. Include the **-KeyvaultEncryption** option to enable customer-managed keys for the storage account.
@@ -214,17 +174,20 @@ To configure customer-managed keys for an existing account with automatic updati
214
174
Next, call [az storage account update](/cli/azure/storage/account#az-storage-account-update) to update the storage account's encryption settings, omitting the key version. Include the `--encryption-key-source` parameter and set it to `Microsoft.Keyvault` to enable customer-managed keys for the account.
215
175
216
176
```azurecli
217
-
key_vault_uri=$(az keyvault show \
218
-
--name <key-vault> \
219
-
--resource-group <resource_group> \
177
+
accountName="<storage-account>"
178
+
179
+
keyVaultUri=$(az keyvault show \
180
+
--name $kvName \
181
+
--resource-group $rgName \
220
182
--query properties.vaultUri \
221
183
--output tsv)
222
-
az storage account update
223
-
--name <storage-account> \
224
-
--resource-group <resource_group> \
225
-
--encryption-key-name <key> \
184
+
185
+
az storage account update \
186
+
--name $accountName \
187
+
--resource-group $rgName \
188
+
--encryption-key-name $keyName \
226
189
--encryption-key-source Microsoft.Keyvault \
227
-
--encryption-key-vault $key_vault_uri
190
+
--encryption-key-vault $keyVaultUri
228
191
```
229
192
230
193
---
@@ -258,8 +221,10 @@ To configure customer-managed keys with manual updating of the key version, expl
258
221
Remember to replace the placeholder values in brackets with your own values and to use the variables defined in the previous examples.
@@ -275,23 +240,27 @@ To configure customer-managed keys with manual updating of the key version, expl
275
240
Remember to replace the placeholder values in brackets with your own values.
276
241
277
242
```azurecli
278
-
key_vault_uri=$(az keyvault show \
279
-
--name <key-vault> \
280
-
--resource-group <resource_group> \
243
+
accountName="<storage-account>"
244
+
245
+
keyVaultUri=$(az keyvault show \
246
+
--name $kvName \
247
+
--resource-group $rgName \
281
248
--query properties.vaultUri \
282
249
--output tsv)
283
-
key_version=$(az keyvault key list-versions \
284
-
--name <key> \
285
-
--vault-name <key-vault> \
250
+
251
+
keyVersion=$(az keyvault key list-versions \
252
+
--name $keyName \
253
+
--vault-name $kvName \
286
254
--query [-1].kid \
287
255
--output tsv | cut -d '/' -f 6)
288
-
az storage account update
289
-
--name <storage-account> \
290
-
--resource-group <resource_group> \
291
-
--encryption-key-name <key> \
292
-
--encryption-key-version $key_version \
256
+
257
+
az storage account update \
258
+
--name $accountName \
259
+
--resource-group $rgName \
260
+
--encryption-key-name $keyName \
261
+
--encryption-key-version $keyVersion \
293
262
--encryption-key-source Microsoft.Keyvault \
294
-
--encryption-key-vault $key_vault_uri
263
+
--encryption-key-vault $keyVaultUri
295
264
```
296
265
297
266
When you manually update the key version, you'll need to update the storage account's encryption settings to use the new version. First, query for the key vault URI by calling [az keyvault show](/cli/azure/keyvault#az-keyvault-show), and for the key version by calling [az keyvault key list-versions](/cli/azure/keyvault/key#az-keyvault-key-list-versions). Then call [az storage account update](/cli/azure/storage/account#az-storage-account-update) to update the storage account's encryption settings to use the new version of the key, as shown in the previous example.
0 commit comments