Skip to content

Commit 4ed4482

Browse files
committed
Update modify effect
1 parent 916b5d1 commit 4ed4482

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

articles/governance/policy/concepts/definition-structure.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Details of the policy definition structure
33
description: Describes how policy definitions are used to establish conventions for Azure resources in your organization.
4-
ms.date: 08/17/2020
4+
ms.date: 08/27/2020
55
ms.topic: conceptual
66
---
77
# Azure Policy definition structure
@@ -805,6 +805,14 @@ Policy, use one of the following methods:
805805
(Get-AzPolicyAlias -NamespaceMatch 'compute').Aliases
806806
```
807807

808+
> [!NOTE]
809+
> To find aliases that can be used with the [modify](./effects.md#modify) effect, use the
810+
> following command:
811+
>
812+
> ```azurepowershell-interactive
813+
> Get-AzPolicyAlias | Select-Object -ExpandProperty 'Aliases' | Where-Object { $_.DefaultMetadata.Attributes -eq 'Modifiable' }
814+
> ```
815+
808816
- Azure CLI
809817
810818
```azurecli-interactive

articles/governance/policy/concepts/effects.md

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Understand how effects work
33
description: Azure Policy definitions have various effects that determine how compliance is managed and reported.
4-
ms.date: 08/17/2020
4+
ms.date: 08/27/2020
55
ms.topic: conceptual
66
---
77
# Understand Azure Policy effects
@@ -605,23 +605,51 @@ Example: Gatekeeper v2 admission control rule to allow only the specified contai
605605

606606
## Modify
607607

608-
Modify is used to add, update, or remove tags on a resource during creation or update. A common
609-
example is updating tags on resources such as costCenter. A Modify policy should always have `mode`
610-
set to _Indexed_ unless the target resource is a resource group. Existing non-compliant resources
608+
Modify is used to add, update, or remove properties or tags on a resource during creation or update.
609+
A common example is updating tags on resources such as costCenter. Existing non-compliant resources
611610
can be remediated with a [remediation task](../how-to/remediate-resources.md). A single Modify rule
612611
can have any number of operations.
613612

613+
The following operations are supported by Modify:
614+
615+
- Add, replace or remove resource tags. For tags, a Modify policy should have `mode` set to
616+
_Indexed_ unless the target resource is a resource group.
617+
- Add or replace the value of managed identity type (`identity.type`) of virtual machines and
618+
virtual machine scale sets.
619+
- Add or replace the values of certain aliases (preview).
620+
- Use
621+
`Get-AzPolicyAlias | Select-Object -ExpandProperty 'Aliases' | Where-Object { $_.DefaultMetadata.Attributes -eq 'Modifiable' }`
622+
in Azure PowerShell to get a list of aliases that can be used with Modify.
623+
614624
> [!IMPORTANT]
615-
> Modify is currently only for use with tags. If you are managing tags, it's recommended to use
616-
> Modify instead of Append as Modify provides additional operation types and the ability to
617-
> remediate existing resources. However, Append is recommended if you aren't able to create a
618-
> managed identity.
625+
> If you're managing tags, it's recommended to use Modify instead of Append as Modify provides
626+
> additional operation types and the ability to remediate existing resources. However, Append is
627+
> recommended if you aren't able to create a managed identity or Modify doesn't yet support the
628+
> alias for the resource property.
619629
620630
### Modify evaluation
621631

622632
Modify evaluates before the request gets processed by a Resource Provider during the creation or
623-
updating of a resource. Modify adds or updates tags on a resource when the **if** condition of the
624-
policy rule is met.
633+
updating of a resource. The Modify operations are applied to the request content when the **if**
634+
condition of the policy rule is met. Each Modify operation can specify a condition that determines
635+
when it's applied. Operations with conditions that are evaluated to _false_ are skipped.
636+
637+
When an alias is specified, the following additional checks are performed to ensure that the Modify
638+
operation doesn't change the request content in a way that causes the resource provider to reject
639+
it:
640+
641+
- The property the alias maps to is marked as 'Modifiable' in the request's API version.
642+
- The token type in the Modify operation matches the expected token type for the property in the
643+
request's API version.
644+
645+
If either of these checks fail, the policy evaluation falls back to the specified
646+
**conflictEffect**.
647+
648+
> [!IMPORTANT]
649+
> It's recommeneded that Modify definitions that include aliases use the _audit_ **conflict effect**
650+
> to avoid failing requests using API versions where the mapped property isn't 'Modifiable'. If the
651+
> same alias behaves differently between API versions, conditional modify operations can be used to
652+
> determine the modify operation used for each API version.
625653
626654
When a policy definition using the Modify effect is run as part of an evaluation cycle, it doesn't
627655
make changes to resources that already exist. Instead, it marks any resource that meets the **if**
@@ -636,11 +664,11 @@ needed for remediation and the **operations** used to add, update, or remove tag
636664
- This property must include an array of strings that match role-based access control role ID
637665
accessible by the subscription. For more information, see
638666
[remediation - configure policy definition](../how-to/remediate-resources.md#configure-policy-definition).
639-
- The role defined must include all operations granted to the [Contributor](../../../role-based-access-control/built-in-roles.md#contributor)
640-
role.
667+
- The role defined must include all operations granted to the
668+
[Contributor](../../../role-based-access-control/built-in-roles.md#contributor) role.
641669
- **conflictEffect** (optional)
642670
- Determines which policy definition "wins" in the event that more than one policy definition
643-
modifies the same property.
671+
modifies the same property or when the Modify operation doesn't work on the specified alias.
644672
- For new or updated resources, the policy definition with _deny_ takes precedence. Policy
645673
definitions with _audit_ skip all **operations**. If more than one policy definition has
646674
_deny_, the request is denied as a conflict. If all policy definitions have _audit_, then none
@@ -662,6 +690,12 @@ needed for remediation and the **operations** used to add, update, or remove tag
662690
- **value** (optional)
663691
- The value to set the tag to.
664692
- This property is required if **operation** is _addOrReplace_ or _Add_.
693+
- **condition** (optional)
694+
- A string containing an Azure Policy language expression with
695+
[Policy functions](./definition-structure.md#policy-functions) that evaluates to _true_ or
696+
_false_.
697+
- Doesn't support the following Policy functions: `field()`, `resourceGroup()`,
698+
`subscription()`.
665699

666700
### Modify operations
667701

@@ -701,9 +735,9 @@ The **operation** property has the following options:
701735

702736
|Operation |Description |
703737
|-|-|
704-
|addOrReplace |Adds the defined tag and value to the resource, even if the tag already exists with a different value. |
705-
|Add |Adds the defined tag and value to the resource. |
706-
|Remove |Removes the defined tag from the resource. |
738+
|addOrReplace |Adds the defined property or tag and value to the resource, even if the property or tag already exists with a different value. |
739+
|Add |Adds the defined property or tag and value to the resource. |
740+
|Remove |Removes the defined property or tag from the resource. |
707741

708742
### Modify examples
709743

@@ -753,6 +787,29 @@ with a parameterized value:
753787
}
754788
```
755789

790+
Example 3: Ensure that a storage account doesn't allow blob public access, the Modify operation
791+
is applied only when evaluating requests with API version greater or equals to '2019-04-01':
792+
793+
```json
794+
"then": {
795+
"effect": "modify",
796+
"details": {
797+
"roleDefinitionIds": [
798+
"/providers/microsoft.authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
799+
],
800+
"conflictEffect": "audit",
801+
"operations": [
802+
{
803+
"condition": "[greaterOrEquals(requestContext().apiVersion, '2019-04-01')]",
804+
"operation": "addOrReplace",
805+
"field": "Microsoft.Storage/storageAccounts/allowBlobPublicAccess",
806+
"value": false
807+
}
808+
]
809+
}
810+
}
811+
```
812+
756813
## Layering policy definitions
757814

758815
A resource may be impacted by several assignments. These assignments may be at the same scope or at
@@ -799,4 +856,4 @@ to validate the right policy assignments are affecting the right scopes.
799856
- Understand how to [programmatically create policies](../how-to/programmatically-create.md).
800857
- Learn how to [get compliance data](../how-to/get-compliance-data.md).
801858
- Learn how to [remediate non-compliant resources](../how-to/remediate-resources.md).
802-
- Review what a management group is with [Organize your resources with Azure management groups](../../management-groups/overview.md).
859+
- Review what a management group is with [Organize your resources with Azure management groups](../../management-groups/overview.md).

articles/governance/policy/how-to/remediate-resources.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: Remediate non-compliant resources
33
description: This guide walks you through the remediation of resources that are non-compliant to policies in Azure Policy.
4-
ms.date: 06/09/2020
4+
ms.date: 08/27/2020
55
ms.topic: how-to
66
---
77
# Remediate non-compliant resources with Azure Policy
88

99
Resources that are non-compliant to a **deployIfNotExists** or **modify** policy can be put into a
1010
compliant state through **Remediation**. Remediation is accomplished by instructing Azure Policy to
11-
run the **deployIfNotExists** effect or the tag **operations** of the assigned policy on your
11+
run the **deployIfNotExists** effect or the **modify operations** of the assigned policy on your
1212
existing resources, whether that assignment is to a management group, a subscription, a resource
1313
group, or an individual resource. This article shows the steps needed to understand and accomplish
1414
remediation with Azure Policy.

0 commit comments

Comments
 (0)