Skip to main content

More Info:

Identifies roles held by the managed identities of compute workloads such as virtual machines and scale sets, together with the permissions those roles carry. Anyone who can run code on the workload inherits the identity, so an application flaw or an exposed VM becomes the roles full permission set. Confirm each workload still needs its role and scope the permissions to the resources it actually touches.

Risk Level

High

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Using Console

None

To remediate the misconfiguration of roles assumable by compute services in Azure using the Azure CLI, follow these step-by-step instructions:
  1. Install and set up the Azure CLI on your local machine if you haven’t already. You can find the installation guide at https://docs.microsoft.com/en-us/cli/azure/install-azure-cli.
  2. Open a command prompt or terminal and log in to your Azure account using the following command:
  3. If you have multiple subscriptions, set the desired subscription where the remediation needs to be applied using the following command:
  4. List all the existing role assignments for the compute services using the following command:
  5. Identify the role assignments that need to be remediated. Make a note of the principalId and scope values for each role assignment.
  6. Remove the role assignments using the following command for each role assignment:
    Replace <principalId> with the principalId value obtained in step 5 and <scope> with the scope value obtained in step 5.
  7. Verify that the role assignments have been successfully removed by re-running the command in step 4.
By following these steps, you will be able to remediate the misconfiguration of roles assumable by compute services in Azure using the Azure CLI.
To remediate the misconfiguration of roles assumable by compute services in Azure using Python, you can follow these steps:
  1. Install the required Python packages:
  2. Import the necessary modules in your Python script:
  3. Authenticate with Azure using the default credentials:
  4. Create an instance of the ResourceManagementClient:
  5. Get the list of compute resources in your Azure subscription:
  6. Iterate over the compute resources and check their role assignments:
  7. Review the output to identify any compute resources with role assignments that need remediation.
  8. To remediate the misconfiguration, you can remove the role assignments for compute resources that are not intended to have them. Use the delete method from the RoleAssignmentsOperations class:
Note: Make sure to replace <your-subscription-id> with your actual Azure subscription ID in step 4.By following these steps, you can identify and remediate the misconfiguration of roles assumable by compute services in Azure using Python.
Changing scope or role_definition_id on an existing azurerm_role_assignment forces replacement of that role assignment, which immediately changes the permissions granted to the VM’s managed identity.To remediate: remove any broad or unnecessary azurerm_role_assignment resources that target the VM’s identity (for example, those scoped at the subscription or management group) and replace them with a single azurerm_role_assignment like the one above, using the narrowest possible scope and least‑privilege role.Verification with terraform plan should show the undesired wide-scope role assignments being destroyed and a single azurerm_role_assignment.vm_identity_least_privilege being created (or updated with a reduced scope/role).