You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/governance/policy/concepts/effects.md
+67-44Lines changed: 67 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,11 @@
2
2
title: Understand how effects work
3
3
description: Azure Policy definitions have various effects that determine how compliance is managed and reported.
4
4
author: davidsmatlak
5
-
ms.date: 02/22/2023
5
+
ms.date: 06/15/2023
6
6
ms.topic: conceptual
7
7
ms.author: davidsmatlak
8
8
---
9
+
9
10
# Understand Azure Policy effects
10
11
11
12
Each policy definition in Azure Policy has a single effect. That effect determines what happens when
@@ -26,9 +27,9 @@ These effects are currently supported in a policy definition:
26
27
27
28
## Interchanging effects
28
29
29
-
Sometimes multiple effects can be valid for a given policy definition. Parameters are often used to specify allowed effect values so that a single definition can be more versatile. However, it's important to note that not all effects are interchangeable. Resource properties and logic in the policy rule can determine whether a certain effect is considered valid to the policy definition. For example, policy definitions with effect **AuditIfNotExists** require additional details in the policy rule that aren't required for policies with effect **Audit**. The effects also behave differently. **Audit** policies will assess a resource's compliance based on its own properties, while **AuditIfNotExists** policies will assess a resource's compliance based on a child or extension resource's properties.
30
+
Sometimes multiple effects can be valid for a given policy definition. Parameters are often used to specify allowed effect values so that a single definition can be more versatile. However, it's important to note that not all effects are interchangeable. Resource properties and logic in the policy rule can determine whether a certain effect is considered valid to the policy definition. For example, policy definitions with effect **AuditIfNotExists** require other details in the policy rule that aren't required for policies with effect **Audit**. The effects also behave differently. **Audit** policies will assess a resource's compliance based on its own properties, while **AuditIfNotExists** policies will assess a resource's compliance based on a child or extension resource's properties.
30
31
31
-
Below is some general guidance around interchangeable effects:
32
+
The following list is some general guidance around interchangeable effects:
32
33
-**Audit**, **Deny**, and either **Modify** or **Append** are often interchangeable.
33
34
-**AuditIfNotExists** and **DeployIfNotExists** are often interchangeable.
34
35
-**Manual** isn't interchangeable.
@@ -57,15 +58,15 @@ manages the evaluation and outcome and reports the results back to Azure Policy.
57
58
-**denyAction** is evaluated last.
58
59
59
60
After the Resource Provider returns a success code on a Resource Manager mode request,
60
-
**AuditIfNotExists** and **DeployIfNotExists** evaluate to determine whether additional compliance
61
+
**AuditIfNotExists** and **DeployIfNotExists** evaluate to determine whether more compliance
61
62
logging or action is required.
62
63
63
-
Additionally, `PATCH` requests that only modify `tags` related fields restricts policy evaluation to
64
+
`PATCH` requests that only modify `tags` related fields restricts policy evaluation to
64
65
policies containing conditions that inspect `tags` related fields.
65
66
66
67
## Append
67
68
68
-
Append is used to add additional fields to the requested resource during creation or update. A
69
+
Append is used to add more fields to the requested resource during creation or update. A
69
70
common example is specifying allowed IPs for a storage resource.
70
71
71
72
> [!IMPORTANT]
@@ -78,7 +79,7 @@ Append evaluates before the request gets processed by a Resource Provider during
78
79
updating of a resource. Append adds fields to the resource when the **if** condition of the policy
79
80
rule is met. If the append effect would override a value in the original request with a different
80
81
value, then it acts as a deny effect and rejects the request. To append a new value to an existing
81
-
array, use the **\[\*\]** version of the alias.
82
+
array, use the `[*]` version of the alias.
82
83
83
84
When a policy definition using the append effect is run as part of an evaluation cycle, it doesn't
84
85
make changes to resources that already exist. Instead, it marks any resource that meets the **if**
@@ -92,9 +93,9 @@ take either a single **field/value** pair or multiples. Refer to
92
93
93
94
### Append examples
94
95
95
-
Example 1: Single **field/value** pair using a non-**\[\*\]**
96
+
Example 1: Single **field/value** pair using a non-`[*]`
96
97
[alias](definition-structure.md#aliases) with an array **value** to set IP rules on a storage
97
-
account. When the non-**\[\*\]** alias is an array, the effect appends the **value** as the entire
98
+
account. When the non-`[*]` alias is an array, the effect appends the **value** as the entire
98
99
array. If the array already exists, a deny event occurs from the conflict.
99
100
100
101
```json
@@ -110,8 +111,8 @@ array. If the array already exists, a deny event occurs from the conflict.
110
111
}
111
112
```
112
113
113
-
Example 2: Single **field/value** pair using an **\[\*\]**[alias](definition-structure.md#aliases)
114
-
with an array **value** to set IP rules on a storage account. By using the **\[\*\]** alias, the
114
+
Example 2: Single **field/value** pair using an `[*]`[alias](definition-structure.md#aliases)
115
+
with an array **value** to set IP rules on a storage account. When you use the `[*]` alias, the
115
116
effect appends the **value** to a potentially pre-existing array. If the array doesn't exist yet,
116
117
it's created.
117
118
@@ -144,11 +145,11 @@ resource is updated.
144
145
145
146
### Audit properties
146
147
147
-
For a Resource Manager mode, the audit effect doesn't have any additional properties for use in the
148
+
For a Resource Manager mode, the audit effect doesn't have any other properties for use in the
148
149
**then** condition of the policy definition.
149
150
150
151
For a Resource Provider mode of `Microsoft.Kubernetes.Data`, the audit effect has the following
151
-
additional subproperties of **details**. Use of `templateInfo` is required for new or updated policy
152
+
subproperties of **details**. Use of `templateInfo` is required for new or updated policy
152
153
definitions as `constraintTemplate` is deprecated.
153
154
154
155
-**templateInfo** (required)
@@ -173,6 +174,21 @@ definitions as `constraintTemplate` is deprecated.
173
174
- The CRD implementation of the Constraint template. Uses parameters passed via **values** as
174
175
`{{ .Values.<valuename> }}`. In example 2 below, these values are
175
176
`{{ .Values.excludedNamespaces }}` and `{{ .Values.allowedContainerImagesRegex }}`.
177
+
-**constraintTemplate** (deprecated)
178
+
- Can't be used with `templateInfo`.
179
+
- Must be replaced with `templateInfo` when creating or updating a policy definition.
180
+
- The Constraint template CustomResourceDefinition (CRD) that defines new Constraints. The
181
+
template defines the Rego logic, the Constraint schema, and the Constraint parameters that are
182
+
passed via **values** from Azure Policy. For more information, go to [Gatekeeper constraints](https://open-policy-agent.github.io/gatekeeper/website/docs/howto/#constraints).
183
+
-**constraintInfo** (optional)
184
+
- Can't be used with `constraint`, `constraintTemplate`, `apiGroups`, or `kinds`.
185
+
- If `constraintInfo` isn't provided, the constraint can be generated from `templateInfo` and policy.
186
+
-**sourceType** (required)
187
+
- Defines the type of source for the constraint. Allowed values: _PublicURL_ or _Base64Encoded_.
188
+
- If _PublicURL_, paired with property `url` to provide location of the constraint. The location must be publicly accessible.
189
+
190
+
> [!WARNING]
191
+
> Don't use SAS URIs or tokens in `url` or anything else that could expose a secret.
@@ -203,12 +219,6 @@ definitions as `constraintTemplate` is deprecated.
203
219
-**values** (optional)
204
220
- Defines any parameters and values to pass to the Constraint. Each value must exist in the
205
221
Constraint template CRD.
206
-
-**constraintTemplate** (deprecated)
207
-
- Can't be used with `templateInfo`.
208
-
- Must be replaced with `templateInfo` when creating or updating a policy definition.
209
-
- The Constraint template CustomResourceDefinition (CRD) that defines new Constraints. The
210
-
template defines the Rego logic, the Constraint schema, and the Constraint parameters that are
211
-
passed via **values** from Azure Policy.
212
222
213
223
### Audit example
214
224
@@ -355,11 +365,11 @@ non-compliant.
355
365
356
366
### Deny properties
357
367
358
-
For a Resource Manager mode, the deny effect doesn't have any additional properties for use in the
368
+
For a Resource Manager mode, the deny effect doesn't have any more properties for use in the
359
369
**then** condition of the policy definition.
360
370
361
371
For a Resource Provider mode of `Microsoft.Kubernetes.Data`, the deny effect has the following
362
-
additional subproperties of **details**. Use of `templateInfo` is required for new or updated policy
372
+
subproperties of **details**. Use of `templateInfo` is required for new or updated policy
363
373
definitions as `constraintTemplate` is deprecated.
364
374
365
375
-**templateInfo** (required)
@@ -384,6 +394,21 @@ definitions as `constraintTemplate` is deprecated.
384
394
- The CRD implementation of the Constraint template. Uses parameters passed via **values** as
385
395
`{{ .Values.<valuename> }}`. In example 2 below, these values are
386
396
`{{ .Values.excludedNamespaces }}` and `{{ .Values.allowedContainerImagesRegex }}`.
397
+
-**constraintTemplate** (deprecated)
398
+
- Can't be used with `templateInfo`.
399
+
- Must be replaced with `templateInfo` when creating or updating a policy definition.
400
+
- The Constraint template CustomResourceDefinition (CRD) that defines new Constraints. The
401
+
template defines the Rego logic, the Constraint schema, and the Constraint parameters that are
402
+
passed via **values** from Azure Policy. For more information, go to [Gatekeeper constraints](https://open-policy-agent.github.io/gatekeeper/website/docs/howto/#constraints).
403
+
-**constraintInfo** (optional)
404
+
- Can't be used with `constraint`, `constraintTemplate`, `apiGroups`, or `kinds`.
405
+
- If `constraintInfo` isn't provided, the constraint can be generated from `templateInfo` and policy.
406
+
-**sourceType** (required)
407
+
- Defines the type of source for the constraint. Allowed values: _PublicURL_ or _Base64Encoded_.
408
+
- If _PublicURL_, paired with property `url` to provide location of the constraint. The location must be publicly accessible.
409
+
410
+
> [!WARNING]
411
+
> Don't use SAS URIs or tokens in `url` or anything else that could expose a secret.
@@ -414,13 +439,6 @@ definitions as `constraintTemplate` is deprecated.
414
439
-**values** (optional)
415
440
- Defines any parameters and values to pass to the Constraint. Each value must exist in the
416
441
Constraint template CRD.
417
-
-**constraintTemplate** (deprecated)
418
-
- Can't be used with `templateInfo`.
419
-
- Must be replaced with `templateInfo` when creating or updating a policy definition.
420
-
- The Constraint template CustomResourceDefinition (CRD) that defines new Constraints. The
421
-
template defines the Rego logic, the Constraint schema, and the Constraint parameters that are
422
-
passed via **values** from Azure Policy. It's recommended to use the newer `templateInfo` to
423
-
replace `constraintTemplate`.
424
442
425
443
### Deny example
426
444
@@ -452,9 +470,10 @@ location of the Constraint template to use in Kubernetes to limit the allowed co
452
470
}
453
471
}
454
472
```
473
+
455
474
## DenyAction (preview)
456
475
457
-
`DenyAction` is used to block requests on intended action to resources. The only supported action today is `DELETE`. This effect will help prevent any accidental deletion of critical resources.
476
+
`DenyAction` is used to block requests on intended action to resources. The only supported action today is `DELETE`. This effect helps prevent any accidental deletion of critical resources.
458
477
459
478
### DenyAction evaluation
460
479
@@ -467,12 +486,15 @@ assignment.
467
486
> Under preview, assignments with `denyAction` effect will show a `Not Started` compliance state.
468
487
469
488
#### Subscription deletion
489
+
470
490
Policy won't block removal of resources that happens during a subscription deletion.
471
491
472
492
#### Resource group deletion
493
+
473
494
Policy will evaluate resources that support location and tags against `DenyAction` policies during a resource group deletion. Only policies that have the `cascadeBehaviors` set to `deny` in the policy rule will block a resource group deletion. Policy won't block removal of resources that don't support location and tags nor any policy with `mode:all`.
474
495
475
496
#### Cascade deletion
497
+
476
498
Cascade deletion occurs when deleting of a parent resource is implicitly deletes all its child resources. Policy won't block removal of child resources when a delete action targets the parent resources. For example, `Microsoft.Insights/diagnosticSettings` is a child resource of `Microsoft.Storage/storageaccounts`. If a `denyAction` policy targets `Microsoft.Insights/diagnosticSettings`, a delete call to the diagnostic setting (child) will fail, but a delete to the storage account (parent) will implicitly delete the diagnostic setting (child).
@@ -491,7 +513,8 @@ The **details** property of the DenyAction effect has all the subproperties that
491
513
- Default value is `deny`.
492
514
493
515
### DenyAction example
494
-
Example: Deny any delete calls targeting database accounts that have a tag environment that equals prod. Since cascade behavior is set to deny, block any DELETE call that targets a resource group with an applicable database account.
516
+
517
+
Example: Deny any delete calls targeting database accounts that have a tag environment that equals prod. Since cascade behavior is set to deny, block any `DELETE` call that targets a resource group with an applicable database account.
495
518
496
519
```json
497
520
{
@@ -619,7 +642,7 @@ related resources to match and the template deployment to execute.
619
642
620
643
### DeployIfNotExists example
621
644
622
-
Example: Evaluates SQL Server databases to determine whether transparentDataEncryption is enabled.
645
+
Example: Evaluates SQL Server databases to determine whether `transparentDataEncryption` is enabled.
623
646
If not, then a deployment to enable is executed.
624
647
625
648
```json
@@ -766,7 +789,7 @@ The following operations are supported by Modify:
766
789
767
790
> [!IMPORTANT]
768
791
> If you're managing tags, it's recommended to use Modify instead of Append as Modify provides
769
-
> additional operation types and the ability to remediate existing resources. However, Append is
792
+
> more operation types and the ability to remediate existing resources. However, Append is
770
793
> recommended if you aren't able to create a managed identity or Modify doesn't yet support the
771
794
> alias for the resource property.
772
795
@@ -848,7 +871,7 @@ properties. Operation determines what the remediation task does to the tags, fie
848
871
tag is altered, and value defines the new setting for that tag. The following example makes the
849
872
following tag changes:
850
873
851
-
- Sets the `environment` tag to "Test", even if it already exists with a different value.
874
+
- Sets the `environment` tag to "Test" even if it already exists with a different value.
852
875
- Removes the tag `TempResource`.
853
876
- Sets the `Dept` tag to the policy parameter _DeptName_ configured on the policy assignment.
854
877
@@ -931,7 +954,7 @@ with a parameterized value:
931
954
```
932
955
933
956
Example 3: Ensure that a storage account doesn't allow blob public access, the Modify operation
934
-
is applied only when evaluating requests with API version greater or equals to '2019-04-01':
957
+
is applied only when evaluating requests with API version greater or equals to `2019-04-01`:
935
958
936
959
```json
937
960
"then": {
@@ -960,29 +983,29 @@ different scopes. Each of these assignments is also likely to have a different e
960
983
condition and effect for each policy is independently evaluated. For example:
961
984
962
985
- Policy 1
963
-
- Restricts resource location to 'westus'
986
+
- Restricts resource location to `westus`
964
987
- Assigned to subscription A
965
988
- Deny effect
966
989
- Policy 2
967
-
- Restricts resource location to 'eastus'
990
+
- Restricts resource location to `eastus`
968
991
- Assigned to resource group B in subscription A
969
992
- Audit effect
970
993
971
994
This setup would result in the following outcome:
972
995
973
-
- Any resource already in resource group B in 'eastus' is compliant to policy 2 and non-compliant to
996
+
- Any resource already in resource group B in `eastus` is compliant to policy 2 and non-compliant to
974
997
policy 1
975
-
- Any resource already in resource group B not in 'eastus' is non-compliant to policy 2 and
976
-
non-compliant to policy 1 if not in 'westus'
977
-
- Any new resource in subscription A not in 'westus' is denied by policy 1
978
-
- Any new resource in subscription A and resource group B in 'westus' is created and non-compliant
998
+
- Any resource already in resource group B not in `eastus` is non-compliant to policy 2 and
999
+
non-compliant to policy 1 if not in `westus`
1000
+
- Any new resource in subscription A not in `westus` is denied by policy 1
1001
+
- Any new resource in subscription A and resource group B in `westus` is created and non-compliant
979
1002
on policy 2
980
1003
981
1004
If both policy 1 and policy 2 had effect of deny, the situation changes to:
982
1005
983
-
- Any resource already in resource group B not in 'eastus' is non-compliant to policy 2
984
-
- Any resource already in resource group B not in 'westus' is non-compliant to policy 1
985
-
- Any new resource in subscription A not in 'westus' is denied by policy 1
1006
+
- Any resource already in resource group B not in `eastus` is non-compliant to policy 2
1007
+
- Any resource already in resource group B not in `westus` is non-compliant to policy 1
1008
+
- Any new resource in subscription A not in `westus` is denied by policy 1
986
1009
- Any new resource in resource group B of subscription A is denied
987
1010
988
1011
Each assignment is individually evaluated. As such, there isn't an opportunity for a resource to
0 commit comments