0
0
Azurecloud~15 mins

Resource locks (delete, read-only) in Azure - Deep Dive

Choose your learning style9 modes available
Overview - Resource locks (delete, read-only)
What is it?
Resource locks in Azure are settings you apply to cloud resources to prevent accidental changes or deletions. There are two main types: delete locks stop resources from being deleted, and read-only locks prevent any changes to the resource. These locks help protect important resources by adding a safety layer. They are easy to apply and remove when needed.
Why it matters
Without resource locks, important cloud resources could be accidentally deleted or changed, causing downtime or data loss. This could disrupt services and cost time and money to fix. Resource locks help avoid these mistakes by making sure critical resources stay safe, even if someone tries to delete or modify them by accident.
Where it fits
Before learning about resource locks, you should understand basic Azure resources and how to manage them. After this, you can learn about Azure role-based access control (RBAC) to control who can apply or remove locks. Later, you might explore Azure policies for broader governance.
Mental Model
Core Idea
Resource locks act like safety covers on your cloud resources, stopping accidental changes or deletions by requiring extra steps to remove the lock first.
Think of it like...
Imagine a valuable book on a shelf with a clear plastic cover. The cover lets you see the book but stops you from tearing pages or throwing it away without first removing the cover carefully.
┌───────────────────────────────┐
│        Azure Resource          │
│  ┌─────────────────────────┐  │
│  │      Resource Lock      │  │
│  │ ┌───────────────┐      │  │
│  │ │ Delete Lock   │      │  │
│  │ │ Read-Only Lock│      │  │
│  │ └───────────────┘      │  │
│  └─────────────────────────┘  │
└───────────────────────────────┘

Lock prevents delete or changes until removed.
Build-Up - 7 Steps
1
FoundationWhat are Azure resource locks
🤔
Concept: Introduction to the idea of resource locks and their types.
Azure resource locks are simple settings you add to resources to protect them. There are two types: Delete locks stop anyone from deleting the resource. Read-only locks stop anyone from changing the resource but still allow reading it.
Result
You understand that locks protect resources from accidental deletion or modification.
Knowing that locks add a safety layer helps prevent costly mistakes in managing cloud resources.
2
FoundationHow to apply resource locks
🤔
Concept: Learning the basic steps to add locks to Azure resources.
In the Azure portal, you select a resource, go to the 'Locks' section, and add a new lock. You choose the lock type (Delete or Read-only) and give it a name. Once applied, the lock immediately protects the resource.
Result
You can protect any resource by applying a lock through the portal.
Understanding the simple process of applying locks empowers you to safeguard resources quickly.
3
IntermediateEffects of delete locks
🤔Before reading on: do you think a delete lock also stops changes to a resource? Commit to your answer.
Concept: Delete locks prevent deletion but allow changes to the resource.
A delete lock stops anyone from deleting the resource, but you can still update or modify it. For example, you can change settings or add data, but you cannot remove the resource entirely while the lock is active.
Result
Resources with delete locks stay safe from deletion but remain usable and changeable.
Knowing that delete locks only block deletion helps you choose the right lock type for your protection needs.
4
IntermediateEffects of read-only locks
🤔Before reading on: do you think a read-only lock allows deleting the resource? Commit to your answer.
Concept: Read-only locks prevent any changes, including deletion, but allow reading the resource.
A read-only lock stops all modifications and deletions. You can view the resource and its data, but you cannot update, delete, or change it in any way until the lock is removed.
Result
Resources with read-only locks are fully protected from changes and deletion.
Understanding that read-only locks provide the strongest protection helps you secure critical resources.
5
IntermediateScope and inheritance of locks
🤔
Concept: Locks can be applied at different levels and affect child resources.
You can apply locks not only on individual resources but also on resource groups or subscriptions. Locks set on a group or subscription automatically protect all resources inside them. This helps protect many resources at once without locking each one separately.
Result
You can protect multiple resources efficiently by locking higher-level containers.
Knowing lock inheritance helps manage protection at scale and avoid missing important resources.
6
AdvancedRemoving and overriding locks
🤔Before reading on: do you think anyone can remove a lock at any time? Commit to your answer.
Concept: Only users with proper permissions can remove locks, and locks can block some operations even for admins.
To remove a lock, you need the right Azure permissions (like Owner or User Access Administrator). Locks prevent accidental changes, but authorized users can remove them when needed. Locks cannot be bypassed by normal operations; they enforce protection strictly.
Result
Locks provide strong protection but can be managed by authorized users.
Understanding permission control around locks prevents accidental lock removal and enforces security.
7
ExpertLocks in automation and deployment pipelines
🤔Before reading on: do you think resource locks can interfere with automated deployments? Commit to your answer.
Concept: Resource locks can block automated scripts or deployments if not handled properly.
When using automation tools like Azure DevOps or ARM templates, resource locks can cause deployment failures if the script tries to delete or modify locked resources. Best practice is to design pipelines to check for locks or remove them safely before changes, then reapply locks after deployment.
Result
Automation respects locks and avoids accidental resource damage during deployments.
Knowing how locks interact with automation helps build reliable, safe deployment processes.
Under the Hood
Azure resource locks work by adding metadata tags to resources that the Azure Resource Manager (ARM) service checks before processing any delete or update requests. When a request comes in, ARM verifies if a lock exists and blocks the operation if it violates the lock type. This check happens at the control plane level, ensuring protection regardless of the client or tool used.
Why designed this way?
Locks were designed to prevent accidental destructive actions without changing resource permissions or roles. This approach allows quick protection without complex access control changes. Using metadata and ARM checks keeps the system flexible and efficient, avoiding performance hits on resource operations.
┌───────────────┐       ┌───────────────────────┐
│ User Request  │──────▶│ Azure Resource Manager │
└───────────────┘       └──────────┬────────────┘
                                    │
                            ┌───────▼────────┐
                            │ Check for Lock │
                            └───────┬────────┘
                                    │
               ┌────────────────────┴────────────────────┐
               │                                         │
      ┌────────▼────────┐                      ┌─────────▼─────────┐
      │ Lock Present?   │                      │ No Lock Present    │
      └────────┬────────┘                      └─────────┬─────────┘
               │ Yes                                      │ No
      ┌────────▼────────┐                      ┌─────────▼─────────┐
      │ Block Operation │                      │ Allow Operation   │
      └─────────────────┘                      └───────────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does a delete lock also prevent changes to a resource? Commit to yes or no.
Common Belief:A delete lock stops all changes to a resource, not just deletion.
Tap to reveal reality
Reality:A delete lock only prevents deletion; changes and updates are still allowed.
Why it matters:Misunderstanding this can lead to insufficient protection if you want to prevent all changes.
Quick: Can a read-only lock be bypassed by an admin? Commit to yes or no.
Common Belief:Admins can bypass read-only locks easily because they have full permissions.
Tap to reveal reality
Reality:Read-only locks block all changes and deletions even from admins until the lock is removed.
Why it matters:Assuming admins can bypass locks may cause accidental resource changes if locks are not respected.
Quick: If you lock a resource group, do locks apply to all resources inside? Commit to yes or no.
Common Belief:Locks on a resource group do not affect individual resources inside it.
Tap to reveal reality
Reality:Locks on a resource group apply to all resources within it, protecting them automatically.
Why it matters:Not knowing this can cause confusion about why resources are locked unexpectedly.
Quick: Do resource locks protect against all types of resource changes? Commit to yes or no.
Common Belief:Resource locks protect against every possible change to a resource.
Tap to reveal reality
Reality:Locks only protect against delete or update operations; they do not control access or data changes inside the resource itself.
Why it matters:Overestimating lock protection can lead to security gaps if access controls are not also used.
Expert Zone
1
Locks do not prevent resource creation; they only protect existing resources from deletion or modification.
2
Applying locks at subscription or resource group level can cause unexpected blocking of operations on nested resources, requiring careful planning.
3
Locks are enforced by Azure Resource Manager, so operations done outside ARM (rare) might bypass locks, which is important for advanced scenarios.
When NOT to use
Avoid using resource locks when you need dynamic, frequent changes to resources or during active development phases. Instead, use role-based access control (RBAC) to manage permissions more flexibly. Locks are best for stable, critical resources where accidental changes must be prevented.
Production Patterns
In production, teams often apply read-only locks on critical infrastructure like databases and networking resources to prevent accidental changes. Delete locks are common on storage accounts or virtual machines to avoid accidental deletion. Automation pipelines include steps to temporarily remove locks for updates and reapply them after deployment.
Connections
Role-Based Access Control (RBAC)
Builds-on
Understanding resource locks alongside RBAC helps create layered security by controlling who can apply or remove locks, combining permission and protection.
Version Control Systems
Similar pattern
Like locks prevent accidental changes to cloud resources, version control systems use locks or branches to prevent accidental overwrites in code, showing a shared principle of protecting important assets.
Physical Safety Locks
Analogous concept from a different field
Just as physical locks prevent unauthorized access or damage to property, resource locks prevent accidental or unauthorized changes to digital assets, illustrating universal safety principles.
Common Pitfalls
#1Trying to delete a resource with an active delete lock.
Wrong approach:az resource delete --ids
Correct approach:az lock delete --name --resource-id az resource delete --ids
Root cause:Not realizing that the delete lock must be removed before deletion causes operation failure.
#2Applying a read-only lock when only deletion protection is needed.
Wrong approach:az lock create --lock-type ReadOnly --name ReadOnlyLock --resource-group MyGroup
Correct approach:az lock create --lock-type Delete --name DeleteLock --resource-group MyGroup
Root cause:Confusing lock types leads to overly restrictive protection, blocking needed updates.
#3Assuming locks prevent unauthorized access to resource data.
Wrong approach:Relying solely on locks to secure sensitive data inside resources.
Correct approach:Use RBAC and network security groups alongside locks to control access and protect data.
Root cause:Misunderstanding that locks only prevent changes, not access, causes security gaps.
Key Takeaways
Azure resource locks protect cloud resources from accidental deletion or modification by adding a safety layer.
Delete locks prevent resource deletion but allow changes; read-only locks prevent all changes including deletion.
Locks can be applied at resource, group, or subscription levels and affect all nested resources.
Only users with proper permissions can remove locks, ensuring controlled management.
Understanding how locks interact with automation and permissions is key to using them effectively in production.