Azure Policy: Guardrails for Governance, Security, and Compliance in the Cloud

Azure Policy: Guardrails for Governance, Security, and Compliance in the Cloud

A beginner-friendly, book-style guide to Azure Policy. Learn how rules are written, how effects such as Deny, Audit, and DeployIfNotExists work, how policies are grouped, assigned, and fixed at scale, and how to design, test, monitor, and operate governance in production.

Imagine a huge apartment complex with ten thousand tenants. The owner trusts the tenants, but also knows that people sometimes make mistakes. One tenant props open the fire door. Another installs a gas heater in a room with no ventilation. A third paints the hallway bright orange, against the building’s rules. The owner could hire inspectors to walk the corridors every day, but with ten thousand flats the inspectors would always be behind. A better answer is to build rules into the building itself: fire doors that close by themselves, gas fittings that only fit approved heaters, and a paint shop that only sells approved colours.

A company’s cloud is that apartment complex. Hundreds of engineers create thousands of servers, databases, networks, and storage accounts, every day, often in a hurry. Azure Policy is the set of building rules for Microsoft Azure. It can stop a risky resource from being created, warn when something drifts from the standard, and even fix problems automatically, all without waiting for a human inspector.

This guide assumes you know nothing about the topic. Every new term is explained the first time it appears, every big idea has an everyday comparison, and the chapters build on each other. By the end you will understand what Azure Policy is, how its rules are written and evaluated, how to roll them out safely, how they differ from related features, and how to operate and troubleshoot them in a real company.

1The Problem: A Cloud Without Guardrails

Before meeting any tool, understand the pain it removes. Once the pain is clear, every feature of Azure Policy looks sensible instead of random.

Freedom is the cloud’s gift and its danger

The cloud lets anyone with permission create resources in minutes. That speed is wonderful for innovation, but it means mistakes also spread in minutes. Consider what can go wrong in a company without automatic rules.

Security

Open doors

A storage account that holds customer files is created with public access. A database is exposed to the whole internet. Nobody notices until a stranger does.

Cost

Runaway spending

A developer tries out the largest, most expensive virtual machine size and forgets to delete it. At month end the bill is a shock.

Compliance

Broken regulations

Rules say that personal data must stay in certain countries, but a team deploys to a region far away. An auditor later asks for proof, and nobody has it.

Consistency

Chaos in naming and tagging

Resources have no owner label, no cost-center tag, and wildly different names, so finance cannot tell who owns what.

Operations

Missing protection

Backups are not enabled, logs are not collected, and encryption settings differ from one resource to the next.

Scale

Impossible to inspect by hand

With thousands of resources in dozens of subscriptions, no human team can check every setting every day.

Analogy

Think of a city’s building code. The city does not post an inspector beside every builder. Instead, it publishes rules, such as “every bedroom needs a smoke alarm,” and checks plans and finished buildings against them. Builders are free to design what they like, as long as they stay within the code. Azure Policy is the building code for your cloud, enforced by the cloud itself.

Why training and documents are not enough

Companies often write governance documents: a PDF that says “all storage must be encrypted and private.” But a PDF cannot stop anything. People forget, new staff never read it, and the document goes out of date. Even careful engineers make errors on a bad day. The only dependable guardrail is one that works automatically, at the moment a resource is created or changed, and keeps checking afterward.

What a good guardrail does

  • Prevents clearly forbidden settings, so mistakes cannot happen.
  • Detects existing resources that break the rules, so you know where you stand.
  • Fixes problems automatically where it is safe to do so.
  • Proves to auditors and managers, with data, that the rules are followed.
  • Stays out of the way of legitimate work, with clear messages and a process for exceptions.
Automatic
rules checked every time a resource is created or changed
Every scope
from one resource group to a whole company
1 dashboard
showing which resources comply and which do not

An illustrative example

Take a hypothetical software company with 300 engineers and 60 Azure subscriptions. A security review finds that 14 storage accounts allow public access and 40 percent of virtual machines have no owner tag. The security team assigns a policy that denies new public storage accounts and another that requires an owner tag. From that day, nobody can create such storage, and untagged resources are listed in a compliance report, giving each team a clear to-do list. Within a few weeks, the percentage of tagged resources rises sharply, and the security team spends its time on real threats instead of chasing settings.

2Core Concepts: The Vocabulary of Azure Policy

Azure Policy has a compact vocabulary. Learn these words once and every later chapter reads easily.

The words, one at a time

TermPlain meaningEveryday comparison
ResourceAnything you create in Azure: a virtual machine, a database, a network, a storage accountA room in the building
Policy definitionA single rule that says what to check and what to do when the check failsOne article in the building code
EffectThe action taken when a resource breaks the rule: deny it, flag it, fix it, and so onThe penalty or response attached to the rule
Initiative (policy set)A bundle of many policy definitions managed as one unitA whole chapter of the code, such as “fire safety”
AssignmentThe act of applying a definition or initiative to a particular scopeDeclaring that a rule applies to a particular building
ScopeThe part of the Azure hierarchy where an assignment applies: a management group, subscription, resource group, or single resourceThe district, street, or building the rule covers
ParameterA value you can change when assigning, such as the list of allowed regionsA blank on a form to fill in
ExclusionA child scope left out of an assignmentA building outside the district boundary
ExemptionA recorded, time-limited permission for a specific resource or scope to break a ruleAn official waiver with an expiry date
Compliance stateWhether a resource currently follows the rule: compliant, non-compliant, exempt, or not startedThe result of the inspection
RemediationFixing existing non-compliant resources, usually through a remediation taskA repair crew sent to fix existing violations
AliasA friendly name for a property of a resource that a policy rule can inspectA labelled gauge on the building’s control panel
Managed identityAn Azure-managed identity that a policy assignment uses to make fixes on your behalfA work permit for the repair crew

The building blocks in one picture

The relationship between the pieces is simple. You write or choose a definition, which holds a condition and an effect. You may group many definitions into an initiative. You then create an assignment that applies the definition or initiative to a scope, filling in any parameters. From then on, Azure evaluates resources within that scope against the rule and records a compliance state for each. For existing problems, you can run a remediation.

Analogy

A policy definition is a recipe for a rule, written once and kept in a library. An assignment is when you pin that recipe on the kitchen wall of a particular restaurant branch. The scope is the list of branches where the recipe is pinned, and the effect is what happens when a cook ignores it: the dish is refused at the pass, noted in a log, or quietly corrected by the head chef.

Definitions come in two flavours

Built-in definitions are written and maintained by Microsoft. There are many hundreds, covering common needs such as allowed locations, required tags, encryption, private networking, and backup. Custom definitions are rules you write yourself when no built-in one matches your standard. A wise team starts with built-in definitions, because they are tested, updated as Azure evolves, and understood by auditors, and writes custom ones only for real gaps.

Policy is about resources, not people

One idea causes endless confusion for beginners, so state it early. Azure Policy asks: “Does this resource have an allowed configuration?” It does not ask “Is this person allowed to do this?” The second question belongs to a different feature, Azure role-based access control (RBAC). A person with full rights may still be blocked by a policy if the resource they try to create breaks a rule, and a person without rights cannot create anything regardless of policy. Chapter 3 explains how the two work together.

i
Tip

When reading any policy, ask three questions in order: What does it check? Where is it assigned? What happens when the check fails? Those three answers describe almost everything about it.

3What Azure Policy Is, and How It Differs from Its Neighbours

Azure has several governance and security features that sound alike. Putting Azure Policy next to them makes its role clear.

A short history

In the early days of Azure’s resource-manager model, teams controlled risk mostly with access rights and manual reviews. As companies moved hundreds of workloads to the cloud, they needed rules about the shape of resources, not just about who could create them. Microsoft introduced Azure Policy to fill that gap, and over time it grew to include effects that can modify and deploy settings, rules for data-plane operations in services like Kubernetes and Key Vault, built-in bundles that map to industry standards, and integration with tools such as Microsoft Defender for Cloud, which uses policy initiatives to show security recommendations. Today it sits at the centre of Microsoft’s guidance for cloud governance, including the Azure landing zone reference designs.

What Azure Policy does

Enforce

Prevent bad configurations

Deny creation or updates that break your rules, for example blocking resources outside approved regions.

Assess

Measure compliance

Evaluate every resource and show the percentage that comply, with details of which ones do not and why.

Fix

Remediate automatically

Add missing settings, such as tags or diagnostic logging, to new and existing resources.

Standardise

Apply at scale

Assign once at a high level, such as a management group, and inherit down to hundreds of subscriptions.

Prove

Support audits

Map to standards such as ISO 27001 or NIST through built-in regulatory compliance initiatives, with evidence collected automatically.

Extend

Reach inside services

Check settings in Kubernetes clusters and inside guest operating systems, not just in the Azure control surface.

Policy versus RBAC

QuestionAzure RBACAzure Policy
What does it control?What a person or application may doWhat a resource is allowed to look like
FocusIdentities and permissionsResource properties and configuration
Example rule“Priya may create virtual machines in this resource group”“Virtual machines may only use approved sizes”
Default stanceEverything is denied until allowedEverything is allowed until a rule forbids it
Can it fix resources?NoYes, with Modify and DeployIfNotExists effects
Analogy

RBAC is the security guard at the door checking who may enter. Policy is the building inspector checking what people build once inside. You need both: a guard without an inspector lets authorised people build dangerous things, and an inspector without a guard lets anyone walk in.

Policy versus other features

FeatureWhat it doesHow it relates to Policy
Resource locksBlock deletion or modification of a specific resourceLocks protect individual resources; Policy sets standards across many
Microsoft Defender for CloudFinds security weaknesses and threats, and suggests improvementsIts recommendations are largely powered by Policy initiatives
Azure Resource GraphQueries resources and their properties across subscriptionsPolicy compliance data can be queried through it
Template specs and deployment stacksPackage and manage standard deploymentsTemplates create things correctly; Policy keeps everything correct whoever creates it
Azure BlueprintsPackaged environments with policy, roles, and templatesAnnounced for retirement by Microsoft; its roles are being taken over by other features. Check current guidance
Azure Automanage and Update ManagerManage and patch virtual machinesPolicy can require or assign them
RBAC decides who may build. Policy decides what may be built.

Cost and where it runs

Azure Policy itself has no separate charge for evaluating and enforcing policies on Azure resources. Some related capabilities have their own pricing, for example machine configuration for servers outside Azure, Defender for Cloud plans that use policy-based assessments, and the resources that remediation tasks deploy, such as log workspaces. Always check the current pricing pages, since packaging changes over time.

4Architecture: Where Azure Policy Lives

To use Azure Policy well, you must understand the hierarchy it works within and the components that cooperate to enforce a rule.

flowchart TD
  TEN["Microsoft Entra tenant"] --> RMG["Tenant root management group"]
  RMG --> MG1["Management group Platform"]
  RMG --> MG2["Management group Landing Zones"]
  MG2 --> SUB1["Subscription Online Apps"]
  MG2 --> SUB2["Subscription Corporate Apps"]
  SUB1 --> RG1["Resource group web"]
  SUB1 --> RG2["Resource group data"]
  RG1 --> RES1["Web app"]
  RG2 --> RES2["Storage account"]
  DEF["Policy definitions and initiatives"] --> ASG["Policy assignment"]
  ASG -->|"applies to scope and inherits downward"| MG2
  ASG --> ENG["Policy engine in Azure Resource Manager"]
  ENG --> CMP["Compliance results and Activity Log"]
Figure 4.1: The Azure hierarchy and how policy assignments flow down it

The Azure hierarchy

Azure organises everything in a tree. At the top is the tenant, which is your organisation’s identity directory in Microsoft Entra ID. Under it sits the tenant root management group. Management groups are folders that hold subscriptions and other management groups, up to six levels deep (not counting the root and the subscription level). A subscription is a billing and security boundary that holds resources. Within a subscription, resource groups hold related resources. Finally come the resources themselves.

Analogy

Picture a country. The tenant is the country, management groups are provinces and districts, subscriptions are neighbourhoods, resource groups are streets, and resources are houses. A national law applies everywhere. A district bylaw applies only inside that district. A street rule applies only on that street. And a new house automatically falls under every law above it.

Inheritance: rules flow downward

A policy assigned at a scope applies to everything beneath it, including resources created later. Assign “allowed locations” at a management group and every subscription, resource group, and resource below obeys it. This is the secret to governing at scale: one assignment can protect thousands of resources. You can carve out exceptions with exclusions (a child scope left out of the assignment) and exemptions (a formal, auditable waiver).

The components

ComponentRole
Policy definitionStores the rule: the condition to test, the effect to apply, and parameters. Lives at a management group or subscription so it can be assigned beneath it
Initiative definitionGroups definitions, with shared parameters and optional policy groups that map to compliance controls
Policy assignmentConnects a definition or initiative to a scope, sets parameter values, enforcement mode, messages, and a managed identity if needed
Policy exemptionRecords that a particular scope or resource is excused from an assignment, with a reason and an optional expiry
Policy engineThe service inside Azure Resource Manager that evaluates requests and existing resources against assigned rules
Resource providersThe services behind each resource type. Some policy modes let policy inspect data-plane operations inside providers such as Key Vault or Kubernetes
Policy InsightsStores and serves compliance states, events, and remediation records
Remediation taskA job that applies fixes to existing non-compliant resources using the assignment’s managed identity

Reading the diagram

The upper part of the figure shows the tree, from the tenant down to individual resources. The lower part shows the policy side: definitions and initiatives are stored once and then attached through an assignment to a scope, in this case the Landing Zones management group. The assignment feeds the policy engine inside Azure Resource Manager, which checks resources beneath that scope and records the outcome as compliance results, while important actions also appear in the Activity Log.

Where definitions should live

A definition is available to assign only at its own location and below. A definition stored at a subscription can be used only in that subscription. A definition stored at a management group can be used by any scope beneath that group. So organisations store shared custom definitions high up, usually at a dedicated top-level management group for their company, and assign them lower down as needed.

i
Tip

Design your management group tree for governance, not for your org chart. Group subscriptions by the policies they need, such as production versus sandbox or regulated versus unregulated, because each group becomes a place to assign a different set of rules.

5How Evaluation Works Inside

Follow a single request from an engineer’s click to a decision, and you will understand most of what Azure Policy does.

sequenceDiagram
  participant U as Engineer or pipeline
  participant ARM as Azure Resource Manager
  participant PE as Policy engine
  participant RP as Resource provider
  participant PI as Policy Insights
  U->>ARM: Create or update resource request
  ARM->>ARM: Check authentication and RBAC
  ARM->>PE: Evaluate request against assignments in scope
  PE->>PE: Apply Disabled then Modify and Append then Deny then Audit
  alt Request violates a Deny rule
    PE-->>ARM: Deny with policy message
    ARM-->>U: Request rejected with error
  else Request allowed
    PE-->>ARM: Allow with any modifications
    ARM->>RP: Create or update resource
    RP-->>ARM: Success
    ARM->>PE: Evaluate AuditIfNotExists and DeployIfNotExists
    PE->>PI: Record compliance state
    ARM-->>U: Success
  end
Figure 5.1: The decision path of a resource request through Azure Policy

The steps in words

1

A request arrives

Someone creates or changes a resource through the portal, a command line tool, a template, or an automation pipeline. All of these routes go through Azure Resource Manager, the front door of Azure.

2

Identity and permissions are checked first

Resource Manager confirms who is asking and whether RBAC allows the action. If not, the request ends there, and Policy is never consulted.

3

The policy engine gathers the rules

It finds every assignment that applies at this scope, including those inherited from management groups above, and takes the properties of the requested resource.

4

Rules are tested in a fixed order

Disabled rules are skipped. Modify and Append effects run next, since they may change the request. Deny is evaluated after that, and then Audit. This order matters, because a Modify can fix a problem before a Deny would complain.

5

Decision for the request

If any Deny matches, the request is rejected with an error that names the policy. Otherwise the request, possibly altered by Modify or Append, goes to the resource provider.

6

The resource is created

The resource provider does its job and reports success.

7

Related-resource effects run after creation

AuditIfNotExists and DeployIfNotExists check whether a related resource exists, such as a diagnostic setting for the new resource, and report or create it.

8

Compliance is recorded

The result becomes a compliance state that you can see in the portal, query, and export.

When does evaluation happen?

TriggerWhat happens
Resource created or updated in scopeEvaluated at request time; compliance results usually appear within a few minutes
New assignment or changed assignmentExisting resources in scope are evaluated; this can take some time on large scopes, often around half an hour or more
Standard compliance cycleAll resources are re-evaluated roughly once every 24 hours to catch drift
On-demand scanYou trigger a scan for a subscription or resource group when you cannot wait for the cycle
Resource provider notificationFor some resource types, changes are reported to Policy soon after they happen
Analogy

Think of airport security. At the gate, when a passenger boards, a scanner stops anyone carrying forbidden items. That is a Deny at creation time. Later, a patrol walks the terminal every day looking for unattended bags. That is the periodic compliance scan. Both are needed: the gate catches new problems instantly, while the patrol catches what slipped through before the rules existed.

An important consequence: Deny does not touch existing resources

A Deny rule stops new or changed resources. It does not delete or alter anything that already exists. Existing resources that break the rule simply appear as non-compliant. If someone later edits such a resource, the update may be blocked, even if the edit has nothing to do with the broken setting. That surprises teams who find they cannot change a tag on an old resource because the resource also violates an unrelated deny rule. Plan for this when rolling out strict rules.

Timing and eventual consistency

Compliance data is not instant. After a change, there is often a delay before the dashboard reflects it. Treat the dashboard as an accurate-in-minutes view, not a live meter. When you need certainty right now, trigger an on-demand scan or inspect the resource directly.

!
Watch out

Specific timings, limits, and evaluation details are documented by Microsoft and change over time. Use the figures in this book as typical orientation and confirm them in the current Azure Policy documentation before building commitments on them.

6Anatomy of a Policy Definition

A policy definition is a small structured document. Knowing its parts lets you read any policy, built-in or custom, and write your own when needed.

The parts

PartPurpose
Display name and descriptionHuman-readable title and explanation. A good description says what the rule does and why
ModeWhich kinds of resources the policy evaluates
MetadataCategory, version, and other labels that help organise definitions
ParametersValues chosen at assignment time, such as a list of allowed regions or the effect to use
Policy ruleThe “if” condition and the “then” effect, the heart of the policy

The mode

The mode decides what the policy looks at. Two common ones are All, which evaluates resource groups, subscriptions, and every resource type, and Indexed, which evaluates only resource types that support tags and location. Use Indexed for policies about tags and locations, so that resource types that cannot be tagged do not show up as false non-compliance. Other modes are resource provider modes, such as those for Kubernetes admission control, Key Vault data operations, and some network data operations. These reach inside a service rather than only at its outer settings.

The rule: if this, then that

The policy rule has two halves. The if half describes which resources match the condition. The then half says which effect to apply to those that match. Importantly, the “if” describes the problem condition. For a rule that says “storage accounts must not allow public access,” the “if” matches storage accounts that do allow public access, and the “then” denies them.

Conditions and logic

Inside the “if,” you compare properties of the resource with expected values. Properties are named by fields, such as the resource type, the location, a tag name, or an alias for a specific property like a network setting. A rich set of comparison operators exists: equals, not equals, contains, like with wildcards, in a list, greater and less than, exists, and several others. Conditions can be combined with logical operators: allOf (every condition must be true, like AND), anyOf (at least one must be true, like OR), and not (reverses a condition). They can be nested to express complex rules.

Analogy

A policy rule reads like a sentence on an airport sign: “If the bag is larger than the size limit, AND it is not marked as medical equipment, then it must be checked in.” The “if” is a set of tests joined by AND, OR, and NOT, and the “then” is the instruction that follows.

Aliases: looking inside resources

Resources have many properties that are specific to their type, such as whether a storage account allows public network access. An alias is a stable name that Azure Policy provides for such a property, so a rule can refer to it without worrying about the underlying structure. Aliases can be discovered with command line tools and the portal. If a property you care about has no alias, it cannot be checked by policy until the resource provider adds one, which is a real limit worth knowing.

Parameters make rules reusable

Instead of hard-coding “allowed regions are East US and West Europe,” a good definition declares a parameter named something like “listOfAllowedLocations” and reads it in the rule. One definition can then be assigned with different values in different places: a European business unit assigns European regions, and a US unit assigns US regions. Parameters can offer a list of permitted values, default values, and a drop-down in the portal. Making the effect itself a parameter is a common practice, since it lets one definition be assigned as Audit during testing and Deny in production.

A readable example in words

Here is an example described without code. A custom policy is meant to ensure that every resource group has an “owner” tag. Its mode is All. Its “if” says: the resource type is a resource group, and the tag called owner does not exist. Its “then” uses the effect from a parameter, with a default of Audit. When assigned at a subscription, resource groups with no owner tag are shown as non-compliant. When the team is ready, they change the parameter to Deny, and from that point no new resource group can be created without the tag.

Tip

Start from a built-in

Copy a built-in definition that is close to what you need and adjust it. This is safer than writing from scratch.

Tip

Write clear messages

A non-compliance message on the assignment tells engineers what to do, such as “Add an owner tag with a team email address.”

Tip

Version your definitions

Use the version in metadata and store definitions in source control so that changes are reviewed.

Tip

Test on a sandbox

Assign new rules to a test subscription first and see what they flag before they touch real work.

!
Watch out

A subtle mistake is to write the “if” as the good condition instead of the bad one. A rule that matches the compliant resources and denies them will block exactly the wrong things. Always read your rule aloud as “if the resource has this problem, then apply this effect.”

7Effects: What Happens When a Rule Matches

The effect is the action half of a rule. Choosing the right effect is the single most important design decision when you write or assign a policy.

flowchart TD
  A["Resource request or existing resource"] --> B{"Does the if condition match"}
  B -->|"No"| C["Compliant, nothing happens"]
  B -->|"Yes"| D{"Which effect is set"}
  D -->|"Disabled"| E["Rule is skipped"]
  D -->|"Append or Modify"| F["Request is changed to add or fix properties"]
  D -->|"Deny"| G["Request is rejected with a message"]
  D -->|"Audit"| H["Resource is flagged as non compliant"]
  D -->|"AuditIfNotExists"| I["Check for a related resource, flag if missing"]
  D -->|"DeployIfNotExists"| J["Check for a related resource, deploy it if missing"]
  D -->|"DenyAction"| K["Block a specific action such as delete"]
  D -->|"Manual"| L["Compliance set by human attestation"]
Figure 7.1: What each effect does when a policy condition matches

The effects, one by one

EffectWhat it doesBest used forCare needed
DenyRejects a create or update that breaks the ruleHard rules, such as blocking public storage or unapproved regionsCan block deployments; introduce after an Audit phase
AuditAllows the action but marks the resource non-compliant and logs a warning eventDiscovery, measuring the size of a problem, softer standardsDoes not prevent anything; someone must act on reports
AuditIfNotExistsFlags a resource when a related resource is missingChecking that a VM has an antimalware extension, or a database has auditingEvaluated after creation, so the resource exists meanwhile
DeployIfNotExists (DINE)Deploys a template to create the missing related resourceAutomatically adding diagnostic settings, agents, or backupNeeds a managed identity with rights; remediation for existing resources is separate
ModifyAdds, replaces, or removes properties or tags on a resourceAdding required tags, turning on a setting, inheriting a tag from the resource groupNeeds a managed identity; works at request time and through remediation
AppendAdds fields to a request during create or updateOlder approach for adding properties; Modify is generally preferred for tagsCannot change existing resources; limited scope
DenyActionBlocks a particular action, notably delete, on matching resourcesProtecting critical resources from accidental deletionSupported for limited actions; not a replacement for locks in all cases
ManualLets people attest compliance for things that cannot be checked automaticallyProcess-based controls, such as “staff have completed training”Needs a human process to keep attestations current
DisabledTurns the rule off without removing the assignmentTemporarily pausing a rule, or disabling one policy within an initiativeEasy to forget; track who disabled what and why
!
Watch out

The list of effects and which resource types support each one change over time. A few older effects are deprecated, and some are available only for specific modes. Check the documentation for the particular definition you plan to use.

Order of evaluation

When several policies apply to the same request, Azure evaluates effects in a defined order: Disabled first (simply skipped), then Append and Modify, then Deny, then Audit. Related-resource effects such as AuditIfNotExists and DeployIfNotExists are evaluated after the resource provider has handled the request. This ordering gives useful behaviour. A Modify policy can add a missing required tag before a Deny policy checks for it, so the request passes instead of being rejected.

Analogy

Think of a restaurant kitchen. Audit is the manager writing a note on a chef’s mistake. Deny is the pass refusing to let a faulty dish out. Modify is the chef quietly adding the missing garnish before the dish leaves. DeployIfNotExists is a rule such as “if a table has no water jug, a waiter brings one.” Manual is the hygiene inspector’s signed paper form that no machine can fill in.

Audit versus Deny: the rollout path

The most common safe path is to begin with Audit, learn which resources would be affected, fix them, tell teams, and only then switch to Deny. Rolling out Deny first often blocks urgent work, triggers a flood of complaints, and teaches the company to see governance as an obstacle. Rolling out Audit first shows you the size of the problem and gives teams time to adjust. Design definitions with the effect as a parameter, so that moving from Audit to Deny is a small, easily reviewed change.

Modify and DeployIfNotExists: the repair effects

These two effects can change things, so they need power. When an assignment uses them, Azure creates or uses a managed identity for the assignment, and you must give that identity the roles listed in the definition, for instance Contributor on the scope or a narrower role such as Tag Contributor. Without those roles, remediation fails. Because these identities can change many resources, treat them like any other privileged identity: give the smallest role possible, and review them regularly.

Choosing the right effect

1

Is the setting always wrong?

If yes, and no legitimate use exists, Deny is appropriate. Examples: public database endpoints in production, disallowed regions.

2

Can the platform safely fix it?

If a correct value is obvious and low risk, such as adding a tag or enabling a logging setting, use Modify or DeployIfNotExists so people do not have to.

3

Is it important but not urgent?

Use Audit, report on it, and assign ownership for cleanup.

4

Is a companion resource required?

Use AuditIfNotExists to find gaps, or DeployIfNotExists to close them.

5

Is the control about people or process?

Use Manual to record attestations alongside automated checks.

8Initiatives and Built-In Standards

Managing hundreds of single rules one by one would be exhausting. Initiatives bundle rules so that you manage a theme, not a pile.

What an initiative is

An initiative definition, also called a policy set, is a group of policy definitions with a shared purpose. Instead of assigning 40 separate storage policies one at a time, you assign one “Storage security baseline” initiative. Compliance can then be reported for the whole initiative as well as for each member policy. An initiative can have its own parameters that feed several member policies, so you fill in “allowed regions” once and it flows to all of them.

Analogy

A single policy is one rule, like “wear a helmet.” An initiative is a safety handbook for a construction site containing helmets, boots, ladders, and scaffolding rules. A site manager adopts the handbook as a whole, instead of picking up each rule at the gate.

Policy groups and compliance controls

Initiatives can organise members into policy definition groups. Regulatory compliance initiatives use groups to map to the controls of a standard. For instance, a group might correspond to “encryption of data at rest” in a standard, and the member policies below it are the Azure checks that provide evidence for it. The compliance dashboard can then show, control by control, which are covered and which have gaps.

Built-in initiatives you will meet

Security

Microsoft cloud security benchmark

Microsoft’s own security baseline for Azure, assigned by default through Defender for Cloud on many subscriptions. It is the source of many security recommendations.

Regulatory

Industry and government standards

Built-in initiatives map to widely used frameworks such as ISO 27001, NIST SP 800-53, PCI DSS, SOC 2, HIPAA, and regional standards. Treat them as helpful evidence, not as a certification by themselves.

Governance

Tagging and naming helpers

Initiatives and definitions that require or inherit tags such as cost center or owner.

Monitoring

Logging and diagnostics

Bundles that configure diagnostic settings so that resource logs flow to a log workspace, storage account, or event hub.

Landing zones

Azure landing zone policies

The reference architecture ships a coordinated set of policy assignments for platform and workload management groups.

Platform

Kubernetes and virtual machine baselines

Initiatives for container security and for guest operating system settings.

!
Watch out

Passing a built-in regulatory initiative does not make you compliant with that regulation. It checks the Azure-technical part of certain controls. Many controls concern people, process, and physical security, which policy cannot see. Always combine policy results with the rest of your compliance programme, and discuss the mapping with your auditors.

Customising an initiative

Built-in initiatives are read-only, but you can copy one, remove members you do not need, add your own custom policies, and change parameters. When copying, remember that your copy does not automatically follow future changes Microsoft makes to the original, so schedule periodic comparisons. Some organisations prefer to assign the built-in initiative unchanged and use exemptions or parameter choices for differences, so that updates keep flowing in.

Initiative design guidelines

  • Group by theme or owner. A “network security” initiative managed by the network team is easier to govern than a mixed bag.
  • Keep sizes manageable. There are documented limits on how many policies an initiative can hold and on the number of initiatives per scope, and very large initiatives slow troubleshooting.
  • Use parameters thoughtfully. Surface the choices people really need to make, such as effects and allowed values, and keep sensible defaults for the rest.
  • Name clearly. Names should tell a new engineer what the initiative is for, and descriptions should say who owns it.
  • Version and document. Record what each release changed and why.

Overlapping initiatives

When two initiatives contain the same policy with different parameters, both evaluate and both report. This can create confusing duplicate findings, and, when one uses Deny and the other Audit, the strictest effect wins at request time. Review overlaps, particularly when you assign a regulatory initiative on top of your own baseline, to avoid duplicated noise.

9Assignments, Scope, Exclusions, and Exemptions

A rule only matters where it is assigned. Choosing scope and handling exceptions wisely is the heart of day-to-day policy work.

What an assignment contains

SettingMeaning
Definition or initiativeWhich rule or bundle to apply
ScopeWhere it applies: management group, subscription, resource group, or resource
ExclusionsChild scopes inside that scope that should not be evaluated
ParametersValues for the definition, including the chosen effect where allowed
Enforcement modeDefault (rules are enforced) or DoNotEnforce (rules evaluated and reported, but Deny and similar blocking is not applied)
Non-compliance messagesFriendly text shown to users when a request is denied
Managed identity and locationNeeded for Modify and DeployIfNotExists so the assignment can make changes
Resource selectors and overridesNewer options to apply an assignment to a subset of resources, such as by location or type, or to override effects for specific members in a safe, staged way

Enforcement mode: a safe test switch

Setting an assignment to DoNotEnforce lets you see what a rule would do without blocking anything. The compliance results appear, the Activity Log shows what would have been denied, but real requests proceed. This is an excellent way to test a Deny rule in production before turning it on. Flip the assignment to the default mode when you are confident.

Choosing the right scope

Wide

Management group

Best for company-wide rules such as allowed regions, mandatory tags, and security baselines. One assignment covers many subscriptions.

Medium

Subscription

Suited to rules that differ by team, application, or environment, such as production-only restrictions.

Narrow

Resource group

Useful for special cases: a project that needs an extra rule or a temporary experiment.

Fine

Single resource

Rare, mostly for exemptions or very specific controls.

A good rule of thumb is to assign as high as is sensible, so that new subscriptions are covered automatically, and to avoid scattering the same rule at many low levels, which becomes a maintenance burden.

Exclusions versus exemptions

Exemptions (preferred)

  • Recorded as their own object with a reason
  • Two categories: Waiver (accepted risk) and Mitigated (covered another way)
  • Can have an expiry date so they do not live forever
  • Resources still appear in reports as exempt
  • Can apply to a resource or a scope

Exclusions (use sparingly)

  • Part of the assignment itself, easy to forget
  • No reason or expiry recorded
  • Excluded scope disappears from the compliance picture
  • Hard to audit later
  • Fine for permanent, well-understood carve-outs
Analogy

An exclusion is like drawing the city boundary so a village falls outside it; the village is simply not part of the conversation anymore. An exemption is like a signed, dated permit letting one particular building keep its old wooden balcony until next year: the building is still on the inspector’s list, and everybody can see why it is allowed.

Managing exemptions well

  • Require a ticket or approval reference in the exemption description.
  • Set an expiry date, and review expired or soon-to-expire exemptions regularly.
  • Restrict who can create exemptions, since this is a power to bypass governance.
  • Report on the number of exemptions per policy; a policy with many exemptions may need redesign.

Conflicts between assignments

If a resource falls under several assignments, all of them are evaluated. There is no “closest assignment wins.” A Deny anywhere in the chain blocks the request. You cannot loosen a parent’s Deny from a child scope except through an exemption. This is why top-level assignments should be few, well-reviewed, and truly universal. Rules that apply only to some workloads belong lower in the tree.

i
Tip

Write clear non-compliance messages. A message like “Storage accounts must disable public network access. See the cloud standards page, section 4, or ask the platform team for an exemption” turns a confusing error into a helpful next step and reduces support requests.

10Remediation: Fixing What Already Exists

Policies that only prevent future mistakes leave the old ones behind. Remediation closes that gap.

Two kinds of problems

New resources that arrive after the policy was assigned are handled at request time: Deny stops them, Modify corrects them, and DeployIfNotExists adds missing parts. Existing resources are different. They were created before the rule, or they drifted, and the policy engine merely marks them non-compliant. Fixing them requires either a human or a remediation task.

How a remediation task works

1

The assignment has a managed identity

When you assign a Modify or DeployIfNotExists policy, you choose a system-assigned or user-assigned managed identity.

2

The identity receives the needed roles

The definition lists the roles required, such as Contributor or Log Analytics Contributor. The portal can assign them during creation, but pipelines must do it explicitly.

3

You create a remediation task

Choose the assignment, and optionally a subset by location or resource filters. Start small to test.

4

Azure applies fixes in the background

For Modify, it updates properties. For DeployIfNotExists, it runs the template in the definition against each non-compliant resource.

5

Results are tracked

The task shows succeeded, failed, and in-progress counts, with per-resource errors. Compliance states update afterwards.

6

Repeat or automate

New non-compliant resources may need new tasks. Some organisations run remediation on a schedule from a pipeline.

Analogy

After a new fire code is introduced, new buildings are built correctly from the start. For old buildings, the city sends a crew with a permit to install sprinklers, floor by floor. The remediation task is that crew, and the managed identity is the permit that lets it enter and work.

Risks of remediation

  • Surprise changes in production. Changing a setting on a live resource may interrupt service. For example, enabling a feature that restarts a service. Test on a small scope first.
  • Too much privilege. An identity with Contributor on a whole management group can change everything. Prefer narrow roles listed in the definition.
  • Cost. Deploying diagnostic settings or agents across thousands of resources can generate large volumes of logs and charges.
  • Template limits. The deployment template in a DeployIfNotExists definition must work for every matching resource, including unusual configurations. Failures are common when resources are in unexpected states.
  • Race with other automation. A pipeline that sets a value and a policy that sets a different value can fight each other forever.

When not to auto-remediate

Some problems are not safe to fix automatically. Disabling public access on a storage account that a partner relies on would break an integration. In such cases, use Audit, notify the owner, and let a human decide, perhaps with an exemption for the justified case. Automatic repair suits settings with an obvious safe value, such as adding tags, enabling logging, and attaching standard monitoring.

i
Tip

Use “tag inheritance” Modify policies to copy tags such as cost center from a resource group down to its resources. This is one of the most popular and safest uses of Modify, and it makes cost reports far more useful.

11Governance Design: Management Groups and Landing Zones

Policy gets its power from where you attach it. A well-designed hierarchy makes policy simple, and a poor one makes it painful.

flowchart TD
  ROOT["Tenant root group"] --> CO["Company top group"]
  CO --> PLAT["Platform"]
  CO --> LZ["Landing Zones"]
  CO --> SAND["Sandbox"]
  CO --> DEC["Decommissioned"]
  PLAT --> IDN["Identity"]
  PLAT --> MGT["Management"]
  PLAT --> CON["Connectivity"]
  LZ --> CORP["Corp private workloads"]
  LZ --> ONL["Online internet facing workloads"]
  CO -.->|"Baseline policies for all"| CO
  LZ -.->|"Workload guardrails"| LZ
  SAND -.->|"Light touch cost and region rules"| SAND
Figure 11.1: A typical management group layout inspired by Azure landing zone guidance

Azure landing zones

A landing zone is a well-prepared Azure environment where workloads can be deployed safely: networking, identity, monitoring, and policy are ready before the first application arrives. Microsoft’s Azure landing zone reference architecture proposes a management group layout, shown in simplified form above, and ships a coordinated set of policy definitions and assignments for it. Platform groups hold shared services such as identity, central networking, and monitoring. Landing zone groups hold application subscriptions, further divided into “Corp” for internally connected workloads and “Online” for internet-facing ones. A Sandbox group provides an area for experiments with light rules, and a Decommissioned group holds subscriptions waiting for deletion.

Analogy

A landing zone is a serviced plot in a planned new town. Roads, water, electricity, and fire hydrants are already in place, and the town’s building code is already in force. A builder arrives and focuses on the house. In a badly planned town, each builder must lay their own pipes and write their own rules.

Which policies where

LevelTypical policies
Company top groupAllowed regions, required tags, baseline security, diagnostic logging to central workspace, deny risky resource types
Platform groupsStricter rules for shared network and identity components, restrictions on who can create them
Landing zonesDeny public IPs on virtual machines, require private endpoints for data services, enforce encryption and backups
CorpBlock direct internet exposure, require connection to the hub network
OnlineRequire web application firewall and DDoS protection for public entry points
SandboxBudgets, size limits, small set of allowed services, automatic cleanup, isolation from production networks

Design principles

  • Keep the tree shallow. Deep trees are hard to reason about. A few levels are usually enough.
  • Do not mirror the org chart. Reorganisations happen often, while the governance needs of workloads change slowly.
  • Use a dedicated top group beneath the tenant root, so that you can manage policies without touching the root, which is hard to undo.
  • Subscriptions as units of scale. Create separate subscriptions per application or environment, because many limits and billing views work at that level, and policy can be tailored by moving the subscription to a different group.
  • Automate subscription vending. A repeatable process creates new subscriptions, places them in the right group, and sets up networking and access, so policies apply from the first minute.
!
Watch out

Be extremely careful with assignments at the tenant root management group. A mistaken Deny at the top can block every deployment in the company, including the fix. Keep changes there to a minimum, and test everything first at lower levels.

12Policy as Code: Managing Governance Like Software

Clicking through the portal does not scale, leaves no history, and invites mistakes. Mature teams manage policies as code with reviews, tests, and automated rollout.

Why policy as code

Policies are powerful: a single wrong change can block every deployment in a company. They deserve at least the same care as application code. Keeping definitions, initiatives, assignments, and exemptions in a Git repository gives you version history, peer review, an audit trail of who approved what, easy rollback, and the ability to recreate the same governance in a new tenant or a test environment.

Analogy

Managing policies by hand in the portal is like a city council changing building laws by scribbling on a single master paper in the clerk’s office. Policy as code is the proper legislative process: a draft is proposed, reviewed, tested against case studies, voted on, published with a version number, and archived. If it turns out to be a mistake, the previous version can be restored at once.

flowchart LR
  A["Change policy files in a branch"] --> B["Pull request"]
  B --> C["Automated validation and linting"]
  C --> D["Deploy to sandbox with DoNotEnforce"]
  D --> E["Check compliance impact report"]
  E --> F{"Reviewers approve"}
  F -->|"No"| A
  F -->|"Yes"| G["Merge to main"]
  G --> H["Deploy to production management group"]
  H --> I["Start with Audit effect"]
  I --> J["Monitor and fix findings"]
  J --> K["Switch to Deny after readiness"]
Figure 12.1: A safe delivery pipeline for policy changes

What goes into the repository

Files

Custom definitions

One file per policy definition, with clear names, metadata, and versions.

Files

Initiative definitions

Group definitions into initiatives, with parameters and groups.

Files

Assignments

The scope, parameter values, enforcement mode, messages, and managed identity role assignments for each environment.

Files

Exemptions

Reasons, categories, expiry dates, and approval references, reviewed like any other change.

Docs

Standards and decision records

Why each rule exists, who owns it, and what to do when it blocks you.

Tests

Test cases

Sample compliant and non-compliant resources to confirm that a rule behaves as designed.

Tooling options

ApproachStrengthConsider
Bicep or ARM templatesNative Azure language; definitions, initiatives, and assignments are normal resourcesLarge estates need careful structuring and ordering
Terraform or OpenTofuPopular multi-cloud tooling with plans and stateState management and the long-running nature of policy objects need attention
Enterprise Policy as Code (EPAC)Community and Microsoft-supported framework built for managing policies at scale, with plans and reportsLearning curve; check current documentation and maintenance status
Azure CLI or PowerShell scriptsFlexible for small cases and one-off tasksHarder to keep consistent and to review as the estate grows
PortalGreat for learning and exploringNot repeatable; avoid for production governance

Testing policies

1

Static checks

Validate syntax, required metadata, naming rules, and that every parameter used is declared.

2

Unit-style tests in a sandbox

Create a few resources that should pass and a few that should fail, and verify the compliance states or the denial messages. Tests can be automated in a pipeline against a test subscription.

3

Impact analysis

Assign with DoNotEnforce or Audit to production scopes, then read the compliance report to see how many resources would be affected.

4

Staged rollout

Move from sandbox to a pilot group of subscriptions, then wider, with communication at each stage.

5

Watch and be ready to roll back

Have a one-click path, such as switching an effect to Audit or setting DoNotEnforce, for emergencies.

Controlling who can change policy

Because policy changes are high impact, restrict them. Only a small platform or governance team should hold rights to write definitions and assignments at high scopes, and ideally only through the pipeline’s identity. Protect the main branch, require review by the governance team, and have the pipeline use OIDC with a narrowly scoped identity. Treat any manual portal change at the top of the hierarchy as an incident.

i
Tip

Keep an “emergency stop” runbook. When a new Deny breaks something important, the on-call person should know exactly how to flip the assignment to DoNotEnforce or add a temporary exemption, and who must approve afterwards.

13Security: Protecting the Guardrails Themselves

Policy is a security tool, but it is also a powerful system that attackers or careless insiders could change. This chapter covers how to protect it and how to use it to protect everything else.

Who may do what with Policy

RoleWhat it allows
ReaderSee policy definitions, assignments, and compliance results
Resource Policy ContributorCreate and manage policy definitions, initiatives, assignments, and exemptions, but not general resources
OwnerEverything, including role assignments needed for managed identities of policy
Policy Insights Data WriterWrite compliance data, used by services that push attestations or machine configuration results
Security ReaderSee security-related policy results through Defender for Cloud

Some actions need more than one permission. Creating an assignment that uses Modify or DeployIfNotExists needs the right to create the assignment, and also the right to give roles to its managed identity. This split intentionally prevents a policy author from silently granting themselves wide powers.

Threats to the governance system

Threat

Disabling a rule

An attacker or careless admin switches a Deny to Disabled or sets DoNotEnforce, then creates forbidden resources.

Threat

Abusing exemptions

Exemptions quietly carve holes in coverage for risky resources.

Threat

Over-powerful identities

A remediation identity with broad Contributor rights can be a stepping stone to full control.

Threat

Malicious custom definitions

A DeployIfNotExists template could deploy something harmful using the identity’s permissions.

Threat

Moving subscriptions

Moving a subscription into a management group with weaker policy escapes stricter rules.

Threat

Hidden gaps

Resource types or properties that policy cannot see are never checked, giving a false sense of safety.

Defences

  • Least privilege. Limit Resource Policy Contributor and Owner at high scopes to a handful of people and one pipeline identity. Use time-limited elevation with Privileged Identity Management for humans.
  • Alert on changes. The Activity Log records changes to assignments, exemptions, and definitions. Send them to your monitoring system and alert on any change at high scopes outside the pipeline.
  • Protect management group moves. Restrict who can move subscriptions and who can create them.
  • Review remediation identities. Give them only the roles in the definition, and prefer user-assigned identities you can inventory.
  • Code review for custom templates. Treat DeployIfNotExists templates as privileged code.
  • Use resource locks and DenyAction for the most critical resources, such as the central log workspace and policy-related storage.
  • Cover the gaps. Combine Policy with Defender for Cloud, network controls, and regular configuration reviews.
Analogy

Protecting the policy system is like guarding the city’s rulebook archive. It is not enough to have strong rules; you must also ensure that nobody can quietly erase a rule, add a secret exception, or hand a master key to a repair crew without anyone noticing.

Using Policy to raise security everywhere

GoalTypical policy idea
No public exposure of dataDeny public network access on storage, databases, and key vaults; require private endpoints
EncryptionRequire encryption in transit, minimum TLS versions, and customer-managed keys where mandated
Safe networksDeny public IP addresses on network interfaces in certain groups; audit open management ports
Identity hygieneRequire managed identities, disable local authentication where supported
Logging and detectionDeploy diagnostic settings to a central workspace; require Defender plans
ResilienceRequire backups, soft delete, and purge protection for vaults
Supply chainAllow only images from approved registries in Kubernetes
!
Watch out

Policy results can mislead if you forget what is not covered. A green dashboard means “no violations of the rules we wrote, on the properties Azure exposes.” It does not mean the environment is secure. Keep testing, threat monitoring, and human review alive.

14Scale, Performance, and Cost

Policy runs on every resource request in your tenant. It is designed to be fast, but a poor design can still cause pain at scale.

Effect on deployments

Evaluation of a request happens within Azure Resource Manager and is generally fast. You rarely notice it. What you do notice are Deny messages that interrupt a deployment and the time taken by DeployIfNotExists remediation deployments that run after the main deployment. A pipeline that creates a resource and then immediately depends on a related resource that a policy will add later can fail, because the policy-created resource appears minutes afterwards. Design pipelines to create what they need explicitly, or to wait for policy effects.

Limits to keep in mind

AreaWhat to remember
Definitions per scopeThere is a documented maximum number of custom policy definitions and initiatives you can create at a given scope, in the hundreds
Assignments per scopeA documented maximum number of assignments per scope; initiatives help stay within it
Policies per initiativeA documented maximum, in the hundreds; very large initiatives are harder to manage
Rule size and complexityLimits on rule length and nesting of logical operators
Exemptions and exclusionsDocumented limits per assignment
Management group depthA documented maximum number of levels

Exact numbers are published in the Azure subscription and service limits documentation and are changed occasionally. Check them when designing a very large estate. If you approach limits, restructure: assign initiatives rather than single policies, and assign at higher scopes instead of repeating assignments.

Analogy

Policy evaluation is like a customs officer at a border checking each traveller against a list. A short, clear list is processed quickly. A list of thousands of overlapping and contradictory rules slows the line, confuses the officer, and causes more disputes at the gate. Keep the list focused.

Compliance data at scale

Large estates generate large compliance data sets. Use the portal for overviews and Azure Resource Graph for queries across subscriptions. For historical trends and executive dashboards, export compliance data to a data store or workbook, because the live view shows the current state and recent history only. Be patient after big changes; a new assignment on thousands of resources can take a while to produce full results.

Cost view

Free

Policy evaluation

Azure Policy for Azure resources has no separate charge for definitions, assignments, or compliance evaluation.

May cost

Resources policies create

DeployIfNotExists may create log settings, agents, or backup items, which are billed as normal resources.

May cost

Log volume

Auditing and diagnostic policies can send huge volumes of data to log workspaces, where ingestion is charged.

May cost

Hybrid and guest checks

Machine configuration for servers outside Azure, through Azure Arc, and some Defender plans may have their own pricing.

Saves

Cost control policies

Allowed VM sizes and regions, required cost tags, and deny rules on very expensive resource types prevent surprise bills.

Saves

Less manual work

Automated compliance reduces audit preparation time and avoids costly incidents.

Always verify current pricing on the official pages, since packaging of Defender and Arc features changes over time.

i
Tip

A powerful low-cost use of Policy is a short list of “cost guardrails”: restrict VM sizes in non-production, require cost-center and owner tags, forbid certain premium services in sandboxes, and audit orphaned disks and public IPs that nobody uses.

15Beyond Resource Settings: Kubernetes, Guest Configuration, and Data Planes

Azure Policy can reach beyond the outer properties of resources. It can inspect what runs inside clusters and servers, and it can control certain data operations.

Azure Policy for Kubernetes

Kubernetes is a system that runs many containers across a group of machines. In Azure, the managed version is Azure Kubernetes Service (AKS). Azure Policy can govern what is allowed inside a cluster by installing an add-on or extension that works with Gatekeeper, an open-source admission controller built on the Open Policy Agent. An admission controller is a gatekeeper that inspects every request to run something in the cluster before it is accepted. Policies can then forbid privileged containers, require resource limits, allow only images from approved registries, block public load balancers, or require certain labels. Results appear in the same compliance dashboard as Azure resource policies.

Analogy

Azure resource policies check the outside of the apartment building: how many floors, what colour, where the entrance is. Kubernetes policies check the rules for each flat inside, such as no open flames and no blocked fire exits. Different inspectors, same rulebook and same report.

Machine configuration (formerly Guest Configuration)

Some important settings live inside a server’s operating system, such as password rules, installed software, or firewall state, and are invisible to the Azure control surface. Azure Machine Configuration (earlier called Guest Configuration) uses an agent on Azure virtual machines and on servers connected via Azure Arc to check these settings and report them back as policy compliance. Built-in policies cover common security baselines, and you can author custom configurations. Some policies can also apply a configuration, not just audit. Because these checks run on the machine itself, they need the agent and a managed identity, and they add some load to servers.

Resource provider modes and data-plane control

Most policies govern the control plane, the operations that create and configure resources. A few services expose a data plane, the operations that work with the data itself. Resource provider modes allow policy for some of these. For example, policies can govern key properties in Key Vault, such as secret expiry or key types, and they can restrict certain network data operations. Support differs by service and changes over time, so check documentation for the one you need.

LayerWhat is checkedMechanismExample
Azure control planeResource properties as created and updatedStandard policy modesStorage accounts must disable public access
Data plane in selected servicesObjects inside a serviceResource provider modesKey Vault secrets must have an expiry date
Inside KubernetesPods, services, ingress rulesAdd-on with GatekeeperContainers must not run as privileged
Inside serversOperating system settingsMachine configuration agentPassword complexity must be enabled

Policy with Azure Arc and hybrid estates

Azure Arc projects servers, Kubernetes clusters, and databases running elsewhere, such as on-premises or in another cloud, into Azure as manageable resources. Once projected, Azure Policy can assess them with the same rules and dashboards. This gives one governance view over a hybrid estate, though supported policies and features differ between Azure-native and Arc-enabled resources.

!
Watch out

Add-ons and agents are extra software on your clusters and servers. They need updates, resource capacity, and monitoring. In a Kubernetes cluster, a strict admission policy can block system or third-party components, so roll out in audit mode first and exclude well-known system namespaces carefully.

16Monitoring, Reporting, and Troubleshooting

A guardrail system must be observed. You need to know what it blocks, what it finds, and why something behaves unexpectedly.

Where to look

Portal

Policy compliance dashboard

Overall percentage, per-assignment compliance, resource lists, and reasons for non-compliance.

Query

Azure Resource Graph

Fast queries across subscriptions for policy states, such as all non-compliant resources by policy and owner tag.

Log

Activity Log

Records denies, audit events, assignment changes, and remediation actions with timestamps and callers.

Alert

Azure Monitor alerts

Notify teams on policy changes at high scopes or on spikes in denial events.

Events

Event Grid

Publishes policy state change events that automation can react to, for instance by opening a ticket.

Security

Defender for Cloud

Presents policy-based assessments as security recommendations and secure score.

Useful reports

  • Compliance percentage by management group, subscription, and owner team, trended over time.
  • Top ten non-compliant policies and top ten teams with findings.
  • Exemptions list with expiry dates and reasons.
  • Denied deployments per week, to see whether a rule is causing friction.
  • Remediation task success rate.
  • Changes to definitions and assignments, with who changed them.

Common problems and their usual causes

What you seeUsual causeWhat to do
Deployment fails with a RequestDisallowedByPolicy errorA Deny rule matched the requestRead the error: it names the assignment and definition. Fix the property or request an exemption
Policy assigned but nothing shows non-compliantEvaluation still running, wrong scope, mode excludes the type, or the rule condition is wrongWait, check the scope and mode, trigger an on-demand scan, and test the condition on a known bad resource
Everything shows non-compliant for a tag ruleMode All applies to types that cannot hold tagsUse Indexed mode for tag and location rules
Remediation task failsThe managed identity lacks required roles, template errors, or resource state problemsCheck role assignments listed in the definition and the per-resource error
DeployIfNotExists never deploysNo managed identity, no roles, or existence condition always evaluates trueVerify the identity, roles, and the details block of the effect
Cannot edit an old resourceThe existing resource breaks a Deny rule, so any update is evaluated and rejectedFix the offending property in the same update, or use an exemption
Assignment fails with missing parametersRequired parameters have no defaultSupply values, or add defaults to the definition
Rule behaves differently from expectationsAlias refers to a different property, case sensitivity, or null versus missing valueInspect the resource JSON and the alias, and test with sample resources
Compliance data seems staleNormal evaluation delayTrigger an on-demand scan and wait a few minutes
Conflicting policies cause failuresTwo policies require different values, such as two Modify policies setting the same tag differentlyAlign the policies or remove duplication
Pipeline fails on newly created resourcesPolicy added or changed a property, causing a mismatch with the templateUpdate templates to match, or use Audit during transition

A calm method for investigating

1

Read the message

Denial errors identify the policy assignment ID. Start there.

2

Open the definition and assignment

Read the rule, parameters, scope, and mode. Ask what condition the resource matched.

3

Compare with the resource

Look at the actual resource properties. Use the compliance details, which show the evaluated field values.

4

Decide: fix the resource, the rule, or grant an exemption

If the rule is right, fix the request. If the rule is wrong, change it through the normal pipeline. If a legitimate exception exists, record an exemption.

5

Capture what you learned

Improve the non-compliance message, update documentation, and add a test case.

i
Tip

Treat denied-deployment counts as a user-experience metric. A rule that produces many denials may be confusing or poorly communicated. Improving messages and documentation is often a better fix than loosening the rule.

17Choosing the Right Tool: Policy and Its Companions

Azure Policy is one tool among several. Using each for what it does best gives a stronger and simpler governance design.

flowchart TD
  Q["What do you want to control"] --> A{"Who can do an action"}
  A -->|"Yes"| RBAC["Azure RBAC and Privileged Identity Management"]
  A -->|"No"| B{"What a resource may look like"}
  B -->|"Yes"| POL["Azure Policy"]
  B -->|"No"| C{"Prevent accidental delete or change of one resource"}
  C -->|"Yes"| LOCK["Resource locks or DenyAction"]
  C -->|"No"| D{"Find threats and weaknesses"}
  D -->|"Yes"| DEF["Microsoft Defender for Cloud"]
  D -->|"No"| E{"Standardise how resources are deployed"}
  E -->|"Yes"| TPL["Templates, template specs, deployment stacks"]
  E -->|"No"| F{"Control spending"}
  F -->|"Yes"| COST["Budgets and Cost Management plus cost policies"]
  F -->|"No"| G["Review other governance options"]
Figure 17.1: Which Azure governance feature fits which question

Each tool in its lane

NeedBest fitWhy
Decide who can create or delete resourcesAzure RBAC with Privileged Identity ManagementPolicy does not look at who is acting
Block public storage or unapproved regionsAzure Policy with DenyResource property rule, at scale
Add missing tags or diagnostics automaticallyAzure Policy with Modify or DeployIfNotExistsAutomatic repair, including existing resources through remediation
Stop deletion of a specific critical resourceResource lock, or DenyAction policyDirect protection of an individual item
Detect attacks and weaknessesMicrosoft Defender for CloudThreat detection, secure score; builds on policy results
Create standard environmentsTemplates, template specs, deployment stacks, landing zone acceleratorsCreation is different from continuous enforcement
Alert on spendingCost Management budgetsPolicy cannot see bills, only configurations
Query inventoryAzure Resource GraphFast, flexible search across subscriptions
!
Watch out

Microsoft has announced the retirement of Azure Blueprints and recommends other tools, such as template specs and deployment stacks, together with policy and landing zone accelerators. If you still use Blueprints, check the current retirement timeline and plan a migration.

Policy and other clouds

If your company uses more than one cloud, remember that Azure Policy governs Azure and Arc-connected resources. Other clouds have their own equivalents, such as service control policies and organisation policies, and there are third-party tools and open standards such as Open Policy Agent that work across environments. Many multi-cloud teams use each cloud’s native guardrails for enforcement and a central tool for reporting. Azure Policy remains the most direct way to enforce rules on Azure resource requests.

Questions to settle the design

  • Which rules must be absolutely enforced, and which are advisory?
  • Which regulations or internal standards apply, and which evidence do auditors need?
  • Who owns each rule, and how do engineers request exceptions?
  • How will changes be tested, approved, and rolled back?
  • Which resources or properties are outside what policy can see, and how will you cover them?

18Patterns and Anti-Patterns

Teams that govern Azure well repeat a few good designs. Teams that struggle repeat a few familiar mistakes. Knowing both saves months.

Patterns that work

Pattern

Audit first, then Deny

Measure impact, give teams time and clear instructions, then enforce. Effects are parameters so the switch is a small reviewed change.

Pattern

Few, high-level baselines

A small set of truly universal rules assigned at the company top group, with workload-specific rules lower down.

Pattern

Initiatives over single assignments

Group rules by theme and owner, so assignments stay few and reporting stays readable.

Pattern

Repair, don’t just reprimand

Use Modify and DeployIfNotExists for safe fixes such as tags and diagnostics, so engineers are not buried in tickets.

Pattern

Time-boxed exemptions

Every exception has a reason, an owner, an approval, and an expiry date, and is reviewed regularly.

Pattern

Policy as code

Definitions and assignments live in Git, flow through review and automated deployment, and can be rolled back.

Pattern

Sandbox for experiments

A lightly governed area with budget limits lets engineers learn without blocking production-grade rules.

Pattern

Friendly messages and docs

Every denial points to a page explaining the standard and how to comply or ask for help.

Habits compared

Healthy habits

  • Start from built-in definitions
  • Test with DoNotEnforce in real scopes
  • Track owners for every initiative
  • Review exemptions and expiries monthly
  • Alert on changes at high scopes

Habits that hurt

  • Turning on Deny everywhere on day one
  • Hundreds of one-off assignments in the portal
  • Permanent exclusions with no reasons
  • Remediation identities with Owner rights
  • Treating a green dashboard as proof of security

Four decisions worth recording

Teams that write down their key decisions avoid arguing about them again a year later. These short records use the common format of context, decision, and consequences. They are illustrative examples, not mandates.

ADR-1Example: Accepted

Roll out new rules in Audit, then Deny after a 30-day notice period. Context: a previous rule denied all public IP addresses and blocked an urgent release on a Friday evening. Decision: every new Deny rule is first assigned in Audit with the owner list published, then switched after 30 days. Consequences: fewer surprises and better trust; enforcement is delayed by a month, and a tracking process is needed.

ADR-2Example: Accepted

Use exemptions, not exclusions, for exceptions. Context: three subscriptions had been excluded from a security initiative years ago and nobody remembered why. Decision: exclusions are forbidden except for platform plumbing; all other exceptions are recorded as exemptions with category, ticket reference, and expiry. Consequences: exceptions are visible and expire; the governance team must run a monthly review.

ADR-3Example: Accepted

Manage all policy objects through a pipeline with a dedicated deployment identity. Context: portal edits at the top management group caused two incidents. Decision: only the pipeline identity can write policy at high scopes; humans have read access and time-limited elevation for emergencies. Consequences: reliable history and review; emergency changes require an elevation process that must be rehearsed.

ADR-4Example: Proposed

Adopt built-in regulatory initiatives unchanged, with parameters and exemptions for differences. Context: copied initiatives drifted from the originals and missed new controls. Decision: assign the built-in version where possible and avoid copying. Consequences: updates flow in automatically; less flexibility, and new checks may add noise that must be triaged.

19Best Practices and Common Mistakes

This chapter gathers the advice of the whole book into one checklist to use before launch, during reviews, and after incidents.

Best practices

1

Design the hierarchy first

Create a clean management group structure and subscription strategy before writing many policies.

2

Prefer built-in definitions

They are maintained by Microsoft and understood by auditors. Write custom rules only for real gaps.

3

Assign initiatives at high scopes

One assignment covers many subscriptions, including future ones.

4

Parameterise the effect

Move easily between Audit, Deny, and Disabled without rewriting definitions.

5

Test before enforcing

Use sandboxes, DoNotEnforce, and impact reports, and communicate dates to teams.

6

Remediate safely

Use narrow roles, small first batches, and avoid auto-fixing risky settings.

7

Manage as code

Git, reviews, pipelines, and a rollback plan for every change.

8

Control exceptions

Exemptions with reasons and expiry dates, reviewed regularly, and limited rights to create them.

9

Monitor and report

Compliance trends by team, denial counts, exemption lists, and alerts on changes to governance objects.

10

Teach and document

Publish a standards page, explain the why behind each rule, and make it easy to ask for help.

Common mistakes

MistakeConsequenceBetter approach
Deny on day oneBlocked releases, angry teams, pressure to remove governanceAudit first, communicate, then enforce
Assigning at the tenant root without testingCompany-wide outage of deploymentsTest lower, assign carefully, keep a rollback ready
Writing the “if” for the good conditionThe rule blocks compliant resourcesDescribe the problem in the “if” and test with samples
Mode All for tag and location rulesFalse non-compliance on types without tagsUse Indexed where appropriate
Forgetting roles for managed identitiesDeployIfNotExists and Modify silently failAssign the roles listed in the definition
Too many tiny assignmentsHit limits, confusing reportsUse initiatives and higher scopes
Permanent exclusionsSilent gaps in coverageTime-boxed exemptions
Assuming compliance means securityUnchecked gapsCombine with threat detection, reviews, and testing
Ignoring existing resourcesLarge non-compliant backlog, blocked editsPlan remediation or cleanup alongside new rules
Copying built-in initiatives and never updatingMissing new controlsAssign originals; review any copies regularly
Pipelines unaware of policySurprise failures and drift between templates and policy resultsAlign templates to standards; run policy checks in pipelines
No owner for each ruleNobody can answer why it exists or change itName an owner and a review date in metadata
A good guardrail feels like a clear road with a gentle barrier, not like a locked gate with no sign. People should know where the road goes and why the barrier is there.

20Real-World Scenarios

The following scenarios are invented illustrations built from common situations. They are not case studies of real companies, and the numbers are examples chosen to make the ideas concrete.

Scenario 1: A mid-size company cleans up tagging and costs

Situation. An imagined company with 25 Azure subscriptions cannot tell which team owns what. Finance spends two days each month matching bills to teams.

Design. The governance team assigns an initiative at the company top group. A Modify policy copies cost-center and owner tags from resource groups to resources. An Audit policy flags resource groups missing those tags. After 30 days, a Deny policy blocks new resource groups without them. A remediation task fixes the existing resources in batches.

Outcome. Tag coverage rises from about half to nearly all resources, cost reports are accurate, and the monthly matching task disappears. Engineers rarely notice the policy, because the tags appear automatically.

Scenario 2: A healthcare provider proves compliance

Situation. An imagined healthcare provider must show auditors that patient-data systems are encrypted, private, logged, and located in approved regions.

Design. The team assigns a built-in regulatory initiative and their own initiative to the management group holding regulated subscriptions. Deny policies forbid public endpoints and unapproved regions. DeployIfNotExists policies enable diagnostic logging to a central workspace. Manual policies record staff training attestations. Compliance exports are saved every month as evidence.

Outcome. The audit preparation time falls from weeks to days. The team also learns that the dashboard covers only part of the controls, so they keep separate process evidence for the rest.

Scenario 3: A start-up builds guardrails early

Situation. An imagined start-up with eight engineers and three subscriptions wants good habits before growth.

Design. They create a simple management group tree with Production and Sandbox groups. They assign the built-in security benchmark in Audit mode at the top, a few Deny policies on public storage and allowed regions for Production, and VM size limits for Sandbox. Policies live in a Git repository and deploy through a pipeline.

Outcome. Costs stay predictable, and when the company later gains enterprise customers who ask for security evidence, the structure is already in place.

Scenario 4: A bank handles an incident caused by a rule

Situation. An imagined bank assigns a Deny policy on public IP addresses. The next morning, a trading support team cannot create a diagnostic virtual machine during an outage.

Design. The on-call engineer follows the runbook. The denial message identifies the policy and links to the standards page. The engineer requests a time-limited exemption, approved by the security duty manager, with a four-hour expiry. The pipeline later records the exemption in Git. The governance team reviews the case and adds a documented, secure remote-access alternative using a bastion service.

Outcome. The outage is resolved quickly, the exception is visible and temporary, and the lesson improves the standard.

21Frequently Asked Questions

Short answers to the questions beginners ask most often.

Q1 What is Azure Policy in one sentence?
It is an Azure service that lets you write rules about how resources must be configured, then automatically blocks, flags, or fixes resources that break them, and reports how well everything complies.
Q2 What is the difference between Azure Policy and RBAC?
RBAC controls what people and applications are allowed to do. Policy controls what the resources themselves are allowed to look like. You need both.
Q3 What is an initiative?
A bundle of policy definitions managed together, such as a security baseline or a regulatory standard. You assign the bundle once instead of each rule separately.
Q4 What is the difference between Audit and Deny?
Audit lets the action happen but marks the resource non-compliant. Deny rejects the request so the resource cannot be created or changed in that way.
Q5 Does a Deny policy delete existing resources?
No. It affects new and updated resources. Existing resources that violate the rule are shown as non-compliant, and updates to them may be blocked until the violation is fixed.
Q6 How long does it take for a new policy to take effect?
Deny, Modify, and Append apply to new requests soon after the assignment becomes active, often within minutes. Evaluating existing resources can take longer, commonly from several minutes to well over half an hour in large scopes, and a full compliance cycle runs about daily.
Q7 Can Azure Policy fix problems automatically?
Yes. Modify and DeployIfNotExists can change settings or deploy missing related resources. For resources that already exist, you run a remediation task, using the assignment’s managed identity.
Q8 What is a managed identity used for in a policy assignment?
It is the identity that Modify and DeployIfNotExists use to make changes. It needs the roles listed in the policy definition, and it should have only those roles.
Q9 What is the difference between an exclusion and an exemption?
An exclusion removes a child scope from an assignment and leaves no record of why. An exemption is a separate, documented waiver with a category, a reason, and optionally an expiry date, and the resource still shows in reports as exempt.
Q10 At which level should I assign policies?
As high as is sensible. Company-wide rules go on a top management group, and workload-specific ones on lower groups or subscriptions. Avoid scattering identical assignments across many small scopes.
Q11 Can I test a policy without blocking anyone?
Yes. Assign it with the DoNotEnforce enforcement mode, or use Audit as the effect, then read the compliance results. Switch to enforcement after you understand the impact.
Q12 Should I write custom policies or use built-in ones?
Use built-in policies first. They are maintained for you and recognised by auditors. Write custom ones when no built-in rule fits your standard.
Q13 Does Azure Policy cost money?
Policy evaluation for Azure resources has no separate charge. Resources that policies deploy, log ingestion they cause, and some related capabilities such as machine configuration for non-Azure servers or Defender plans can have costs. Check current pricing pages.
Q14 Can Azure Policy govern Kubernetes and servers?
Yes. An add-on based on Gatekeeper can enforce rules inside Kubernetes clusters, and machine configuration can check settings inside virtual machines and Arc-enabled servers.
Q15 If my compliance dashboard is 100 percent green, am I secure?
Not necessarily. It means no violations of the rules you assigned, for the properties policy can see. Keep threat detection, reviews, and testing in place.
Q16 Why was my deployment rejected?
The error message includes the policy assignment that denied it. Open it, read the rule, compare it with your resource settings, and either fix the setting or request an exemption.
Q17 Is Azure Blueprints the same as Azure Policy?
No. Blueprints packaged policies, roles, and templates together for environments. Microsoft has announced its retirement and points to other tools, so check current guidance. Azure Policy itself remains a core governance service.
Q18 What is the best way to learn it?
In a sandbox subscription, assign a built-in “allowed locations” policy and try to create a resource elsewhere. Then assign a tag policy in Audit, read the compliance report, switch it to Modify, and run a remediation task. Doing this loop once teaches more than reading about each piece separately.

22Summary and Key Takeaways

You began with an apartment complex that could not be inspected by hand. You now have the blueprint for building the rules into the building itself.

Azure Policy evaluates the shape of resources, not the rights of people. A rule has a condition and an effect, rules are grouped into initiatives, and assignments attach them to scopes in the management group hierarchy, where they flow downward to everything beneath. Deny prevents, Audit reveals, Modify and DeployIfNotExists repair, and exemptions record justified exceptions. Remediation tasks fix the past, and policy as code with staged rollout keeps the system itself safe. Around all this sit the disciplines of good design: a clean hierarchy, careful scoping, friendly messages, monitoring, and humility about what the dashboard cannot see.

Key takeaways

  • Policy governs resources; RBAC governs people. Use both, each in its own lane.
  • Know the effects. Deny stops, Audit flags, Modify and DeployIfNotExists fix, Manual records attestations, and the evaluation order matters.
  • Assign high, inherit down. Design the management group hierarchy so that a few assignments cover many subscriptions, including future ones.
  • Roll out gently. Audit and DoNotEnforce first, communicate, then enforce, and keep a rollback path.
  • Use exemptions, not silent exclusions. Every exception needs a reason, an owner, and an expiry date.
  • Treat policy as code and protect it. Git, reviews, pipelines, least privilege, and alerts on changes to governance objects.
  • Don’t confuse green with safe. Compliance shows the rules you wrote on the properties policy can see; combine it with threat detection and human review.
i
Where to go next

Build a small project in a sandbox: create a management group with one test subscription, assign a built-in security initiative in Audit mode, add an allowed-locations Deny and a tag-inheritance Modify, run a remediation task, and put the assignments in a Git repository with a pipeline. Then read the current Microsoft documentation for details that change quickly, such as limits, supported effects per resource type, and newly available built-in initiatives.