Azure Introduction
Azure Pricing
Azure Threats
Resource Locking Administrator Role
More Info:
Ensure there is a custom IAM role assigned to manage resource locking within each Microsoft Azure subscription. Azure resource locking is a powerful protection mechanism that can prevent inadvertent modification or deletion of resources running within a Azure cloud account
Risk Level
Medium
Address
Security
Compliance Standards
CBP
Triage and Remediation
Remediation
To remediate the “Resource Locking Administrator Role” misconfiguration in Azure using the Azure console, follow these steps:
- Log in to the Azure portal (https://portal.azure.com/)
- Click on “Azure Active Directory” from the left-hand menu.
- Click on “Roles and administrators” under “Security”.
- Click on “Add role assignment”.
- In the “Add role assignment” blade, select “Resource Lock Contributor” from the “Role” drop-down menu.
- In the “Select” field, search for the user or group that needs the Resource Lock Contributor role.
- Select the user or group from the search results.
- Click on “Save” to assign the Resource Lock Contributor role to the selected user or group.
By assigning the Resource Lock Contributor role to the appropriate user or group, you can ensure that they have the necessary permissions to create and manage resource locks in Azure. This will help prevent accidental deletion or modification of critical resources.
To remediate the “Resource Locking Administrator Role” misconfiguration in Azure using Azure CLI, follow these steps:
-
Open the Azure CLI and log in to your Azure account.
-
Identify the scope of the Azure resource group or resource that needs to be locked.
-
Create a new role assignment for the Resource Locking Administrator role using the following command:
az role assignment create --role "Resource Locking Administrator" --assignee <object ID or email address> --scope <resource group or resource ID>
Replace
<object ID or email address>
with the email address or object ID of the user or group you want to assign the role to, and replace<resource group or resource ID>
with the ID of the resource group or resource you want to lock. -
Verify that the role assignment was created successfully by running the following command:
az role assignment list --role "Resource Locking Administrator" --all
This command will list all role assignments that have the Resource Locking Administrator role assigned to them.
-
Test the resource locking by attempting to delete the locked resource or modify its properties. You should receive an error message indicating that the resource is locked.
By following these steps, you can remediate the “Resource Locking Administrator Role” misconfiguration in Azure using Azure CLI.
To remediate the “Resource Locking Administrator Role” misconfiguration in Azure using Python, you can follow the below steps:
- Install the Azure SDK for Python using pip:
pip install azure-mgmt-resource
- Authenticate with Azure using your credentials:
from azure.common.credentials import UserPassCredentials
from azure.mgmt.resource import ResourceManagementClient
# Replace the values with your credentials
subscription_id = 'your-subscription-id'
username = 'your-username'
password = 'your-password'
tenant_id = 'your-tenant-id'
credentials = UserPassCredentials(username, password, tenant_id)
resource_client = ResourceManagementClient(credentials, subscription_id)
- Retrieve the Resource Locking Administrator Role:
role_name = 'Resource Locking Administrator'
roles = resource_client.role_definitions.list()
role_definition = next((r for r in roles if r.name == role_name), None)
- If the role does not exist, create it:
if not role_definition:
role_definition = resource_client.role_definitions.create_or_update(
scope='/subscriptions/' + subscription_id,
role_definition_name=role_name,
role_definition={
'Name': role_name,
'IsCustom': False,
'Description': 'Allows management of resource locks.',
'Actions': [
'Microsoft.Authorization/*/read',
'Microsoft.Authorization/locks/*'
],
'NotActions': [],
'AssignableScopes': ['/subscriptions/' + subscription_id]
}
)
- Assign the role to the appropriate user or group:
principal_id = 'your-principal-id' # replace with the principal ID of the user or group you want to assign the role to
assignment_name = 'Resource Locking Administrator Assignment'
assignment_scope = '/subscriptions/' + subscription_id
assignment = resource_client.role_assignments.create(
scope=assignment_scope,
role_assignment_name=assignment_name,
role_assignment_parameters={
'role_definition_id': role_definition.id,
'principal_id': principal_id
}
)
By following these steps, you can remediate the “Resource Locking Administrator Role” misconfiguration in Azure using Python.