Azure Policy guardrails every subscription should have
A handful of built-in Azure Policy assignments stop the most common mistakes before they happen. Start with these at the management group level.
On this page
Azure Policy evaluates resources against rules and can audit, deny or automatically fix them. You don't need hundreds of policies to get value. A few well-chosen guardrails at the top of your management group hierarchy prevent most of the mess.
↓ Assignments inherit downwards. Exemptions are the exception, not the rule.
Start with these built-in policies
| Policy | Why |
|---|---|
| Allowed locations | Keeps resources in the regions you've approved for data residency and support |
| Allowed locations for resource groups | Stops resource groups (and their metadata) appearing in other regions |
| Require a tag on resource groups | Enforces ownership and cost-centre tags so every bill has an owner |
| Inherit a tag from the resource group | Copies tags down automatically, so you don't rely on people tagging every resource |
| Storage accounts should disable public network access | Closes one of the most common accidental exposures |
| Configure diagnostic settings | Sends platform logs to your Log Analytics workspace by default |
Roll out with the right effect
- Assign with Audit first and review the compliance results.
- Fix existing resources, or create exemptions with a reason and an expiry date.
- Switch to Deny for prevention policies, and use Modify or DeployIfNotExists with a remediation task for policies that can fix things.
# Assign Allowed locations at a management group, UK regions only
az policy assignment create \
--name allowed-locations \
--display-name "Allowed locations: UK" \
--scope "/providers/Microsoft.Management/managementGroups/mg-landingzones" \
--policy "e56962a6-4747-49cd-b67b-bf8b01975c4c" \
--params '{ "listOfAllowedLocations": { "value": ["uksouth","ukwest"] } }'How evaluation works
- New and updated resources are evaluated when they're created or changed. A Deny policy rejects the request there and then.
- Existing resources are evaluated by a regular compliance scan, roughly once a day. They aren't deleted or blocked, only marked non-compliant.
- New assignments can take up to about 30 minutes to start applying. Don't test a fresh Deny policy and conclude it doesn't work.
# Run a compliance scan now rather than waiting
az policy state trigger-scan --resource-group rg-app-prod
# What's non-compliant at a management group?
az policy state summarize --management-group mg-landingzonesGroup them into an initiative
Once you have more than a handful of assignments, bundle them into an initiative (policy set). One assignment, one compliance score, and parameters such as the list of allowed regions are set in one place.
Exemptions done properly
- Use the Waiver category for accepted risk and Mitigated when the risk is handled another way
- Always add a description that names the owner and the reason
- Set an expiry date so the exemption gets reviewed
- Scope the exemption as narrowly as possible: a resource, not a subscription
Will Deny break my existing resources?
No. Deny only stops new or updated resources. Existing ones show as non-compliant until you fix or exempt them, but changes to them can be blocked if the change itself doesn't comply.
Why does my deployment fail on a resource group in another region?
The Allowed locations for resource groups policy applies to the group's own location. Create the resource group in an approved region, even if it holds global resources.
This post was last checked against Microsoft's documentation over six months ago. The approach should still hold, but check the linked sources for anything that has changed before you act on it.
Next in Azure landing zone guardrails · part 2 of 5Resource locks: a cheap insurance policy against the wrong click →