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/how-to/remediate-resources.md
+62-27Lines changed: 62 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Remediate non-compliant resources
3
3
description: This guide walks you through the remediation of resources that are non-compliant to policies in Azure Policy.
4
-
ms.date: 04/27/2022
4
+
ms.date: 07/29/2022
5
5
ms.topic: how-to
6
6
ms.author: timwarner
7
7
author: timwarner-msft
@@ -67,7 +67,7 @@ az role definition list --name "Contributor"
67
67
68
68
## Configure the managed identity
69
69
70
-
Each Azure Policy assignment can be associated with only one managed identity. However, the managed identity can be assigned multiple roles. Configuration occurs in two steps: first create either a system-assigned or user-assigned managed identity, then grant it the necessary roles.
70
+
Each Azure Policy assignment can be associated with only one managed identity. However, the managed identity can be assigned multiple roles. Configuration occurs in two steps: first create either a system-assigned or user-assigned managed identity, then grant it the necessary roles.
71
71
72
72
> [!NOTE]
73
73
> When creating a managed identity through the portal, roles will be granted automatically to the managed identity. If **roleDefinitionIds** are later edited in the policy definition, the new permissions must be manually granted, even in the portal.
@@ -80,25 +80,25 @@ When creating an assignment using the portal, Azure Policy can generate a system
80
80
81
81
:::image type="content" source="../media/remediate-resources/remediation-tab.png" alt-text="Screenshot of a policy assignment creating a system-assigned managed identity in East US with Log Analytics Contributor permissions.":::
82
82
83
-
To set a system-assigned managed identity in the portal:
83
+
To set a system-assigned managed identity in the portal:
84
84
85
-
1. On the **Remediation** tab of the create/edit assignment view, under **Types of Managed Identity**, ensure that **System assigned managed identity**
86
-
is selected.
85
+
1. On the **Remediation** tab of the create/edit assignment view, under **Types of Managed Identity**, ensure that **System assigned managed identity**
86
+
is selected.
87
87
88
-
1. Specify the location at which the managed identity is to be located.
88
+
1. Specify the location at which the managed identity is to be located.
89
89
90
-
To set a user-assigned managed identity in the portal:
90
+
To set a user-assigned managed identity in the portal:
91
91
92
-
1. On the **Remediation** tab of the create/edit assignment view, under **Types of Managed Identity**, ensure that **User assigned managed identity**
93
-
is selected.
92
+
1. On the **Remediation** tab of the create/edit assignment view, under **Types of Managed Identity**, ensure that **User assigned managed identity**
93
+
is selected.
94
94
95
-
1. Specify the scope where the managed identity is hosted. The scope of the managed identity does not have to equate to the scope of the assignment, but it must be in the same tenant.
95
+
1. Specify the scope where the managed identity is hosted. The scope of the managed identity does not have to equate to the scope of the assignment, but it must be in the same tenant.
96
96
97
-
1. Under **Existing user assigned identities**, select the managed identity.
97
+
1. Under **Existing user assigned identities**, select the managed identity.
98
98
99
99
# [PowerShell](#tab/azure-powershell)
100
100
101
-
To create an identity during the assignment of the policy, **Location** must be defined and **Identity** used.
101
+
To create an identity during the assignment of the policy, **Location** must be defined and **Identity** used.
102
102
103
103
The following example gets the definition of the built-in policy **Deploy SQL DB transparent data encryption** sets the target resource group, and then creates the assignment using a **system assigned** managed identity.
The `$assignment` variable now contains the principal ID of the managed identity along with the standard values returned when creating a policy assignment. It can be accessed through
140
-
`$assignment.Identity.PrincipalId` for system-assigned managed identities and `$assignment.Identity.UserAssignedIdentities[$userassignedidentityid].PrincipalId` for user-assigned managed identities.
140
+
`$assignment.Identity.PrincipalId` for system-assigned managed identities and `$assignment.Identity.UserAssignedIdentities[$userassignedidentityid].PrincipalId` for user-assigned managed identities.
141
141
142
142
# [Azure CLI](#tab/azure-cli)
143
143
@@ -150,13 +150,13 @@ To add a system-assigned identity or a user-assigned identity to a policy assign
150
150
### Grant permissions to the managed identity through defined roles
151
151
152
152
> [!IMPORTANT]
153
-
>
153
+
>
154
154
> If the managed identity does not have the permissions needed to execute the required remediation task, it will be granted permissions *automatically* only through the portal. You may skip this step if creating a managed identity through the portal.
155
155
>
156
156
> For all other methods, the assignment's managed identity must be manually granted access through the addition of roles, or else the remediation deployment will fail.
157
-
>
157
+
>
158
158
> Example scenarios that require manual permissions:
159
-
> - If the assignment is created through SDK
159
+
> - If the assignment is created through an Azure software development kit (SDK)
160
160
> - If a resource modified by **deployIfNotExists** or **modify** is outside the scope of the policy
161
161
> assignment
162
162
> - If the template accesses properties on resources outside the scope of the policy assignment
@@ -200,22 +200,57 @@ To add a role to the assignment's managed identity, follow these steps:
200
200
# [PowerShell](#tab/azure-powershell)
201
201
202
202
The new managed identity must complete replication through Azure Active Directory before it can be
203
-
granted the needed roles. Once replication is complete, the following example iterates the policy
203
+
granted the needed roles. Once replication is complete, the following examples iterate the policy
204
204
definition in `$policyDef` for the **roleDefinitionIds** and uses
205
205
[New-AzRoleAssignment](/powershell/module/az.resources/new-azroleassignment) to
206
206
grant the new managed identity the roles.
207
207
208
+
Specifically, the first example shows you how to grant roles at the policy scope. The second
209
+
example demonstrates how to grant roles at the initiative (policy set) scope.
@@ -246,7 +281,7 @@ There are three ways to create a remediation task through the portal.
246
281
1. All **deployIfNotExists** and **modify** policy assignments are
247
282
shown on the **Policies to remediate** tab. Select one with resources
248
283
that are non-compliant to open the **New remediation task** page.
249
-
284
+
250
285
1. Follow steps to [specify remediation task details](#step-2-specify-remediation-task-details).
251
286
252
287
#### Option 2: Create a remediation task from a non-compliant policy assignment
@@ -267,7 +302,7 @@ the **Remediation** tab of the wizard offers a _Create a remediation task_ optio
267
302
> [!NOTE]
268
303
> This is the most streamlined approach for creating a remediation task and is supported for policies assigned on a _subscription_. For policies assigned on a _management group_, remediation tasks should be created using [Option 1](#option-1-create-a-remediation-task-from-the-remediation-page) or [Option 2](#option-2-create-a-remediation-task-from-a-non-compliant-policy-assignment) after evaluation has determined resource compliance.
269
304
270
-
1. From the assignment wizard in the portal, navigate to the **Remediation** tab. Select the check box for **Create a remediation task**.
305
+
1. From the assignment wizard in the portal, navigate to the **Remediation** tab. Select the check box for **Create a remediation task**.
271
306
272
307
1. If the remediation task is initiated from an initiative assignment, select the policy to remediate from the drop-down.
273
308
@@ -277,21 +312,21 @@ the **Remediation** tab of the wizard offers a _Create a remediation task_ optio
277
312
278
313
This step is only applicable when using [Option 1](#option-1-create-a-remediation-task-from-the-remediation-page) or [Option 2](#option-2-create-a-remediation-task-from-a-non-compliant-policy-assignment) to initiate remediation task creation.
279
314
280
-
1. If the remediation task is initiated from an initiative assignment, select the policy to remediate from the drop-down. One **deployIfNotExists** or **modify** policy can be remediated through a single Remediation task at a time.
315
+
1. If the remediation task is initiated from an initiative assignment, select the policy to remediate from the drop-down. One **deployIfNotExists** or **modify** policy can be remediated through a single Remediation task at a time.
281
316
282
-
1. Optionally modify remediation settings on the **New remediation task** page:
317
+
1. Optionally modify remediation settings on the **New remediation task** page:
283
318
284
-
-**Failure Threshold percentage** - Used to specify whether the remediation task should fail if the percentage of failures exceeds the given threshold. Provided as a number between 0 to 100. By default, the failure threshold is 100%.
319
+
-**Failure Threshold percentage** - Used to specify whether the remediation task should fail if the percentage of failures exceeds the given threshold. Provided as a number between 0 to 100. By default, the failure threshold is 100%.
285
320
-**Resource Count** - Determines how many non-compliant resources to remediate in a given remediation task. The default value is 500 (the previous limit). The maximum number is 50,000 resources.
286
321
-**Parallel Deployments** - Determines how many resources to remediate at the same time. The allowed values are 1 to 30 resources at a time. The default value is 10.
287
322
288
323
> [!NOTE]
289
324
> These settings cannot be changed once the remediation task has started.
290
-
325
+
291
326
1. On the same page, filter the resources to remediate by using the **Scope**
292
327
ellipses to pick child resources from where the policy is assigned (including down to the
293
328
individual resource objects). Additionally, use the **Locations** dropdown list to further filter
294
-
the resources.
329
+
the resources.
295
330
296
331
:::image type="content" source="../media/remediate-resources/select-resources.png" alt-text="Screenshot of the Remediate node and the grid of resources to remediate." border="false":::
You may also choose to adjust remediation settings through these optional parameters:
330
-
-`-FailureThreshold` - Used to specify whether the remediation task should fail if the percentage of failures exceeds the given threshold. Provided as a number between 0 to 100. By default, the failure threshold is 100%.
365
+
-`-FailureThreshold` - Used to specify whether the remediation task should fail if the percentage of failures exceeds the given threshold. Provided as a number between 0 to 100. By default, the failure threshold is 100%.
331
366
-`-ParallelDeploymentCount` - Determines how many non-compliant resources to remediate in a given remediation task. The default value is 500 (the previous limit). The maximum number is 50,000 resources.
332
367
-`-ResourceCount` - Determines how many resources to remediate at the same time. The allowed values are 1 to 30 resources at a time. The default value is 10.
0 commit comments