SecurityAzure
Azure Policy: audit, deny and fix resources that break the rules
Azure Policy compares the properties of your resources with rules that you assign. Microsoft's guidance is to start with an audit effect in place of an enforcement effect, and to track how the definition affects your resources.

Definitions, initiatives and assignments
- A policy definition is a business rule in JSON. Its
policyRulehas anifblock with the conditions and athenblock with one effect. - An initiative, also referred to as a policySet, groups several definitions.
- An assignment applies a definition or an initiative to a scope: a management group, a subscription, a resource group or an individual resource. Subscopes can be excluded. The assignment also carries the parameter values.
Azure Policy evaluates a resource on four occasions: the resource is created or updated in a scope with an assignment, a scope receives a new assignment, an existing assignment is updated, and the standard compliance evaluation cycle comes round, once every 24 hours.
The effects
Each definition has a single effect. Azure Policy supports eleven:
auditcreates a warning event in the activity log for a non-compliant resource and does not stop the request.auditIfNotExistsaudits resources related to the one that matched.denyprevents a create or update request that does not match the standard. The request returns a 403.denyActionblocks an action on resources. The only action it supports today is DELETE.modifyadds, updates or removes properties or tags during creation or update.appendadds fields to the request. Microsoft recommendsmodifyfor tags.deployIfNotExistsruns a template deployment when the related resource it checks for does not exist.disabledturns a definition off for a single assignment.manuallets you attest the compliance of resources yourself.mutateis specific to Kubernetes policy definitions, andaddToNetworkGroupto Azure Virtual Network Manager.
A definition can take its effect from a parameter. The assignment then chooses among the allowed values.
Two built-in policies
Allowed locations restricts the locations you can specify when deploying resources. Its parameters are listOfAllowedLocations and effect, which accepts Audit, Deny or Disabled and defaults to Deny. It excludes resource groups, which have a separate definition named Allowed locations for resource groups, and resources that use the global region.
Require a tag on resources takes one parameter, tagName, and its effect is fixed at deny. It does not apply to resource groups. Require a tag on resource groups is a separate definition.
Audit before deny
Microsoft's guidance is to start with an audit or auditIfNotExists effect in place of an enforcement effect such as deny, to track how a definition affects the resources in your environment.
Where the effect is a parameter, set it to Audit. You can also set the assignment's enforcement mode to DoNotEnforce. Resources are still evaluated, but the effect is not enforced when a resource is created or updated. Microsoft describes this mode as the way to review compliance impact before enforcement.
az policy assignment create \
--name allowed-locations \
--scope /subscriptions/<subscription-id> \
--policy e56962a6-4747-49cd-b67b-bf8b01975c4c \
-p "{ 'listOfAllowedLocations': { 'value': [ 'eastus', 'westus' ] } }" \
--enforcement-mode DoNotEnforce
az policy assignment create \
--name require-owner-tag \
--scope /subscriptions/<subscription-id> \
--policy 871b6d14-10aa-478d-b590-94f262ecfa99 \
-p "{ 'tagName': { 'value': 'owner' } }" \
--enforcement-mode DoNotEnforceThe two --policy values are the names of the built-in definitions, which are GUIDs. The regions and the tag name owner are choices made for this example, so put your own in their place.
az policy state summarize
az policy assignment update \
--name require-owner-tag \
--enforcement-mode DefaultThe first command returns the latest summary of non-compliant policy states for the current subscription. Review the non-compliant resources, then run the second command to enforce the effect.
Remediation tasks
The deny effect prevents create and update requests. Existing resources that match a deny definition are marked as non-compliant.
Resources that are non-compliant to a modify or deployIfNotExists policy can be brought into compliance through a remediation task. The built-in Inherit a tag from the resource group if missing uses modify in this way. Two conditions apply:
- The assignment uses a managed identity. With the CLI, create it with
--mi-system-assignedand--locationonaz policy assignment create. - The identity needs the roles that the definition lists under
roleDefinitionIds. The portal grants them automatically. With any other method you grant them manually, or the remediation deployment fails.
az policy remediation create \
--name fix-owner-tag \
--policy-assignment <policy-assignment-id>A single remediation task remediates one policy at a time. For an initiative assignment, you select the policy to remediate.
Mistakes to avoid
- Enforcement first. Start with an audit effect or
DoNotEnforce, read the compliance results, then enforce. - A missing role on the managed identity. Outside the portal, grant the roles yourself before you start a remediation task.
- Tags on resources only. The tag policies for resources and for resource groups are separate definitions.
- Overlapping deny policies. Each assignment is evaluated individually, and Microsoft calls the net result cumulative most restrictive. In its example, one policy allows only one region on a subscription and another allows a different region on a resource group inside it. With both set to deny, every new resource in that resource group is denied.
- Management group resources. Assigning a policy at the management group level is possible. Evaluation still covers only the resources at subscription level and at resource group level.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

Azure RBAC: scopes, built-in roles and custom roles
Security · 4 min read
Role assignments, the four scope levels, the built-in roles to know and a custom role in JSON.

Landing zones: accounts, subscriptions and projects in order
Cloud operations · 5 min read
The account hierarchy, identity, network, logging and guardrails in each vendor's landing zone design.

CloudTrail, Azure Activity Log and Cloud Audit Logs: turn them on first
Security · 4 min read
What each cloud logs by default, how long it keeps the record and where to send a copy.