01 Run storage account show command (Windows/macOS/Linux) using the name of the Azure Storage account that you want to reconfigure as identifier parameter to describe the ID of the storage account principal:
az storage account show
--name abcdabcdabcd123412341234
--query 'identity.principalId'
02 The command output should return the requested storage account principal ID:
"abcdabcd-1234-1234-1234-abcdabcdabcd"
If the command output didn't return as shown in the example above, the requested principal ID is missing, therefore you need to assign your identity to storage account. Run
storage account update command using the storage account name and resource group name as parameter:
az storage account update
--name abcdabcdabcd123412341234
--resource-group cloud-shell-storage-westeurope
--assign-identity
03 Run keyvault create command (Windows/macOS/Linux) to create the Microsoft Azure Key Vault where the required customer-managed key will be placed:
az keyvault create
--name cc-production-vault
--resource-group cloud-shell-storage-westeurope
--location westeurope
--enabled-for-deployment true
--enabled-for-template-deployment true
--enable-soft-delete true
--enable-purge-protection true
--query 'properties.accessPolicies[*].objectId'
04 The command output should return the Key Vault ID set for new Microsoft Azure Key Vault:
[
"abcdabcd-1234-1234-1234-abcdabcdabcd"
]
05 Run keyvault set-policy command (Windows/macOS/Linux) using the principal ID as object id which get from step 02 and the name of the newly created key vault as identifier parameters to assign the right permissions for the selected vault:
az keyvault set-policy
--name cc-production-vault
--object-id abcdabcd-1234-1234-1234-abcdabcdabcd
--key-permissions get recover unwrapKey wrapKey
06 The command output should return the modified key vault configuration metadata:
{
"id": "/subscriptions/abcdabcd-1234-abcd-1234-abcd1234abcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.KeyVault/vaults/cc-production-vault",
"location": "westeurope",
"name": "cc-production-vault",
"properties": {
"accessPolicies": [
{
"applicationId": null,
"objectId": "...",
"permissions": {
"certificates": [
"get",
"list",
"delete",
"create",
"import",
"update",
"managecontacts",
"getissuers",
"listissuers",
"setissuers",
"deleteissuers",
"manageissuers",
"recover"
],
"keys": [
"get",
"create",
"delete",
"list",
"update",
"import",
"backup",
"restore",
"recover"
],
"secrets": [
"get",
"list",
"set",
"delete",
"backup",
"restore",
"recover"
],
"storage": [
"get",
"list",
"delete",
"set",
"update",
"regeneratekey",
"setsas",
"listsas",
"getsas",
"deletesas"
]
},
"tenantId": "..."
},
{
"applicationId": null,
"objectId": "...",
"permissions": {
"certificates": null,
"keys": [
"get",
"recover",
"unwrapKey",
"wrapKey"
],
"secrets": null,
"storage": null
},
"tenantId": "..."
}
],
"createMode": null,
"enablePurgeProtection": true,
"enableSoftDelete": true,
"enabledForDeployment": true,
"enabledForDiskEncryption": null,
"enabledForTemplateDeployment": true,
"networkAcls": null,
"provisioningState": "Succeeded",
"sku": {
"name": "standard"
},
"tenantId": "...",
"vaultUri": "https://cc-production-vault.vault.azure.net/"
},
"resourceGroup": "cloud-shell-storage-westeurope",
"tags": {},
"type": "Microsoft.KeyVault/vaults"
}
07 Run keyvault key create command (Windows/macOS/Linux) to create the customer-managed key (Bring Your Own Key - BYOK), required to encrypt data within your Microsoft Azure Storage account:
az keyvault key create
--name cc-production-byok
--vault-name cc-production-vault
--kty RSA
--size 2048
--ops decrypt encrypt sign unwrapKey verify wrapKey
--expires "2020-12-05T10:30:00Z"
--protection software
--disabled false
--query 'key.kid'
08 The command output should return the ID of the new customer-managed key. This identifier contains the encryption key version, a 32-digit number (e.g. "12345678901234567890123456789012") that will be used later as value for the --encryption-key-version parameter, to enable encryption for your storage account:
"12345678901234567890123456789012"
09 Run storage account update command (Windows/macOS/Linux) using the name of the Azure Storage account that you want to reconfigure as identifier parameter (see Audit section part I to identify the right resource identifier), to enable encryption with BYOK for the selected storage account (the command does not produce an output):
az storage account update
--name abcdabcdabcd123412341234
--encryption-key-name cc-production-byok
--encryption-key-version 12345678901234567890123456789012
--encryption-key-source Microsoft.Keyvault
--encryption-key-vault https://cc-production-vault.vault.azure.net/
10 Repeat step no. 9 for each storage account created within the current Azure subscription.
11 Repeat steps no. 1 – 10 for each subscription available in your Microsoft Azure cloud account.