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/machine-configuration/how-to/create-policy-definition.md
+37-22Lines changed: 37 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ description: Learn how to create a machine configuration policy.
4
4
ms.date: 02/01/2024
5
5
ms.topic: how-to
6
6
---
7
+
7
8
# How to create custom machine configuration policy definitions
8
9
9
10
Before you begin, it's a good idea to read the overview page for [machine configuration][01], and
@@ -105,20 +106,31 @@ Parameters of the `New-GuestConfigurationPolicy` cmdlet:
105
106
-**Description**: Policy description.
106
107
-**Parameter**: Policy parameters provided in a hash table.
107
108
-**PolicyVersion**: Policy version.
108
-
-**Path**: Destination path where policy definitions are created. This is NOT a path a local copy of the package.
109
+
-**Path**: Destination path where policy definitions are created. Don't specify this parameter as
110
+
the path to a local copy of the package.
109
111
-**Platform**: Target platform (Windows/Linux) for machine configuration policy and content
110
112
package.
111
-
-**Mode**: (case sensitive: `ApplyAndMonitor`, `ApplyAndAutoCorrect`, `Audit`) choose if the policy should audit
112
-
or deploy the configuration. The default is `Audit`.
113
-
-**Tag** adds one or more tag filters to the policy definition
114
-
-**Category** sets the category metadata field in the policy definition
115
-
-**LocalContentPath** (Optional) - The path to the local copy of the `.zip` Machine Configuration package file (Required if you are using a User Assigned Managed Identity to provide access to an Azure Storge blob)
116
-
-**ManagedIdentityResourceId** (Optional) - The resourceId of the User Assigned Managed Identity with read access to the Azure Storage blob containing the `.zip` Machine Configuration package file (Required if you are using a User Assigned Managed Identity to provide access to an Azure Storge blob)
117
-
-**`-ExcludeArcMachines`** (Optional) - A flag to exclude Arc machines from the generated Policy definition (Required if you are using a User Assigned Managed Identity to provide access to an Azure Storge blob)
113
+
-**Mode**: (case sensitive: `ApplyAndMonitor`, `ApplyAndAutoCorrect`, `Audit`) choose if the
114
+
policy should audit or deploy the configuration. The default is `Audit`.
115
+
-**Tag**: Adds one or more tag filters to the policy definition.
116
+
-**Category**: Sets the category metadata field in the policy definition.
117
+
-**LocalContentPath**: The path to the local copy of the `.zip` Machine Configuration package
118
+
file. This parameter is required if you're using a User Assigned Managed Identity to provide
119
+
access to an Azure Storge blob.
120
+
-**ManagedIdentityResourceId**: The `resourceId` of the User Assigned Managed Identity that has
121
+
read access to the Azure Storage blob containing the `.zip` Machine Configuration package file.
122
+
This parameter is required if you're using a User Assigned Managed Identity to provide access to
123
+
an Azure Storge blob.
124
+
-**ExcludeArcMachines**: Specifies that the Policy definition should exclude Arc machines. This
125
+
parameter is required if you are using a User Assigned Managed Identity to provide access to an
126
+
Azure Storge blob.
118
127
119
128
> [!IMPORTANT]
120
-
> - Please note that, unlike Azure VMs, Arc-connected machines currently do not support User Assigned Managed Identities. As a result, the `-ExcludeArcMachines` flag is required to ensure the exclusion of those machines from the policy definition.
121
-
> - Additionally, for the Azure VM to download the assigned package and apply the policy, the Guest Configuration Windows Agent Version 1.29.82.0 OR Linux Agent Version 1.26.76.0 is required
129
+
> Unlike Azure VMs, Arc-connected machines currently do not support User Assigned Managed
130
+
> Identities. As a result, the `-ExcludeArcMachines` flag is required to ensure the exclusion of
131
+
> those machines from the policy definition. For the Azure VM to download the assigned package and
132
+
> apply the policy, the Guest Configuration Agent must be version `1.29.82.0` or higher for Windows
133
+
> and version `1.26.76.0` or higher for Linux.
122
134
123
135
For more information about the **Mode** parameter, see the page
124
136
[How to configure remediation options for machine configuration][02].
@@ -156,26 +168,29 @@ $PolicyConfig2 = @{
156
168
New-GuestConfigurationPolicy @PolicyConfig2
157
169
```
158
170
159
-
Create a policy definition that **enforces** a custom configuration package using a User-Assigned Managed Identity:
171
+
Create a policy definition that **enforces** a custom configuration package using a User-Assigned
172
+
Managed Identity:
160
173
161
174
```powershell
162
175
$PolicyConfig3 = @{
163
-
PolicyId = '_My GUID_'
164
-
ContentUri = $contentUri
165
-
DisplayName = 'My deployment policy'
166
-
Description = 'My deployment policy'
167
-
Path = './policies/deployIfNotExists.json'
168
-
Platform = 'Windows'
169
-
PolicyVersion = 1.0.0
170
-
Mode = 'ApplyAndAutoCorrect'
171
-
contentLocalPath = "C:\Local\Path\To\Package" # Required parameter for managed identity
172
-
managedIdentityResourceId = "YourManagedIdentityResourceId" # Required parameter for managed identity
176
+
PolicyId = '_My GUID_'
177
+
ContentUri = $contentUri
178
+
DisplayName = 'My deployment policy'
179
+
Description = 'My deployment policy'
180
+
Path = './policies/deployIfNotExists.json'
181
+
Platform = 'Windows'
182
+
PolicyVersion = 1.0.0
183
+
Mode = 'ApplyAndAutoCorrect'
184
+
ContentLocalPath = "C:\Local\Path\To\Package" # Required parameter for managed identity
185
+
ManagedIdentityResourceId = "YourManagedIdentityResourceId" # Required parameter for managed identity
# How to provide secure access to custom machine configuration packages
10
-
This page provides a guide on how to provide access to Machine Configuration packages stored in Azure storage by using the resource ID of a user-assigned managed identity or a Shared Access Signature (SAS) token.
10
+
11
+
This page provides a guide on how to provide access to Machine Configuration packages stored in
12
+
Azure storage by using the resource ID of a user-assigned managed identity or a Shared Access
13
+
Signature (SAS) token.
11
14
12
15
## Prerequisites
16
+
13
17
- Azure subscription
14
18
- Azure Storage account with the Machine Configuration package
15
-
19
+
16
20
## Steps to provide access to the package
21
+
22
+
The following steps prepare your resources for more secure operations. TThe code snippets for the
23
+
steps include values in angle brackets, like `<storage-account-container-name>`, which you must
24
+
replace with a valid value when following the steps. If you just copy and paste the code, the
25
+
commands may raise errors due to invalid values.
26
+
17
27
### Using a User Assigned Identity
18
28
19
29
> [!IMPORTANT]
20
-
> Please note that, unlike Azure VMs, Arc-connected machines currently do not support User-Assigned Managed Identities.
30
+
> Please note that, unlike Azure VMs, Arc-connected machines currently do not support User-Assigned
31
+
> Managed Identities.
21
32
22
-
You can grant private access to a machine configuration package in an Azure Storage blob by assigning a [User-Assigned Identity][01] to a scope of Azure VMs. For this to work, you need to grant the managed identity read access to the Azure storage blob. This involves assigning the “Storage Blob Data Reader” role to the identity at the scope of the blob container. This setup ensures that your Azure VMs can securely read from the specified blob container using the user-assigned managed identity. You can assign a User Assigned Identity at scale in your server fleet using Azure Policy, learn more [here][02].
33
+
You can grant private access to a machine configuration package in an Azure Storage blob by
34
+
assigning a [User-Assigned Identity][01] to a scope of Azure VMs. For this to work, you need to
35
+
grant the managed identity read access to the Azure storage blob. This involves assigning the
36
+
"Storage Blob Data Reader" role to the identity at the scope of the blob container. This setup
37
+
ensures that your Azure VMs can securely read from the specified blob container using the
38
+
user-assigned managed identity. To learn how you can assign a User Assigned Identity at scale, see
39
+
[Use Azure Policy to assign managed identities][02].
23
40
24
-
### Using a SAS Token
25
-
Optionally, you can add a shared access signature (SAS) token in the URL to ensure secure access to the package. The below example generates a blob SAS token with read access and returns the full blob URI with the shared access signature token. In this example, the token has a time limit of three years.
41
+
### Using a SAS Token
42
+
43
+
Optionally, you can add a shared access signature (SAS) token in the URL to ensure secure access to
44
+
the package. The below example generates a blob SAS token with read access and returns the full
45
+
blob URI with the shared access signature token. In this example, the token has a time limit of
By using the resource ID of a user-assigned managed identity or SAS token, you can securely provide access to Machine Configuration packages stored in Azure storage. The additional parameters and flags ensure that the package is retrieved using the managed identity and that Azure Arc machines are not included in the policy scope.
66
+
67
+
By using the resource ID of a user-assigned managed identity or SAS token, you can securely provide
68
+
access to Machine Configuration packages stored in Azure storage. The additional parameters ensure
69
+
that the package is retrieved using the managed identity and that Azure Arc machines aren't
70
+
included in the policy scope.
45
71
46
72
## Next Steps
47
-
- After creating the policy definition, you can assign it to the appropriate scope (e.g., management group, subscription, resource group) within your Azure environment.
48
-
- Remember to monitor the policy compliance status and make any necessary adjustments to your Machine Configuration package or policy assignment to meet your organizational requirements.
73
+
- After creating the policy definition, you can assign it to the appropriate scope, like management
74
+
group, subscription, or resource group, within your Azure environment.
75
+
- Remember to monitor the policy compliance status and make any necessary adjustments to your
76
+
Machine Configuration package or policy assignment to meet your organizational requirements.
Parameters of the `Protect-GuestConfigurationPackage` cmdlet:
87
102
88
-
-**Path**: Full path of the machine configuration package.
103
+
-**Path**: Full path to the machine configuration package.
89
104
-**Certificate**: Code signing certificate to sign the package. This parameter is only supported
90
105
when signing content for Windows.
106
+
-**PrivateGpgKeyPath**: Full path to the private key `.gpg` file. This parameter is only supported
107
+
when signing content for Linux.
108
+
-**PublicGpgKeyPath**: Full path to the public key `.gpg` file. This parameter is only supported
109
+
when signing content for Linux.
110
+
91
111
92
112
## Certificate requirements
93
113
94
-
The machine configuration agent expects the certificate public key to be present in "Trusted Publishers" on Windows machines and in the path `/usr/local/share/ca-certificates/gc`
95
-
on Linux machines. For the node to verify signed content, install the certificate public key on the
96
-
machine before applying the custom policy. This process can be done using any technique inside the
97
-
VM or by using Azure Policy. An example template is available
98
-
[to deploy a machine with a certificate][01]. The Key Vault access policy must allow the Compute
99
-
resource provider to access certificates during deployments. For detailed steps, see
114
+
The machine configuration agent expects the certificate public key to be present in "Trusted
115
+
Publishers" on Windows machines and in the path `/usr/local/share/ca-certificates/gc` on Linux
116
+
machines. For the node to verify signed content, install the certificate public key on the machine
117
+
before applying the custom policy.
118
+
119
+
You can install the certificate public key using normal tools inside the VM or by using Azure
120
+
Policy. An [example template using Azure Policy][01] shows how you can deploy a machine with a
121
+
certificate. The Key Vault access policy must allow the Compute resource provider to access
122
+
certificates during deployments. For detailed steps, see
100
123
[Set up Key Vault for virtual machines in Azure Resource Manager][02].
101
124
102
125
Following is an example to export the public key from a signing certificate, to import to the
0 commit comments