Azure Locks – Keeping Your Resources Safe from Accidental (or Panic-Induced) Deletes

Imagine this:
Your team is working at full speed… and suddenly someone deletes a production resource group – and everything vanishes. 😱

Oops?

Enter Azure Locks – the safety net you didn’t know you needed until something got nuked.


🧠 What Are Azure Locks?

Azure Locks prevent accidental changes or deletions to critical Azure resources by enforcing strict control.

✅ You can apply them to:

  • Entire subscriptions
  • Individual resource groups
  • Specific resources

“Locks = Administrative guardrails – even owners and contributors can’t bypass them without removing the lock first.”


🔐 Types of Locks

Azure supports two lock types:

Lock TypeWhat It Does
Read-only (CanNotModify)Allows read access only – no changes allowed
Delete (CanNotDelete)Allows changes, but prevents deletion

🧠 Read-only = like putting a resource in glass
CanNotDelete = changes okay, delete not allowed


📌 Where Can You Apply Locks?

LevelScope
SubscriptionApplies to everything under that subscription
Resource GroupApplies to all resources within that RG
ResourceApplies to that individual resource only

✅ Lock is inherited downward, based on Azure’s resource hierarchy.


🧬 Lock Inheritance & Hierarchy

Locks follow a top-down inheritance model:

  • A subscription-level lock affects all RGs and resources below
  • A resource group-level lock applies to all resources inside
  • A resource-level lock can override nothing – but is still enforced

🧠 Important:

You can’t override a higher-level lock by placing a different lock at a lower level.

Example:
If there’s a CanNotDelete lock on the resource group, even a Contributor cannot delete individual resources inside, even if the resource has no lock of its own.


🛡️ Critical Resources You Should Lock

ResourceWhy Lock It?Recommended Lock Type
Production Resource GroupsPrevent deletion of live infraCanNotDelete
Virtual NetworksAvoid breaking network dependenciesRead-only (if static)
Azure FirewallCritical for security perimeterCanNotDelete
App ServicesIf linked to backend APIsCanNotDelete
Storage Accounts (for logs, backups)Audit and retentionRead-only
Key VaultsSecurity!CanNotDelete

✅ Also useful for shared services, e.g., DNS zones, VPN gateways, monitoring infra.


🛠️ How to Apply Locks

MethodCommand/Action
Azure PortalResource → Locks → Add
PowerShellNew-AzResourceLock
CLIaz lock create --lock-type CanNotDelete
ARM Template/BicepDefine resources block for Microsoft.Authorization/locks

✅ Locks are visible in the Locks blade of each resource or RG


🧠 AZ-104 + Admin Nuggets

  • ✅ Locks don’t prevent billing or monitoring
  • ✅ You must be Owner or User Access Admin to manage locks
  • ✅ Locks do not apply to Data Plane (e.g., cannot prevent writing to a storage blob)
  • ✅ Removing a lock is a deliberate action – and is logged!
  • ✅ NSGs, VNets, and Firewalls are top candidates for Read-only locks in secure setups

🏁 TL;DR – Azure Locks at a Glance

FeatureSummary
PurposePrevent unwanted deletion or changes
Lock TypesCanNotDelete, ReadOnly
ScopeSub, RG, or Resource
Inheritance✅ Top-down enforced
Override?❌ No lower-level override allowed
Use CasesProd RGs, VNets, Firewalls, Storage, Key Vault

“Azure Locks are like seatbelts – not glamorous, but you’ll thank them when something hits the fan.” 😎

Until your next locked-down deployment,
Cya & keep securing smart 🚀

Advertisements

Leave a comment

Website Powered by WordPress.com.

Up ↑

Discover more from BrontoWise

Subscribe now to keep reading and get access to the full archive.

Continue reading