How to Keep Your Azure Resources Safe with Resource Locks
Tags: cloud, devops, security, azure
Published: 2023-05-19 14:44:50

Accidents and unintentional changes can happen in the dynamic world of cloud computing, where many users collaborate and interact with many resources.

Resource locks allow you to protect important assets, prevent accidental deletion or modification, and ensure reliable functioning throughout your Azure environment. Resource locks act as a crucial defence mechanism which help impose restrictions on necessary resources to protect their availability, integrity, and confidentiality.

In this blog post, we will show you how to create and manage resource locks in Azure.

Locks are used to prevent accidental changes and deletion of azure resources while maintaining privileges assigned to users. Users can maintain their roles and the resource locks can be applied when needed. Locks can also be applied to Subscription and on a Resource group level, this is known as Management Locks. The highest-level locks can be applied to is the subscription level.

Resource locks can be either of the following types:

- **CanNoDelete (Delete Locks)**: This lock type restricts the user from deletion. The user can read and update a resource.

- **ReadOnly**: This lock restricts the user from updating and deleting resources. However, the user has only read access.

By making use of these locks strategically, you gain an additional layer of protection and peace of mind, reducing the chances of human error or unauthorized changes.
Now, let's delve into the process of applying resource locks in Azure. The good news is that the process is simple and straightforward.

To create a resource lock in the Azure portal, follow these steps:

## Part 1

**Go to the Azure portal**
Log in to the Azure Portal using this [link](https://azure.microsoft.com/en-gb/free/) 

**Create a New Resource Group**
A resource group is a logical container that holds related Azure resources. To create a resource group, search for resource group in the search bar and click on it 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/arqns8sy1mc7yw2w1j50.png)

Click on "**_Create_**" 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqd52vkcrps5r2jlgqys.png)

Give it a name (Resource Group) and click on "**_Create + Review_**"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ed385f6ewg62bqinezw7.png)

**Access the Locks section and Add a new lock**
Click the "**_Locks_**" tab in the left-hand menu. On the "**_Locks_**" page, click on the "**_Add_**" button to create a new lock.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7cr9ddv6abvlblboji7.png)

**Define the lock details**
In the "_**Add lock**_" dialog, provide the necessary information to configure the lock

- Lock Name: Give a meaningful name to identify the lock

- Lock Type: Select "**_Delete_**" from the drop-down menu since you want to prevent deletion

- Notes (optional): Add any relevant notes or descriptions to provide additional context for the lock. Click on the "**_OK_**" 
button to create the lock.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjz883a6j647puge6rxj.png)

**_Verify the lock_**
After saving the lock, you should see it listed in the "_**Locks**_" section

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8ybxgtlqvlizgj5m9x3.png)

## Part 2

Locate the storage account
Use the search bar or navigate to the Azure "**_Storage service_**"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4v655htl6uco9s38ghv3.png)

Click on "**_Create_**"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbq9kl9mtzhaem8qkmv3.png)

Give the Storage account a name and click on the "**_Review button_**" and then "**_Create button_**"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hvsz842v4nnfpvm2kk9z.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fd4q4sz6mwb0uleq7zoo.png)

If you try to delete the storage account, an error message will appear

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9kwfidz0xkdbwt3bc4t.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ve5nhu2tptinwl2cmhe.png)

Once the lock has been removed, you will have the necessary permission to delete

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ec0xfwez5bkok4hwcezf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yae5uw567zvxl2xhespe.png)

Congratulations! You have successfully enabled a lock for your Azure storage account to prevent accidental deletion and unauthorized changes. This lock will help ensure the integrity and availability of your storage resources.