|
| 1 | +--- |
| 2 | +title: Azure Policy compliance states |
| 3 | +description: This article describes the concept of compliance states in Azure Policy. |
| 4 | +ms.date: 04/05/2023 |
| 5 | +ms.topic: conceptual |
| 6 | +--- |
| 7 | + |
| 8 | +# Azure Policy compliance states |
| 9 | + |
| 10 | +## How compliance works |
| 11 | + |
| 12 | +When initiative or policy definitions are assigned, Azure Policy determines which resources are [applicable](./policy-applicability.md) then evaluates those which haven't been [excluded](./assignment-structure.md#excluded-scopes) or [exempted](./exemption-structure.md). Evaluation yields **compliance states** based on conditions in the policy rule and each resources' adherence to those requirements. |
| 13 | + |
| 14 | +## Available compliance states |
| 15 | + |
| 16 | +### Non-compliant |
| 17 | + |
| 18 | +Policy assignments with `audit`, `auditIfNotExists`, or `modify` effects are considered non-compliant for _new_, _updated_, or _existing_ resources when the conditions of the policy rule evaluate to **TRUE**. |
| 19 | + |
| 20 | +Policy assignments with `append`, `deny`, and `deployIfNotExists` effects are considered non-compliant for _existing_ resources when the conditions of the policy rule evaluate to **TRUE**. _New_ and _updated_ resources are automatically remediated or denied at request time to enforce compliance. When a previously existing non-compliant resource is updated, the compliance state remains non-compliant until the resource deployment and Policy evaluation complete. |
| 21 | + |
| 22 | +> [!NOTE] |
| 23 | +> The DeployIfNotExist and AuditIfNotExist effects require the IF statement to be TRUE and the |
| 24 | +> existence condition to be FALSE to be non-compliant. When TRUE, the IF condition triggers |
| 25 | +> evaluation of the existence condition for the related resources. |
| 26 | +
|
| 27 | +Policy assignments with `manual` effects are considered non-compliant under two circumstances: |
| 28 | +1. The policy definition has a default compliance state of non-compliant and there is no active [attestation](./attestation-structure.md) for the applicable resource stating otherwise. |
| 29 | +1. The resource has been attested as non-compliant. |
| 30 | + |
| 31 | +To determine |
| 32 | +the reason a resource is non-compliant or to find the change responsible, see |
| 33 | +[Determine non-compliance](../how-to/determine-non-compliance.md). To [remediate](./remediation-structure.md) non-compliant resources for `deployIfNotExists` and `modify` policies, see [Remediate non-compliant resources with Azure Policy](../how-to/remediate-resources.md). |
| 34 | + |
| 35 | +### Compliant |
| 36 | + |
| 37 | +Policy assignments with `append`, `audit`, `auditIfNotExists`, `deny`, `deployIfNotExists`, or `modify` effects are considered compliant for _new_, _updated_, or _existing_ resources when the conditions of the policy rule evaluate to **FALSE**. |
| 38 | + |
| 39 | +Policy assignments with `manual` effects are considered compliant under two circumstances: |
| 40 | +1. The policy definition has a default compliance state of compliant and there is no active [attestation](./attestation-structure.md) for the applicable resource stating otherwise. |
| 41 | +1. The resource has been attested as compliant. |
| 42 | + |
| 43 | +### Error |
| 44 | + |
| 45 | +The error compliance state is given to policy assignments that generate a system error, such as template or evaluation error. |
| 46 | + |
| 47 | +### Conflicting |
| 48 | + |
| 49 | +A policy assignment is considered conflicting when there are two or more policy assignments existing in the same scope with contradicting or conflicting rules. For example, two definitions that append the same tag with different values. |
| 50 | + |
| 51 | +### Exempt |
| 52 | + |
| 53 | +An applicable resource has a compliance state of exempt for a policy assignment when it is in the scope of an [exemption](./exemption-structure.md). |
| 54 | + |
| 55 | +> [!NOTE] |
| 56 | +> _Exempt_ is different than _excluded_. For more details, see [scope](./scope.md). |
| 57 | +
|
| 58 | +### Unknown (preview) |
| 59 | + |
| 60 | + Unknown is the default compliance state for definitions with `manual` effect, unless the default has been explicitly set to compliant or non-compliant. This state indicates that an [attestation](./attestation-structure.md) of compliance is warranted. This compliance state only occurs for policy assignments with `manual` effect. |
| 61 | + |
| 62 | +### Not registered |
| 63 | + |
| 64 | +This compliance state is visible in portal when the Azure Policy Resource Provider hasn't been registered, or when the account logged in doesn't have permission to read compliance data. |
| 65 | + |
| 66 | +> [!NOTE] |
| 67 | +> If compliance state is being reported as **Not registered**, verify that the |
| 68 | +> **Microsoft.PolicyInsights** Resource Provider is registered and that the user has the appropriate Azure role-based access control (Azure RBAC) permissions as described in |
| 69 | +> [Azure RBAC permissions in Azure Policy](../overview.md#azure-rbac-permissions-in-azure-policy). |
| 70 | +> To register Microsoft.PolicyInsights, [follow these steps](../../../azure-resource-manager/management/resource-providers-and-types.md). |
| 71 | +
|
| 72 | +### Not started |
| 73 | + |
| 74 | +This compliance state indicates that the evaluation cycle hasn't started for the policy or resource. |
| 75 | + |
| 76 | +## Example |
| 77 | + |
| 78 | +Now that you have an understanding of what compliance states exist and what each one means, let's look at an example using compliant and non-compliant states. |
| 79 | + |
| 80 | +Suppose you have a resource group - ContosoRG, with some storage accounts |
| 81 | +(highlighted in red) that are exposed to public networks. |
| 82 | + |
| 83 | +:::image type="complex" source="../media/getting-compliance-data/resource-group01.png" alt-text="Diagram of storage accounts exposed to public networks in the Contoso R G resource group." border="false"::: |
| 84 | + Diagram showing images for five storage accounts in the Contoso R G resource group. Storage accounts one and three are blue, while storage accounts two, four, and five are red. |
| 85 | +:::image-end::: |
| 86 | + |
| 87 | +In this example, you need to be wary of security risks. Assume you assign a policy definition that audits for storage accounts that are exposed to public networks, and that no exemptions are created for this assignment. The policy checks for applicable resources (which includes all storage accounts in the ContosoRG resource group), then evaluates those resources that aren't excluded from evaluation. It audits the three storage accounts exposed to public networks, changing their compliance states to **Non-compliant.** The remainder are marked **compliant**. |
| 88 | + |
| 89 | +:::image type="complex" source="../media/getting-compliance-data/resource-group03.png" alt-text="Diagram of storage account compliance in the Contoso R G resource group." border="false"::: |
| 90 | + Diagram showing images for five storage accounts in the Contoso R G resource group. Storage accounts one and three now have green checkmarks beneath them, while storage accounts two, four, and five now have red warning signs beneath them. |
| 91 | +:::image-end::: |
| 92 | + |
| 93 | +## Compliance rollup |
| 94 | + |
| 95 | +Compliance state is determined per-resource, per-policy assignment. However, we often need a big-picture view of the state of the environment, which is where aggregate compliance comes into play. |
| 96 | + |
| 97 | +There are several ways to view aggregated compliance results in the portal: |
| 98 | + |
| 99 | +| Aggregate compliance view | Factors determining compliance state | |
| 100 | +| --- | --- | |
| 101 | +| Scope | All policies within the selected scope | |
| 102 | +| Initiative | All policies within the initiative | |
| 103 | +| Initiative group or control | All policies within the group or control | |
| 104 | +| Policy | All applicable resources | |
| 105 | +| Resource | All applicable policies | |
| 106 | + |
| 107 | +### Comparing different compliance states |
| 108 | + |
| 109 | +So how is the aggregate compliance state determined if multiple resources or policies have different compliance states themselves? Azure Policy ranks each compliance state so that one "wins" over another in this situation. The rank order is: |
| 110 | +1. Non-compliant |
| 111 | +1. Compliant |
| 112 | +1. Error |
| 113 | +1. Conflicting |
| 114 | +1. Exempted |
| 115 | +1. Unknown (preview) |
| 116 | + |
| 117 | +> [!NOTE] |
| 118 | +> [Not started](#not-started) and [not registered](#not-registered) aren't considered in compliance rollup calculations. |
| 119 | +
|
| 120 | +With this ranking, if there are both non-compliant and compliant states, then the rolled up aggregate would be non-compliant, and so on. Let's look at an example: |
| 121 | + |
| 122 | +Assume an initiative contains 10 policies, and a resource is exempt from one policy but compliant to the remaining nine. Because a compliant state has a higher rank than an exempted state, the resource would register as compliant in the rolled-up summary of the initiative. So, a resource only shows as exempt for the entire initiative if it's exempt from, or has unknown compliance to, every other single applicable policy in that initiative. On the other extreme, a resource that is non-compliant to at least one applicable policy in the initiative has an overall compliance state of non-compliant, regardless of the remaining applicable policies. |
| 123 | + |
| 124 | +### Compliance percentage |
| 125 | + |
| 126 | +The compliance percentage is determined by dividing **Compliant**, **Exempt**, and **Unknown** resources by _total resources_. _Total resources_ include **Compliant**, **Non-compliant**, |
| 127 | +**Exempt**, and **Conflicting** resources. The overall compliance numbers are the sum of distinct |
| 128 | +resources that are **Compliant**, **Exempt**, and **Unknown** divided by the sum of all distinct resources. |
| 129 | + |
| 130 | +```text |
| 131 | +overall compliance % = (compliant + exempt + unknown) / (compliant + non-compliant + exempt + conflicting) |
| 132 | +``` |
| 133 | + |
| 134 | +In the image shown, there are 20 distinct resources that are applicable and only one is **Non-compliant**. |
| 135 | +The overall resource compliance is 95% (19 out of 20). |
| 136 | + |
| 137 | +:::image type="content" source="../media/getting-compliance-data/simple-compliance.png" alt-text="Screenshot of policy compliance details from Compliance page." border="false"::: |
| 138 | + |
| 139 | +## Next steps |
| 140 | + |
| 141 | +- Learn how to [get compliance data](../how-to/get-compliance-data.md) |
| 142 | +- Learn how to [determine causes of non-compliance](../how-to/determine-non-compliance.md) |
| 143 | +- Get compliance data through [ARG query samples](../samples/resource-graph-samples.md) |
0 commit comments