Azure Policy has been available for some time now, but for folks getting start with Cloud Governance, Azure Policy is a service in Azure that allows you to manage, assign, and create custom policies. These policies can be used to enforce a global set of rules or specific set of controls for a specific environments, ie. less control and governance in a “development” environment. This allows resources to stay compliant with you enterprise standards. Azure policies can enforce different rules, from Denying specific services, for example, ensuring only resources are built within a specific region, ie. resources can only be built within the Canadian regions. Conversely, rather than enforcing, policies can also be configured to Audit, where resources will be marked if they are not compliant, for example, a Storage Account is not configured with secure transfer.
Before diving into the policy itself, I want to quick go over the types of conditions that are available, and that can be used to enforce different compliance rules. The following table shows how different policy effects work with the condition evaluation for the resulting compliance state. Although you don’t see the evaluation logic in the Azure portal, the compliance state results are shown. The compliance state result is either compliant or non-compliant.
Resource State | Effect | Policy Evaluation | Compliance State |
Exists | Deny, Audit, Append, DeployIfNotExist, AuditIfNotExist* | True | Non-Compliant |
Exists | Deny, Audit, Append, DeployIfNotExist, AuditIfNotExist* | False | Compliant |
New | Audit, AuditIfNotExist* | True | Non-Compliant |
New | Audit, AuditIfNotExist* | False | Compliant |
- *The Append, DeployIfNotExist, and AuditIfNotExist effects require the IF statement to be TRUE. The effects also require the existence condition to be FALSE to be non-compliant. When TRUE, the IF condition triggers evaluation of the existence condition for the related resources.
Source: https://docs.microsoft.com/en-us/azure/governance/policy/assign-policy-portal
In this example today, I want to show a real world example, where a customer recently asked to monitor any changes being made to their UDRs (User Defined Routes/Routing).
The following will continuously monitor all UDRs in the environment. If any changes are made to a single UDR table, it will be audited and its changes will be tracked. Once the policy is enabled, you can see it in action by creating/modifying a UDR.
“policyRule”: {
“if”: {
“anyOf”: [
{
“source”: “action”,
“like”: “Microsoft.Network/routeTables/*”
}
]
},
“then”: {
“effect”: “audit”
}
}
See below for the compliance once a change has been made to a UDR. Once you drill down to the event, the user, the activity log, you can then see the exact changes that were made to the UDR.
I hope this was helpful!