Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Use Customer Managed Keys for Virtual Hard Disk Encryption” for Azure using the Azure console, follow the below steps:
  1. Open the Azure portal and log in to your account.
  2. Navigate to the virtual machine that you want to remediate.
  3. Select the virtual machine and click on the “Disks” option in the left-hand side menu.
  4. Select the disk that you want to encrypt with customer-managed keys.
  5. Click on the “Disk Encryption” option in the top menu.
  6. In the Disk Encryption pane, select “Customer Managed Keys” as the encryption type.
  7. Click on the “Select a Key” option and choose the key that you want to use for encryption.
  8. Click on the “Save” button to save the changes.
  9. Wait for the encryption process to complete.
Once the encryption process is complete, the virtual machine disk will be encrypted with the customer-managed key.

To remediate the misconfiguration “Use Customer Managed Keys for Virtual Hard Disk Encryption” for Azure using Azure CLI, follow the below steps:
  1. Open Azure CLI and log in to your Azure account.
  2. Create a new customer-managed key in Azure Key Vault using the below command: az keyvault key create --vault-name <key-vault-name> --name <key-name> --protection software Replace <key-vault-name> with the name of your Azure Key Vault and <key-name> with a name for your new key.
  3. Retrieve the key ID of the newly created key using the below command: az keyvault key show --vault-name <key-vault-name> --name <key-name> --query key.kid -o tsv This command will return the key ID in the format: /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.KeyVault/vaults/<key-vault-name>/keys/<key-name>/<key-version>
  4. Update the virtual hard disk (VHD) to use the customer-managed key for encryption using the below command: az disk encryption set --resource-group <resource-group-name> --name <disk-name> --key-url <key-id> --key-vault <key-vault-name> --encryption-type <encryption-type> Replace <resource-group-name> with the name of the resource group containing the VHD, <disk-name> with the name of the VHD to be encrypted, <key-id> with the key ID retrieved in step 3, <key-vault-name> with the name of the Azure Key Vault, and <encryption-type> with the type of encryption to use (e.g. “AES256”).
  5. Verify that the disk encryption is enabled by running the below command: az disk encryption show --resource-group <resource-group-name> --name <disk-name> This command will return the encryption status of the disk.
By following the above steps, you can remediate the misconfiguration “Use Customer Managed Keys for Virtual Hard Disk Encryption” for Azure using Azure CLI.
To remediate the misconfiguration “Use Customer Managed Keys for Virtual Hard Disk Encryption” for AZURE using Python, you can follow the below steps:Step 1: Import the required libraries and authenticate to Azure
Step 2: Get the list of virtual machines in the subscription
Step 3: For each virtual machine, check if the virtual hard disk is encrypted with a customer managed key. If not, update the encryption settings to use a customer managed key.
Note: Replace the <subscription-id>, <key-vault-uri> and <key-secret-url> placeholders with the actual values.By following the above steps, you can remediate the misconfiguration “Use Customer Managed Keys for Virtual Hard Disk Encryption” for AZURE using Python.
Switching an existing VM OS or data disk from platform-managed keys to a disk_encryption_set_id forces replacement of the disk (and typically recreation of the VM), which is an outage; plan carefully before applying.Verification: terraform plan should show creation of the Key Vault, key, user-assigned identity, role assignment, disk encryption set, and an in-place update (or replacement) on the VM resource adding disk_encryption_set_id under the os_disk (and similarly under any data_disk blocks you update).