Skip to content

Commit 1f4fe0e

Browse files
committed
updates audit and deny properties
1 parent fc243db commit 1f4fe0e

File tree

1 file changed

+67
-44
lines changed

1 file changed

+67
-44
lines changed

articles/governance/policy/concepts/effects.md

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
title: Understand how effects work
33
description: Azure Policy definitions have various effects that determine how compliance is managed and reported.
44
author: davidsmatlak
5-
ms.date: 02/22/2023
5+
ms.date: 06/15/2023
66
ms.topic: conceptual
77
ms.author: davidsmatlak
88
---
9+
910
# Understand Azure Policy effects
1011

1112
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:
2627

2728
## Interchanging effects
2829

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.
3031

31-
Below is some general guidance around interchangeable effects:
32+
The following list is some general guidance around interchangeable effects:
3233
- **Audit**, **Deny**, and either **Modify** or **Append** are often interchangeable.
3334
- **AuditIfNotExists** and **DeployIfNotExists** are often interchangeable.
3435
- **Manual** isn't interchangeable.
@@ -57,15 +58,15 @@ manages the evaluation and outcome and reports the results back to Azure Policy.
5758
- **denyAction** is evaluated last.
5859

5960
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
6162
logging or action is required.
6263

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
6465
policies containing conditions that inspect `tags` related fields.
6566

6667
## Append
6768

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
6970
common example is specifying allowed IPs for a storage resource.
7071

7172
> [!IMPORTANT]
@@ -78,7 +79,7 @@ Append evaluates before the request gets processed by a Resource Provider during
7879
updating of a resource. Append adds fields to the resource when the **if** condition of the policy
7980
rule is met. If the append effect would override a value in the original request with a different
8081
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.
8283

8384
When a policy definition using the append effect is run as part of an evaluation cycle, it doesn't
8485
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
9293

9394
### Append examples
9495

95-
Example 1: Single **field/value** pair using a non-**\[\*\]**
96+
Example 1: Single **field/value** pair using a non-`[*]`
9697
[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
9899
array. If the array already exists, a deny event occurs from the conflict.
99100

100101
```json
@@ -110,8 +111,8 @@ array. If the array already exists, a deny event occurs from the conflict.
110111
}
111112
```
112113

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
115116
effect appends the **value** to a potentially pre-existing array. If the array doesn't exist yet,
116117
it's created.
117118

@@ -144,11 +145,11 @@ resource is updated.
144145

145146
### Audit properties
146147

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
148149
**then** condition of the policy definition.
149150

150151
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
152153
definitions as `constraintTemplate` is deprecated.
153154

154155
- **templateInfo** (required)
@@ -173,6 +174,21 @@ definitions as `constraintTemplate` is deprecated.
173174
- The CRD implementation of the Constraint template. Uses parameters passed via **values** as
174175
`{{ .Values.<valuename> }}`. In example 2 below, these values are
175176
`{{ .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.
176192
- **namespaces** (optional)
177193
- An _array_ of
178194
[Kubernetes namespaces](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/)
@@ -203,12 +219,6 @@ definitions as `constraintTemplate` is deprecated.
203219
- **values** (optional)
204220
- Defines any parameters and values to pass to the Constraint. Each value must exist in the
205221
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.
212222

213223
### Audit example
214224

@@ -355,11 +365,11 @@ non-compliant.
355365

356366
### Deny properties
357367

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
359369
**then** condition of the policy definition.
360370

361371
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
363373
definitions as `constraintTemplate` is deprecated.
364374

365375
- **templateInfo** (required)
@@ -384,6 +394,21 @@ definitions as `constraintTemplate` is deprecated.
384394
- The CRD implementation of the Constraint template. Uses parameters passed via **values** as
385395
`{{ .Values.<valuename> }}`. In example 2 below, these values are
386396
`{{ .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.
387412
- **namespaces** (optional)
388413
- An _array_ of
389414
[Kubernetes namespaces](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/)
@@ -414,13 +439,6 @@ definitions as `constraintTemplate` is deprecated.
414439
- **values** (optional)
415440
- Defines any parameters and values to pass to the Constraint. Each value must exist in the
416441
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`.
424442

425443
### Deny example
426444

@@ -452,9 +470,10 @@ location of the Constraint template to use in Kubernetes to limit the allowed co
452470
}
453471
}
454472
```
473+
455474
## DenyAction (preview)
456475

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.
458477

459478
### DenyAction evaluation
460479

@@ -467,12 +486,15 @@ assignment.
467486
> Under preview, assignments with `denyAction` effect will show a `Not Started` compliance state.
468487
469488
#### Subscription deletion
489+
470490
Policy won't block removal of resources that happens during a subscription deletion.
471491

472492
#### Resource group deletion
493+
473494
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`.
474495

475496
#### Cascade deletion
497+
476498
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).
477499

478500
[!INCLUDE [policy-denyAction](../../../../includes/azure-policy-deny-action.md)]
@@ -491,7 +513,8 @@ The **details** property of the DenyAction effect has all the subproperties that
491513
- Default value is `deny`.
492514

493515
### 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.
495518

496519
```json
497520
{
@@ -619,7 +642,7 @@ related resources to match and the template deployment to execute.
619642
620643
### DeployIfNotExists example
621644

622-
Example: Evaluates SQL Server databases to determine whether transparentDataEncryption is enabled.
645+
Example: Evaluates SQL Server databases to determine whether `transparentDataEncryption` is enabled.
623646
If not, then a deployment to enable is executed.
624647

625648
```json
@@ -766,7 +789,7 @@ The following operations are supported by Modify:
766789

767790
> [!IMPORTANT]
768791
> 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
770793
> recommended if you aren't able to create a managed identity or Modify doesn't yet support the
771794
> alias for the resource property.
772795
@@ -848,7 +871,7 @@ properties. Operation determines what the remediation task does to the tags, fie
848871
tag is altered, and value defines the new setting for that tag. The following example makes the
849872
following tag changes:
850873

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.
852875
- Removes the tag `TempResource`.
853876
- Sets the `Dept` tag to the policy parameter _DeptName_ configured on the policy assignment.
854877

@@ -931,7 +954,7 @@ with a parameterized value:
931954
```
932955

933956
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`:
935958

936959
```json
937960
"then": {
@@ -960,29 +983,29 @@ different scopes. Each of these assignments is also likely to have a different e
960983
condition and effect for each policy is independently evaluated. For example:
961984

962985
- Policy 1
963-
- Restricts resource location to 'westus'
986+
- Restricts resource location to `westus`
964987
- Assigned to subscription A
965988
- Deny effect
966989
- Policy 2
967-
- Restricts resource location to 'eastus'
990+
- Restricts resource location to `eastus`
968991
- Assigned to resource group B in subscription A
969992
- Audit effect
970993

971994
This setup would result in the following outcome:
972995

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
974997
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
9791002
on policy 2
9801003

9811004
If both policy 1 and policy 2 had effect of deny, the situation changes to:
9821005

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
9861009
- Any new resource in resource group B of subscription A is denied
9871010

9881011
Each assignment is individually evaluated. As such, there isn't an opportunity for a resource to

0 commit comments

Comments
 (0)