Skip to content

Commit 8922c7c

Browse files
committed
add CLI & PowerShell instructions
1 parent 822e09b commit 8922c7c

File tree

1 file changed

+177
-2
lines changed

1 file changed

+177
-2
lines changed

articles/azure-netapp-files/configure-customer-managed-keys.md

Lines changed: 177 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The following diagram demonstrates how customer-managed keys work with Azure Net
4646
`az netappfiles account renew-credentials –-account-name myaccount –resource-group myresourcegroup`
4747

4848
* If the account isn't eligible for MSI certificate renewal, an error message communicates the date and time when the account is eligible. It's recommended you run this operation periodically (for example, daily) to prevent the certificate from expiring and from the customer-managed key volume going offline.
49-
49+
* If you are using the CLI or PowerShell, you must take additional steps to enable access from the NetApp account to the customer-managed keys.
5050
* Applying Azure network security groups on the private link subnet to Azure Key Vault isn't supported for Azure NetApp Files customer-managed keys. Network security groups don't affect connectivity to Private Link unless `Private endpoint network policy` is enabled on the subnet. It's recommended to keep this option disabled.
5151
* If Azure NetApp Files fails to create a customer-managed key volume, error messages are displayed. Refer to the [Error messages and troubleshooting](#error-messages-and-troubleshooting) section for more information.
5252
* If Azure Key Vault becomes inaccessible, Azure NetApp Files loses its access to the encryption keys and the ability to read or write data to volumes enabled with customer-managed keys. In this situation, create a support ticket to have access manually restored for the affected volumes.
@@ -116,6 +116,8 @@ For more information about Azure Key Vault and Azure Private Endpoint, refer to:
116116

117117
## Configure a NetApp account to use customer-managed keys
118118

119+
### [Portal](#tab/azure-portal)
120+
119121
1. In the Azure portal and under Azure NetApp Files, select **Encryption**.
120122

121123
The **Encryption** page enables you to manage encryption settings for your NetApp account. It includes an option to let you set your NetApp account to use your own encryption key, which is stored in [Azure Key Vault](../key-vault/general/basic-concepts.md). This setting provides a system-assigned identity to the NetApp account, and it adds an access policy for the identity with the required key permissions.
@@ -146,7 +148,180 @@ For more information about Azure Key Vault and Azure Private Endpoint, refer to:
146148
* `Microsoft.KeyVault/vaults/keys/decrypt/action`
147149
The user-assigned identity you select is added to your NetApp account. Due to the customizable nature of role-based access control (RBAC), the Azure portal doesn't configure access to the key vault. See [Provide access to Key Vault keys, certificates, and secrets with an Azure role-based access control](../key-vault/general/rbac-guide.md) for details on configuring Azure Key Vault.
148150

149-
1. After selecting **Save** button, you'll receive a notification communicating the status of the operation. If the operation was not successful, an error message displays. Refer to [error messages and troubleshooting](#error-messages-and-troubleshooting) for assistance in resolving the error.
151+
1. Select **Save** then observe the notification communicating the status of the operation. If the operation was not successful, an error message displays. Refer to [error messages and troubleshooting](#error-messages-and-troubleshooting) for assistance in resolving the error.
152+
153+
### [Azure CLI](#tab/azure-cli)
154+
155+
The process to configure a NetApp account with customer-managed keys in the Azure CLI depends on whether you are using a [system-assigned identity](#use-a-system-assigned-idenitty) or an [user-assigned identity](#use-a-new-user-assigned-identity).
156+
157+
#### Use a system-assigned identity
158+
159+
1. Update your NetApp account to use a system-assigned identity.
160+
161+
```azurecli
162+
az netappfiles account update \
163+
--name <account_name> \
164+
--resource-group <resource_group> \
165+
--identity-type SystemAssigned
166+
```
167+
168+
1. To use an access policy, create a variable that includes the principal ID of the account identity, then run `az keyvault set-policy` and assign permissions of "Get", "Encrypt", and "Decrypt".
169+
170+
```azurecli
171+
netapp_account_principal=$(az netappfiles account show \
172+
--name <account_name> \
173+
--resource-group <resource_group> \
174+
--query identity.principalId \
175+
--output tsv)
176+
177+
az keyvault set-policy \
178+
--name <key_vault_name> \
179+
--resource-group <resource-group> \
180+
--object-id $netapp_account_principal \
181+
--key-permissions get encrypt decrypt
182+
```
183+
184+
1. Update the NetApp account with your key vault.
185+
186+
```azurecli
187+
key_vault_uri=$(az keyvault show \
188+
--name <key-vault> \
189+
--resource-group <resource_group> \
190+
--query properties.vaultUri \
191+
--output tsv)
192+
az netappfiles account update --name <account_name> \
193+
--resource-group <resource_group> \
194+
--key-source Microsoft.Keyvault \
195+
--key-vault-uri $key_vault_uri \
196+
--key-name <key>
197+
```
198+
199+
#### Use a new user-assigned identity
200+
201+
1. Create a new user-assigned identity.
202+
203+
```azurecli
204+
az identity create \
205+
--name <identity_name> \
206+
--resource-group <resource_group>
207+
```
208+
209+
1. Set an access policy for the key vault.
210+
```azurecli
211+
user_assigned_identity_principal=$(az identity show \
212+
--name <identity_name> \
213+
--resource-group <resource_group> \
214+
--query properties.principalId \
215+
-output tsv)
216+
az keyvault set-policy \
217+
--name <key_vault_name> \
218+
--resource-group <resource-group> \
219+
--object-id $user_assigned_identity_principal \
220+
--key-permissions get encrypt decrypt
221+
```
222+
223+
>[!NOTE]
224+
>You can alternately [use role-based access control to grant access to the key vault](#use-role-based-access-control).
225+
226+
1. Assign the user-assigned identity to the NetApp account and update the key vault encryption.
227+
228+
```azurecli
229+
key_vault_uri=$(az keyvault show \
230+
--name <key-vault> \
231+
--resource-group <resource_group> \
232+
--query properties.vaultUri \
233+
--output tsv)
234+
user_assigned_identity=$(az identity show \
235+
--name <identity_name> \
236+
--resource-group <resource_group> \
237+
--query id \
238+
-output tsv)
239+
az netappfiles account update --name <account_name> \
240+
--resource-group <resource_group> \
241+
--identity-type UserAssigned \
242+
--user-identity-id $user-assigned-identity \
243+
--key-source Microsoft.Keyvault \
244+
--key-vault-uri $key_vault_uri \
245+
--key-name <key> \
246+
--keyvault-resource-id <key-vault> \
247+
--user-assigned-identity $user_assigned_identity
248+
```
249+
250+
### [Azure PowerShell](#tab/azure-powershell)
251+
252+
The process to configure a NetApp account with customer-managed keys in the Azure CLI depends on whether you are using a [system-assigned identity](#enable-access-for-system-assigned-identity) or an [user-assigned identity](#enable-access-for-user-assigned-identityy).
253+
254+
#### Enable access for system-assigned identity
255+
256+
1. Update your NetApp account to use system-assigned identity.
257+
258+
```azurepowershell
259+
$netappAccount = Update-AzNetAppFilesAccount -ResourceGroupName <resource_group> -Name <account_name> -AssignIdentity
260+
```
261+
262+
1. To use an access policy, run `Set-AzKeyVaultAccessPolicy` with the key vault name, the principal ID of the account identity, and the permissions "Get", "Encrypt", and "Decrypt".
263+
264+
```azurepowershell
265+
Set-AzKeyVaultAccessPolicy -VaultName <key_vault_name> -ResourceGroupname <resource_group> -ObjectId $netappAccount.Identity.PrincipalId -PermissionsToKeys get,encrypt,decrypt
266+
```
267+
268+
1. Update your NetApp account with the key vault information.
269+
270+
```azurepowershell
271+
Update-AzNetAppFilesAccount -ResourceGroupName $netappAccount.ResourceGroupName -AccountName $netappAccount.ResourceGroupName -KeyVaultEncryption -KeyVaultUri <keyVaultUri> -KeyName <keyName>
272+
```
273+
274+
#### Enable access for user-assigned identity
275+
276+
1. Create a new user-assigned identity.
277+
278+
```azurepowershell
279+
az identity create \
280+
--name <identity_name> \
281+
--resource-group <resource_group>
282+
```
283+
284+
1. Assign the access policy to the key vault.
285+
286+
```azurepowershell
287+
user_assigned_identity_principal=$(az identity show \
288+
--name <identity_name> \
289+
--resource-group <resource_group> \
290+
--query properties.principalId \
291+
-output tsv)
292+
az keyvault set-policy \
293+
--name <key_vault_name> \
294+
--resource-group <resource-group> \
295+
--object-id $user_assigned_identity_principal \
296+
--key-permissions get encrypt decrypt
297+
```
298+
299+
>[!NOTE]
300+
>You can alternately [use role-based access control to grant access to the key vault](#use-role-based-access-control).
301+
302+
1. Assign the user-assigned identity to the NetApp account and update the key vault encryption.
303+
304+
```azurepowershell
305+
key_vault_uri=$(az keyvault show \
306+
--name <key-vault> \
307+
--resource-group <resource_group> \
308+
--query properties.vaultUri \
309+
--output tsv)
310+
user_assigned_identity=$(az identity show \
311+
--name <identity_name> \
312+
--resource-group <resource_group> \
313+
--query id \
314+
-output tsv)
315+
az netappfiles account update --name <storage-account> \
316+
--resource-group <resource_group> \
317+
--identity-type UserAssigned \
318+
--user-identity-id $user_assigned_identity \
319+
--key-source Microsoft.Keyvault \
320+
--key-vault-uri $key_vault_uri \
321+
--key-name <key> \
322+
--keyvault-resource-id <key-vault> \
323+
--user-assigned-identity $user_assigned_identity
324+
```
150325

151326
## Use role-based access control
152327

0 commit comments

Comments
 (0)