Enforcing Standards with Azure Policy
This lesson explains Azure Policy: definitions, assignments and initiatives, policy effects and remediation, and how Azure Policy differs from Azure RBAC.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the purpose of Azure Policy.
- Distinguish policy definitions, assignments and initiatives.
- Explain common policy effects and the difference between Azure Policy and Azure RBAC.
What Azure Policy does
Azure Policy is a service in Azure that enables you to create, assign and manage policies that control or audit resources. Policies enforce different rules across resource configurations so that those configurations stay compliant with corporate standards, for example allowing only certain VM sizes, requiring encryption, limiting resources to approved regions or requiring a tag. Azure Policy evaluates resources when they are created or changed and regularly afterwards, and shows the results in a compliance dashboard.
Definitions, assignments and initiatives
Azure Policy is built from three concepts. The following table describes them.
| Concept | Description | Example |
|---|---|---|
| Policy definition | A rule: the condition to evaluate and the effect to apply, written in JSON | Allowed locations; Require a tag on resources |
| Policy assignment | Applies a definition to a scope (management group, subscription, resource group), optionally excluding child scopes | Assign Allowed locations to the Europe management group |
| Initiative | A group of related policy definitions managed and assigned as a single unit | A regulatory standard such as ISO 27001, or a set of tagging rules |
Azure includes hundreds of built-in policy definitions and initiatives, and organizations can write custom definitions. Assignments are inherited: a policy assigned to a management group applies to every subscription, resource group and resource beneath it. Many policies take parameters, such as the list of allowed regions, so one definition can be reused with different values.
Policy effects
The effect determines what happens when a resource does not comply. Common effects include:
- Deny: blocks a create or update request that would make a resource non-compliant, so the resource is never created.
- Audit: allows the request but marks the resource as non-compliant in the compliance dashboard and activity log.
- Append and Modify: change the request, for example adding a tag or a setting, so that the resource complies.
- DeployIfNotExists and AuditIfNotExists: check for a related resource or setting, such as a diagnostic setting or an agent, and deploy it or report its absence.
Existing resources that were created before a policy was assigned are evaluated and reported, but Deny does not delete them. For policies with Modify or DeployIfNotExists effects, a remediation task can fix existing non-compliant resources.
Choose the policy effect
Azure Policy beyond single resources
Azure Policy integrates with Azure DevOps and other pipelines by applying continuous integration and delivery policies to pre-deployment and post-deployment phases. It can also govern servers and Kubernetes clusters outside Azure that are connected through Azure Arc, and it can audit settings inside machines with machine configuration. Azure Policy differs from Azure RBAC: RBAC controls who can perform actions, while Policy controls what configurations are allowed, whoever performs the action, even an Owner.
RBAC or Policy?
Enforcing allowed regions
A company's data must stay in Europe. Its administrators are subscription Owners and sometimes create resources in US regions by mistake. The company wants such deployments blocked in all of its subscriptions, and a report of any existing resources outside Europe. What should it do?
Assign the built-in Allowed locations policy, with European regions as the parameter, to a management group that contains all subscriptions. Its Deny effect blocks new resources in other regions, even for Owners, and the compliance dashboard reports existing resources outside Europe as non-compliant. Azure RBAC cannot restrict which region an Owner chooses, and a resource lock prevents deletion or changes rather than controlling where resources are created.
What is an initiative in Azure Policy?
Show answer
A group of related policy definitions that is managed and assigned as a single unit.
Exam Tips
Remember for the exam
- Azure Policy enforces and audits rules on resource configurations, such as allowed regions or required tags.
- Definitions are assigned to scopes and inherited; initiatives group related definitions.
- Deny blocks non-compliant requests; Audit reports them; Modify and DeployIfNotExists can fix them.
- RBAC controls who can act; Policy controls what configurations are allowed, even for Owners.