Skip to content

Commit 9f04368

Browse files
authored
Merge pull request #109239 from mgreenegit/azurepolicy-howto-rbac-0
Azure Policy custom role for DINE, GC How-To
2 parents ed4cc15 + 88eca71 commit 9f04368

File tree

2 files changed

+86
-68
lines changed

2 files changed

+86
-68
lines changed

articles/governance/policy/how-to/guest-configuration-create-linux.md

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ms.topic: how-to
66
---
77
# How to create Guest Configuration policies for Linux
88

9-
Before creating custom policies, it is a good idea to read the conceptual overview information
10-
at the page [Azure Policy Guest Configuration](../concepts/guest-configuration.md).
9+
Before creating custom policies, read the overview information
10+
at [Azure Policy Guest Configuration](../concepts/guest-configuration.md).
1111

1212
To learn about creating Guest Configuration policies for Windows, see the page
1313
[How to create Guest Configuration policies for Windows](./guest-configuration-create.md)
@@ -28,9 +28,8 @@ non-Azure machine.
2828
2929
## Install the PowerShell module
3030

31-
The process of creating a Guest Configuration artifact, automated testing of the artifact, creating
32-
a policy definition, and publishing the policy, is entirely automatable using PowerShell. This
33-
module can be installed on a machine running Windows, macOS, or Linux with PowerShell 6.2 or later
31+
Creating a Guest Configuration artifact, automated testing of the artifact, creating
32+
a policy definition, and publishing the policy, is entirely automatable using the Guest Configuration module in PowerShell. The module can be installed on a machine running Windows, macOS, or Linux with PowerShell 6.2 or later
3433
running locally, or with [Azure Cloud Shell](https://shell.azure.com), or with the
3534
[Azure PowerShell Core Docker image](https://hub.docker.com/r/azuresdk/azure-powershell-core).
3635

@@ -71,22 +70,20 @@ To install the **GuestConfiguration** module in PowerShell:
7170
Get-Command -Module 'GuestConfiguration'
7271
```
7372

74-
## Background information regarding Guest Configuration artifacts and policy for Linux
73+
## Guest Configuration artifacts and policy for Linux
7574

76-
Even in Linux environments, Guest Configuration utilizes Desired State Configuration as a language
75+
Even in Linux environments, Guest Configuration uses Desired State Configuration as a language
7776
abstraction. The implementation is based in native code (C++) so it doesn't require loading
78-
PowerShell at this time. However, it does require a configuration MOF file describing basic details
79-
about the environment. DSC is acting as a "wrapper" for InSpec to standardize how it's executed, how
80-
parameters are provided from Azure Resource Manager, and how output is captured and returned to the
77+
PowerShell. However, it does require a configuration MOF describing details
78+
about the environment. DSC is acting as a wrapper for InSpec to standardize how it's executed, how
79+
parameters are provided, and how output is returned to the
8180
service. Little knowledge of DSC is required when working with custom InSpec content.
8281

8382
#### Configuration requirements
8483

85-
The only requirement for Guest Configuration to use a custom configuration file is for the name of
86-
the configuration to be consistent everywhere it's used. This name requirement includes the name of
87-
the .zip file for the content package, the configuration name in the MOF file stored inside the
88-
content package, and the configuration name used in a Resource Manager template as the guest
89-
assignment name.
84+
The name of the custom configuration must be consistent everywhere. The name of
85+
the .zip file for the content package, the configuration name in the MOF file, and the guest
86+
assignment name in the Resource Manager template, must be the same.
9087

9188
### Custom Guest Configuration configuration on Linux
9289

@@ -180,9 +177,7 @@ New-GuestConfigurationPackage `
180177
-ChefProfilePath './'
181178
```
182179

183-
After creating the Configuration package but before publishing it to Azure, you can test the
184-
functionality of the package from your workstation or CI/CD environment. The GuestConfiguration
185-
module includes a cmdlet `Test-GuestConfigurationPackage` that loads the same agent in your
180+
After creating the Configuration package but before publishing it to Azure, you can test the package from your workstation or CI/CD environment. The GuestConfiguration cmdlet `Test-GuestConfigurationPackage` includes the same agent in your
186181
development environment as is used inside Azure machines. Using this solution, you can perform
187182
integration testing locally before releasing to billed cloud environments.
188183

@@ -267,8 +262,7 @@ $uri = publish `
267262
-filePath ./AuditFilePathExists.zip `
268263
-blobName 'AuditFilePathExists'
269264
```
270-
Once a Guest Configuration custom policy package has been created and uploaded to a location
271-
accessible by the machines, create the Guest Configuration policy definition for Azure Policy. The
265+
Once a Guest Configuration custom policy package has been created and uploaded, create the Guest Configuration policy definition. The
272266
`New-GuestConfigurationPolicy` cmdlet takes a custom policy package and creates a policy definition.
273267

274268
Parameters of the `New-GuestConfigurationPolicy` cmdlet:
@@ -307,6 +301,8 @@ Finally, publish the policy definitions using the `Publish-GuestConfigurationPol
307301
The cmdlet only has the **Path** parameter that points to the location of the JSON files
308302
created by `New-GuestConfigurationPolicy`.
309303

304+
To run the Publish command, you need access to create Policies in Azure. The specific authorization requirements are documented in the [Azure Policy Overview](../overview.md) page. The best built-in role is **Resource Policy Contributor**.
305+
310306
```azurepowershell-interactive
311307
Publish-GuestConfigurationPolicy `
312308
-Path '.\policyDefinitions'
@@ -334,6 +330,23 @@ and [Azure PowerShell](../assign-policy-powershell.md).
334330
> assigned, the prerequisites aren't deployed and the policy always shows that '0' servers are
335331
> compliant.
336332
333+
Assigning an Azure Policy with _DeployIfNotExists_ type requires an additional level of access.
334+
To grant the least privilege, you can create a custom role definition
335+
that extends **Resource Policy Contributor**. The example below creates a role named
336+
**Resource Policy Contributor DINE** with the additional permission _Microsoft.Authorization/roleAssignments/write_.
337+
338+
```azurepowershell-interactive
339+
$subscriptionid = '00000000-0000-0000-0000-000000000000'
340+
$role = Get-AzRoleDefinition "Resource Policy Contributor"
341+
$role.Id = $null
342+
$role.Name = "Resource Policy Contributor DINE"
343+
$role.Description = "Can assign Policies that require remediation."
344+
$role.Actions.Clear()
345+
$role.Actions.Add("Microsoft.Authorization/roleAssignments/write")
346+
$role.AssignableScopes.Clear()
347+
$role.AssignableScopes.Add("/subscriptions/$subscriptionid")
348+
New-AzRoleDefinition -Role $role
349+
```
337350

338351
### Using parameters in custom Guest Configuration policies
339352

@@ -343,8 +356,7 @@ override values are provided through Azure Policy and don't impact how the Confi
343356
authored or compiled.
344357

345358
With InSpec, parameters are typically handled as input either at runtime or as code using
346-
attributes. Guest Configuration obfuscates this process so input can be provided to Azure Resource
347-
Manager when policy is assigned. An attributes file is automatically created within the machine. You
359+
attributes. Guest Configuration obfuscates this process so input can be provided when policy is assigned. An attributes file is automatically created within the machine. You
348360
don't need to create and add a file in your project. There are two steps to adding parameters to
349361
your Linux audit project.
350362

@@ -360,7 +372,7 @@ end
360372
```
361373

362374
The cmdlets `New-GuestConfigurationPolicy` and `Test-GuestConfigurationPolicyPackage` include a
363-
parameter named **Parameters**. This parameter takes a hashtable definition including all details
375+
parameter named **Parameters**. This parameter takes a hashtable including all details
364376
about each parameter and automatically creates all the required sections of the files used to create
365377
each Azure Policy definition.
366378

@@ -413,27 +425,24 @@ Configuration AuditFilePathExists
413425

414426
## Policy lifecycle
415427

416-
After you've published a custom Azure Policy using your custom content package, there are two fields
417-
that must be updated if you would like to publish a new release.
428+
If you would like to release an update to the Policy, there are two fields
429+
that require attention.
418430

419431
- **Version**: When you run the `New-GuestConfigurationPolicy` cmdlet, you must specify a version
420432
number greater than what is currently published. The property updates the version of the Guest
421-
Configuration assignment in the new policy file so the extension recognizes that the package
422-
has been updated.
433+
Configuration assignment so the agent recognizes the updated package.
423434
- **contentHash**: This property is updated automatically by the `New-GuestConfigurationPolicy`
424435
cmdlet. It's a hash value of the package created by `New-GuestConfigurationPackage`. The property
425-
must be correct for the `.zip` file you publish. If only the **contentUri** property is updated,
426-
such as in the case where someone could make a manual change to the Policy definition from the
427-
portal, the Extension won't accept the content package.
436+
must be correct for the `.zip` file you publish. If only the **contentUri** property is updated, the Extension won't accept the content package.
428437

429438
The easiest way to release an updated package is to repeat the process described in this article and
430439
provide an updated version number. That process guarantees all properties have been correctly
431440
updated.
432441

433442
## Optional: Signing Guest Configuration packages
434443

435-
Guest Configuration custom policies by default use SHA256 hash to validate the policy package hasn't
436-
changed from when it was published to when it's read by the server that is being audited.
444+
Guest Configuration custom policies use SHA256 hash to validate the policy package hasn't
445+
changed.
437446
Optionally, customers may also use a certificate to sign packages and force the Guest Configuration
438447
extension to only allow signed content.
439448

articles/governance/policy/how-to/guest-configuration-create.md

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ non-Azure machine.
2929
3030
## Install the PowerShell module
3131

32-
The process of creating a Guest Configuration artifact, automated testing of the artifact, creating
33-
a policy definition, and publishing the policy, is entirely automatable using PowerShell. This
34-
module can be installed on a machine running Windows, macOS, or Linux with PowerShell 6.2 or later
32+
Creating a Guest Configuration artifact, automated testing of the artifact, creating
33+
a policy definition, and publishing the policy, is entirely automatable using the Guest Configuration module in PowerShell. The module can be installed on a machine running Windows, macOS, or Linux with PowerShell 6.2 or later
3534
running locally, or with [Azure Cloud Shell](https://shell.azure.com), or with the
3635
[Azure PowerShell Core Docker image](https://hub.docker.com/r/azuresdk/azure-powershell-core).
3736

@@ -72,11 +71,10 @@ To install the **GuestConfiguration** module in PowerShell:
7271
Get-Command -Module 'GuestConfiguration'
7372
```
7473

75-
## Background information regarding Guest Configuration artifacts and policy for Windows
74+
## Guest Configuration artifacts and policy for Windows
7675

77-
Guest Configuration utilizes PowerShell Desired State Configuration as a language abstraction for
78-
writing what audit in Windows and how the audits should be performed. An instance of PowerShell 6.2
79-
is loaded and managed by the agent to host the environment, so there's no conflict with usage of
76+
Guest Configuration uses PowerShell Desired State Configuration as a language abstraction for
77+
writing what to audit in Windows. The agent loads a standalone instance of PowerShell 6.2, so there's no conflict with usage of
8078
PowerShell DSC in Windows PowerShell 5.1, and there's no requirement to pre-install PowerShell 6.2
8179
or later.
8280

@@ -108,9 +106,9 @@ than one reason.
108106
The properties **Code** and **Phrase** are expected by the service. When authoring a custom
109107
resource, set the text (typically stdout) you would like to show as the reason the resource isn't
110108
compliant as the value for **Phrase**. **Code** has specific formatting requirements so reporting
111-
can clearly display information about the resource that was used to perform the audit. This solution
112-
makes Guest Configuration extensible. Any command could be run to audit a machine as long as the
113-
output can be captured and returned as a string value for the **Phrase** property.
109+
can clearly display information about the resource used to do the audit. This solution
110+
makes Guest Configuration extensible. Any command could be run as long as the
111+
output can be returned as a string value for the **Phrase** property.
114112

115113
- **Code** (string): The name of the resource, repeated, and then a short name with no spaces as an
116114
identifier for the reason. These three values should be colon-delimited with no spaces.
@@ -130,16 +128,14 @@ return @{
130128
```
131129
### Configuration requirements
132130

133-
The only requirement for Guest Configuration to use a custom configuration file is for the name of
134-
the configuration to be consistent everywhere it's used. This name requirement includes the name of
135-
the .zip file for the content package, the configuration name in the MOF file stored inside the
136-
content package, and the configuration name used in a Resource Manager template as the guest
137-
assignment name.
131+
The name of the custom configuration must be consistent everywhere. The name of
132+
the .zip file for the content package, the configuration name in the MOF file, and the guest
133+
assignment name in the Resource Manager template, must be the same.
138134

139135
### Scaffolding a Guest Configuration project
140136

141-
For developers who would like to accelerate the process of getting started and working from sample
142-
code, a community project named **Guest Configuration Project** exists as a template for the
137+
Developers who would like to accelerate the process of getting started and work from sample
138+
code can install a community project named **Guest Configuration Project**. The project installs a template for the
143139
[Plaster](https://github.com/powershell/plaster) PowerShell module. This tool can be used to
144140
scaffold a project including a working configuration and sample resource, and a set of
145141
[Pester](https://github.com/pester/pester) tests to validate the project. The template also includes
@@ -226,10 +222,9 @@ New-GuestConfigurationPackage `
226222
-Configuration './Config/AuditBitlocker.mof'
227223
```
228224

229-
After creating the Configuration package but before publishing it to Azure, you can test the
230-
functionality of the package from your workstation or CI/CD environment. The GuestConfiguration
231-
module includes a cmdlet `Test-GuestConfigurationPackage` that loads the same agent in your
232-
development environment as is used inside Azure machines. Using this solution, you can perform
225+
After creating the Configuration package but before publishing it to Azure, you can test the package from your workstation or CI/CD environment. The GuestConfiguration
226+
cmdlet `Test-GuestConfigurationPackage` includes the same agent in your
227+
development environment as is used inside Azure machines. Using this solution, you can do
233228
integration testing locally before releasing to billed cloud environments.
234229

235230
Since the agent is actually evaluating the local environment, in most cases you need to run the
@@ -314,8 +309,7 @@ $uri = publish `
314309
-blobName 'AuditBitlocker'
315310
```
316311

317-
Once a Guest Configuration custom policy package has been created and uploaded to a location
318-
accessible by the machines, create the Guest Configuration policy definition for Azure Policy. The
312+
Once a Guest Configuration custom policy package has been created and uploaded, create the Guest Configuration policy definition. The
319313
`New-GuestConfigurationPolicy` cmdlet takes a custom policy package and creates a policy definition.
320314

321315
Parameters of the `New-GuestConfigurationPolicy` cmdlet:
@@ -354,6 +348,8 @@ Finally, publish the policy definitions using the `Publish-GuestConfigurationPol
354348
cmdlet only has the **Path** parameter that points to the location of the JSON files created by
355349
`New-GuestConfigurationPolicy`.
356350

351+
To run the Publish command, you need access to create Policies in Azure. The specific authorization requirements are documented in the [Azure Policy Overview](../overview.md) page. The best built-in role is **Resource Policy Contributor**.
352+
357353
```azurepowershell-interactive
358354
Publish-GuestConfigurationPolicy `
359355
-Path '.\policyDefinitions'
@@ -381,6 +377,23 @@ initiative with [Portal](../assign-policy-portal.md), [Azure CLI](../assign-poli
381377
> assigned, the prerequisites aren't deployed and the policy always shows that '0' servers are
382378
> compliant.
383379
380+
Assigning an Azure Policy with _DeployIfNotExists_ type requires an additional level of access.
381+
To grant the least privilege, you can create a custom role definition
382+
that extends **Resource Policy Contributor**. The example below creates a role named
383+
**Resource Policy Contributor DINE** with the additional permission _Microsoft.Authorization/roleAssignments/write_.
384+
385+
```azurepowershell-interactive
386+
$subscriptionid = '00000000-0000-0000-0000-000000000000'
387+
$role = Get-AzRoleDefinition "Resource Policy Contributor"
388+
$role.Id = $null
389+
$role.Name = "Resource Policy Contributor DINE"
390+
$role.Description = "Can assign Policies that require remediation."
391+
$role.Actions.Clear()
392+
$role.Actions.Add("Microsoft.Authorization/roleAssignments/write")
393+
$role.AssignableScopes.Clear()
394+
$role.AssignableScopes.Add("/subscriptions/$subscriptionid")
395+
New-AzRoleDefinition -Role $role
396+
```
384397

385398
### Using parameters in custom Guest Configuration policies
386399

@@ -391,11 +404,10 @@ authored or compiled.
391404

392405
The cmdlets `New-GuestConfigurationPolicy` and `Test-GuestConfigurationPolicyPackage` include a
393406
parameter named **Parameters**. This parameter takes a hashtable definition including all details
394-
about each parameter and automatically creates all the required sections of the files used to create
395-
each Azure Policy definition.
407+
about each parameter and creates the required sections of each file used for the Azure Policy definition.
396408

397-
The following example would create an Azure Policy to audit a service, where the user selects from a
398-
list of services at the time of Policy assignment.
409+
The following example creates an Azure Policy to audit a service, where the user selects from a
410+
list when the Policy is assigned.
399411

400412
```azurepowershell-interactive
401413
$PolicyParameterInfo = @(
@@ -422,18 +434,15 @@ New-GuestConfigurationPolicy
422434

423435
## Policy lifecycle
424436

425-
After you've published a custom Azure Policy using your custom content package, there are two fields
426-
that must be updated if you would like to publish a new release.
437+
If you would like to release an update to the Policy, there are two fields
438+
that require attention.
427439

428440
- **Version**: When you run the `New-GuestConfigurationPolicy` cmdlet, you must specify a version
429441
number greater than what is currently published. The property updates the version of the Guest
430-
Configuration assignment in the new policy file so the extension recognizes that the package
431-
has been updated.
442+
Configuration assignment so the agent recognizes the updated package.
432443
- **contentHash**: This property is updated automatically by the `New-GuestConfigurationPolicy`
433444
cmdlet. It's a hash value of the package created by `New-GuestConfigurationPackage`. The property
434-
must be correct for the `.zip` file you publish. If only the **contentUri** property is updated,
435-
such as in the case where someone could make a manual change to the Policy definition from the
436-
portal, the Extension won't accept the content package.
445+
must be correct for the `.zip` file you publish. If only the **contentUri** property is updated, the Extension won't accept the content package.
437446

438447
The easiest way to release an updated package is to repeat the process described in this article and
439448
provide an updated version number. That process guarantees all properties have been correctly
@@ -452,8 +461,8 @@ Policy are the same as for any DSC content.
452461

453462
## Optional: Signing Guest Configuration packages
454463

455-
Guest Configuration custom policies by default use SHA256 hash to validate the policy package hasn't
456-
changed from when it was published to when it's read by the server that is being audited.
464+
Guest Configuration custom policies use SHA256 hash to validate the policy package hasn't
465+
changed.
457466
Optionally, customers may also use a certificate to sign packages and force the Guest Configuration
458467
extension to only allow signed content.
459468

0 commit comments

Comments
 (0)