Scopes are locked in Azure, which means that a user can't create a new scope or delete an existing one. This is a security measure to prevent accidental changes to the permissions and access control settings.
In Azure, scopes are the highest level of granularity for access control. They determine the scope of access for a user or group, and are used to manage permissions and access control settings. Scopes can be based on a variety of factors, including organizational units, departments, or locations.
Scopes are locked in Azure to prevent users from creating new scopes or deleting existing ones. This ensures that the permissions and access control settings are not accidentally changed.
Lock Basics
A lock is a fundamental component of Azure Scopes, ensuring that access to resources is restricted to authorized users or services.
In Azure Scopes, a lock is a mechanism that prevents accidental or unauthorized changes to a resource.
A lock can be applied to a resource at the subscription level, resource group level, or even at the individual resource level.
To apply a lock, you need to specify the lock level, which can be either Read-only or Can-Not-Delete.
Read-only locks prevent any changes to a resource, while Can-Not-Delete locks prevent deletion but allow other changes.
Locks can be applied by anyone with the necessary permissions, but only the lock's owner can remove it.
Azure Scopes support both Azure Resource Manager (ARM) and classic locks, but ARM locks are recommended for new resources.
Lock Properties
Lock Properties are crucial when it comes to scopes in Azure, and understanding them is essential for effective resource management.
The level of the lock is a critical property, with three possible values: NotSpecified, CanNotDelete, and ReadOnly. CanNotDelete means authorized users can read and modify resources, but not delete them, while ReadOnly means users can only read from a resource, but can't modify or delete it.
The level of the lock is a required property, and it's essential to choose the correct level based on your organization's needs. For example, if you want to prevent users from deleting resources, you should set the level to CanNotDelete.
The notes property allows you to add a description or comment about the lock, with a maximum character limit of 512 characters. This can be helpful for future reference or for communicating with other team members.
The owners property is used to specify the owners of the lock, and it's an array of ManagementLockOwner objects. This allows you to assign multiple owners to a single lock.
Here's a summary of the lock properties:
Azure Locks in Portal and CLI
You can manage Azure locks within the Azure Portal or using the Azure CLI. To deploy a resource lock in the Azure Portal, navigate to the resource or resource group, choose 'Settings > Locks', and add a lock name, type, and optional notes.
In the Azure CLI, you can assign a resource, resource group, or subscription lock using specific commands. The lock types are 'CanNotDelete' for Delete Locks or 'ReadOnly' for Read Only Locks.
To delete a lock, you can use similar commands to create or list existing locks, with the difference being the 'delete' keyword.
Preventing Lock Removal
Preventing Lock Removal is crucial when working with sensitive resources in Azure. To add, modify, or remove resource locks, you need to be either the Owner or User Access Administrator.
You can't rely on custom roles alone, as they require specific permissions to manage resource locks. The required permissions include the ability to add, modify, and remove resource locks.
If you want to enforce locks at the subscription level, you can create resource groups within it and provide necessary permissions to colleagues. This way, they can perform their tasks without compromising the resource locks.
To assign a resource, resource group, or subscription lock using Azure CLI, you'll need to use the 'CanNotDelete' or 'ReadOnly' lock types. Remember that 'CanNotDelete' is for Delete Locks and 'ReadOnly' is for Read Only Locks.
Portal
To deploy a resource lock, navigate to the Azure Portal and go to the resource or resource group you want to lock, then choose 'Settings > Locks' or 'Settings > Resource locks' for subscriptions.
You can add a lock by clicking the 'Add' option, providing a lock name, lock type, and any notes you want to include.
The lock name and type are required fields, but the notes section is optional and can be used to justify why the lock exists.
In my experience, using notes to explain the purpose of the lock helps others understand its significance and makes it easier to manage multiple locks.
You can access resource locks for a resource or resource group by going to 'Settings > Locks', and for a subscription, you can access them by going to 'Settings > Resource locks'.
CLI
You can use Azure CLI to assign a resource, resource group, or subscription lock. To do this, you'll want to perform one of the following commands.
The lock types within Azure CLI are 'CanNotDelete' for Delete Locks, or 'ReadOnly' for Read Only Locks. You can use these commands to assign the appropriate lock type to your resource, resource group, or subscription.
To see all the locks within your current subscription, you can leverage the following command. This command will give you a comprehensive view of all the locks in place.
You can also add additional parameters to narrow the scope of your results. For example, to get resource group locks, you can add the --resource-group parameter. Similarly, to get resource level locks, you can add the --resource parameter.
Deleting
Deleting locks is a straightforward process in Azure. To delete a subscription-level lock, you simply run a command.
You'll need to use the Azure CLI to execute the deletion command. To delete a subscription-level lock, run the following command:
Deleting a resource group-level lock is also possible. To do this, run the following command:
Resource-level locks can be deleted as well, and the command for this is:
Return
To return a list of all resource types, you can use the command provided in the resource section, which will give you a comprehensive list of Microsoft's resource types.
You can also filter down the results by leveraging parameters from Microsoft's documentation, such as the type value.
Microsoft's resource type list can be found here, or you can review the example output to see the type value in action.
Frequently Asked Questions
How to remove scope lock in Azure?
To remove a scope lock in Azure, select the lock you want to delete and click the Delete button. This will remove the lock from the selected resource, resource group, or subscription.
Sources
- https://learn.microsoft.com/en-us/azure/templates/microsoft.authorization/locks
- https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/using-resource-locks-to-prevent-accidental-changes-in-azure/ba-p/3842402
- https://stackoverflow.com/questions/70438131/how-to-stop-a-storage-event-trigger-of-azure-data-factory-using-powershell-when
- https://micoolpaul.com/2023/06/26/microsoft-azure-resource-locks-alerts-a-what-how-and-why-guide/
- https://tutorialsdojo.com/azure-101-protecting-your-resources-using-azure-resource-locks/
Featured Images: pexels.com