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
HighAddress
SecurityCompliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
None
Using CLI
Using CLI
To remediate the misconfiguration of roles assumable by compute services in Azure using the Azure CLI, follow these step-by-step instructions:
- 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.
-
Open a command prompt or terminal and log in to your Azure account using the following command:
-
If you have multiple subscriptions, set the desired subscription where the remediation needs to be applied using the following command:
-
List all the existing role assignments for the compute services using the following command:
-
Identify the role assignments that need to be remediated. Make a note of the
principalIdandscopevalues for each role assignment. -
Remove the role assignments using the following command for each role assignment:
Replace
<principalId>with theprincipalIdvalue obtained in step 5 and<scope>with thescopevalue obtained in step 5. - Verify that the role assignments have been successfully removed by re-running the command in step 4.
Using Python
Using Python
To remediate the misconfiguration of roles assumable by compute services in Azure using Python, you can follow these steps:
-
Install the required Python packages:
-
Import the necessary modules in your Python script:
-
Authenticate with Azure using the default credentials:
-
Create an instance of the ResourceManagementClient:
-
Get the list of compute resources in your Azure subscription:
-
Iterate over the compute resources and check their role assignments:
- Review the output to identify any compute resources with role assignments that need remediation.
-
To remediate the misconfiguration, you can remove the role assignments for compute resources that are not intended to have them. Use the
deletemethod from theRoleAssignmentsOperationsclass:
<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.Using Terraform
Using Terraform
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).
