Skip to content

Part 6: Azure Policy

Source: John Savill's Azure Master Class v3 - Part 3: Governance
Video Timestamps: 1:18:00 - 1:32:00
AZ-104 Relevance: ⭐⭐⭐⭐⭐ CRITICAL - Heavily tested


What is Azure Policy?

Azure Policy enforces rules on resources. Unlike RBAC (WHO can do WHAT), Policy controls HOW resources can exist.

Key Concept: Even an Owner can be blocked by Policy!


Policy Flow


Policy Definition

A definition is the rule written in JSON.

Structure

json
{
  "if": {
    "field": "type",
    "equals": "Microsoft.Storage/storageAccounts"
  },
  "then": {
    "effect": "deny"
  }
}

Translation: IF resource type is storage account, THEN deny.

Fields You Can Check

FieldExample
typeResource type (Microsoft.Storage/storageAccounts)
locationRegion (eastus, westeurope)
tagsAny tag value
properties.*Any resource property (SKU, settings)

Policy Effects

EffectBehavior
DenyBlock non-compliant creation/update
AuditAllow but flag as non-compliant
AuditIfNotExistsAudit if related resource missing
DeployIfNotExists (DINE)Auto-deploy missing related resource
ModifyChange properties during create/update
DisabledPolicy exists but doesn't run
AppendAdd properties (deprecated, use Modify)

Evaluation Order

Important: Deny is evaluated BEFORE the resource is created. DINE runs AFTER.


Common Policy Scenarios

ScenarioEffectExample
Block public storageDenyPrevent storage with public access
Require tagsDenyMust have costCenter tag
Allowed locationsDenyOnly eastus and westeurope
Audit unencryptedAuditFlag VMs without disk encryption
Add tagsModifyAuto-add createdBy tag
Deploy diagnosticsDINEAuto-enable logging

Policy Assignment

A definition does nothing until assigned.

Assignment Components

ComponentDescription
Policy/InitiativeWhat rule(s) to apply
ScopeWhere (MG, Sub, RG)
ExclusionsWhat to skip
ParametersValues for the policy
Non-compliance messageCustom error text

Assignment Flow


Initiatives (Policy Sets)

An initiative bundles multiple policies together.

Why? Easier to assign one initiative than 50 individual policies.

Built-in Initiatives

InitiativePurpose
Azure Security BenchmarkMicrosoft's security best practices
CIS BenchmarkIndustry security standard
ISO 27001Compliance framework
NIST SP 800-53US government standard

Policy Exemptions

When a resource legitimately can't comply, use an exemption.

Exemption Types

TypeDuration
WaiverPermanent exception
MitigatedCompliance achieved another way

Exemptions can have expiry dates.


Policy Evaluation

When Policies Run

TriggerTiming
Resource create/updateImmediate
Policy assignmentWithin 30 minutes
Full evaluation cycleEvery 24 hours
On-demandManual trigger

Compliance States

StateMeaning
CompliantPasses all applicable policies
Non-compliantFails one or more policies
ExemptHas an exemption
UnknownNot yet evaluated

Viewing Compliance

Portal → Policy → Compliance

Shows:

  • Overall compliance percentage
  • Non-compliant resources
  • Which policies they fail

Remediation Tasks

For Modify and DINE policies, existing non-compliant resources need remediation.

How Remediation Works

  1. Policy deployed with DINE effect
  2. Existing resources flagged non-compliant
  3. Create remediation task
  4. Task runs to fix existing resources
  5. New resources auto-fixed at creation

Managed Identity Requirement

DINE and Modify policies need a managed identity to make changes. The identity needs permissions to perform the remediation actions.


Policy vs RBAC

AspectRBACPolicy
ControlsWHO can do actionsHOW resources must be configured
DenyNo deny capabilityCan deny
DefaultDeny (must grant access)Allow (must add restrictions)
Applied toUsers/appsResources
InheritanceDown the hierarchyDown the hierarchy

Remember: RBAC is about identity, Policy is about resources.


Mental Model

Policy = Building Code Inspector 👷

  • You have permission to build (RBAC = building permit)
  • But inspector checks: "Is this up to code?"
  • Non-compliant? Can't build (Deny) or get flagged (Audit)
  • Some inspectors auto-fix issues (Modify/DINE)

Initiative = Inspection Checklist 📋

  • Multiple code requirements bundled together
  • Pass the checklist = compliant building

AZ-104 Exam Tips

TopicKey Point
Policy vs RBACPolicy = resources, RBAC = identities
Effects orderDisabled → Append → Modify → Deny → Audit → DINE
DINERuns AFTER resource creation
InitiativeCollection of policies
ExemptionWaiver (permanent) vs Mitigated
ComplianceEvaluated every 24 hours + on changes
RemediationRequired for existing resources with DINE/Modify

Practical Exercises

Exercise 1: View Built-in Policies (5 min)

  1. Portal → PolicyDefinitions
  2. Filter by Category: Tags
  3. Find "Require a tag on resources" - review the JSON

Exercise 2: View Compliance (3 min)

  1. Portal → PolicyCompliance
  2. See overall compliance percentage
  3. Click a non-compliant policy to see affected resources

Exercise 3: Assign a Policy (10 min)

  1. Portal → PolicyAssign policy
  2. Scope: Your test resource group
  3. Policy: "Allowed locations"
  4. Parameter: Select only one region
  5. Try creating a resource in a different region - watch it fail

End of Part 6

Released under the MIT License.