Azure Resource Locks seem boring right up until they save production from an enthusiastic click on Delete. They aren’t a governance strategy on their own, and they don’t replace backups, RBAC, Azure Policy or change control. Used well, though, they add a cheap, low-friction guardrail around critical resources. The trick is knowing where locks help, where they surprise people, and where they break automation.
Azure Resource Locks decision map
Start with
CanNotDelete.Consider
ReadOnly, then test operations.Pair locks with Azure Policy
denyAction.Automate approved lock removal and reapplication.
What Azure Resource Locks do
Management locks apply at subscription, resource group or resource scope. There are two levels:
| Lock level | Portal name | What it blocks | Best fit |
|---|---|---|---|
CanNotDelete | Delete | Authorized users can read and modify, but not delete. | Production resource groups, shared networking, Log Analytics workspaces, key vaults, managed identities, DNS zones. |
ReadOnly | Read-only | Authorized users can read, but not update or delete. | Rarely changed infrastructure where updates should be intentionally frozen. |
Locks override normal permissions for the protected operation. Even a subscription Owner can’t delete a locked resource until someone with permission to manage locks removes the lock. RBAC decides who may act; the lock makes destructive actions deliberate.
Start with CanNotDelete, not ReadOnly
For most scenarios, CanNotDelete is the right first move. It prevents accidental deletion while allowing patching, scaling, configuration changes and deployments. ReadOnly sounds stronger but blocks operations that don’t look like writes to a human.
Microsoft lists real surprises. A read-only lock on a storage account can block listing account keys, because that’s a POST to Azure Resource Manager. A read-only lock on a resource group with VMs can prevent starts and restarts, and on a group with an App Service plan it can block scaling.
| CanNotDelete | ReadOnly |
|---|---|
| Best default production safeguard | Much more restrictive |
| Allows most normal updates | Blocks update-like control-plane operations |
| Blocks resource and inherited resource group deletion | Can interrupt starts, restarts, scaling, RBAC assignments and runbooks |
| Can still affect cleanup jobs and backup-managed resource groups | Use only after testing the operational workflow |
Understand inheritance before locking a resource group
Locks inherit downward. Child resources inherit a parent lock, including resources created later, and the most restrictive lock in the chain wins. If a locked resource sits inside a group and someone deletes the group, Azure blocks the whole delete rather than partially succeeding. That’s exactly what you want for an accidental delete, and exactly what breaks an unprepared cleanup pipeline.
Control plane vs. data plane
Azure Resource Locks apply to control-plane operations through Azure Resource Manager, not data-plane operations against the service endpoint.
| Plane | Typical endpoint | What a lock can do | What it doesn’t do |
|---|---|---|---|
| Control plane | https://management.azure.com | Block management actions such as deleting or modifying resources. | Inspect application-level data access. |
| Data plane | Storage, SQL or Key Vault endpoints | Usually nothing. | Stop someone with valid data permissions from changing data. |
A lock on a storage account protects the account from deletion, not its blobs, queues, tables or files from identities with data access. That’s the job of data-plane permissions, network controls, immutability, backups and least privilege.
A practical locking pattern
- Classify resources by blast radius. Start with hub networking, production DNS, key vaults, Log Analytics workspaces, managed identities, API Management, production databases and core resource groups.
- Use
CanNotDeletebroadly andReadOnlysparingly. - Document the unlock path: who can remove a lock, what approval is needed and how long it may stay off.
- Automate temporary unlocks for planned changes, with approval, logging and automatic re-lock.
- Pair locks with Azure Policy for broader standards and drift prevention.
- Test the awkward cases in non-production: scaling, restarts, backup cleanup, deployment cleanup, role assignments and group deletion.
Azure CLI and PowerShell examples
Create a resource group delete lock with Azure CLI:
az lock create \
--name rg-prod-cannot-delete \
--lock-type CanNotDelete \
--resource-group rg-prod-shared \
--notes "Production guardrail: remove only through approved change."
List locks on a resource group:
az lock list --resource-group rg-prod-shared --output table
PowerShell:
New-AzResourceLock `
-LockName "rg-prod-cannot-delete" `
-LockLevel CanNotDelete `
-ResourceGroupName "rg-prod-shared" `
-LockNotes "Production guardrail: remove only through approved change."
Use names that encode scope and ownership, such as rg-prod-platform-cannot-delete or kv-payments-prod-cannot-delete.
When to use Azure Policy denyAction instead
Azure Policy’s denyAction effect blocks requests by intended action at scale; delete is the documented supported action, and matching requests get 403 Forbidden. It suits rules such as “deny deletion of production Cosmos DB accounts tagged environment=prod.” It isn’t identical to a lock; Microsoft documents specific behaviors for resource group deletion, cascade deletion, subscription deletion and some authorization resources.
| Need | Resource locks | Azure Policy denyAction |
|---|---|---|
| Protect one known resource or group | Yes | Optional |
| Protect all matching resources by tag or type | Manual unless automated | Yes |
| Visible protection in the portal | Yes | Less visible to operators |
| Block deletes across many subscriptions | Possible but maintenance-heavy | Better fit |
| Freeze updates | ReadOnly lock | No; delete is the supported action |
Common mistakes
- ReadOnly everywhere, which makes normal operations fail in confusing ways.
- Locking backup-managed resource groups without testing; locks can interfere with backup cleanup and restore point management.
- Assuming locks protect data. They protect management operations only.
- Forgetting deployment history. A
CanNotDeletelock on a resource group can stop Resource Manager deleting old deployments; at 800, deployments can fail. - Open-ended temporary unlocks. Re-locking belongs in the same runbook or pipeline.
- Not testing inherited locks, which affect extension resources and future resources.
Recommended Azure Resource Locks baseline
- Production resource groups:
CanNotDelete, unless tooling regularly replaces the whole group. - Shared networking:
CanNotDeleteon hub groups, DNS zones, firewalls, route tables and VPN/ExpressRoute. - Secrets and identity:
CanNotDeleteon production key vaults and managed identities. - Observability:
CanNotDeleteon Log Analytics workspaces and action groups, after testing purge and retention workflows. - ReadOnly: only for tightly controlled resources with rare, tested updates.
- Azure Policy:
denyActionfor tagged production resource types needing broad delete prevention.
Use Azure Resource Graph queries to find production resources without guardrails, and see App Service Key Vault references for a dependency a delete lock can protect. The goal isn’t to make deletion impossible; it’s to make destructive change intentional.
Last reviewed: October 2026
Sources
- Lock your Azure resources (Microsoft Learn)
- Azure Policy denyAction effect (Microsoft Learn)
- Manage resource groups in the Azure portal (Microsoft Learn)
- Azure control plane and data plane (Microsoft Learn)
Discover more from Cloud Osprey
Subscribe to get the latest posts sent to your email.