Skip to content

Commit df2d5ef

Browse files
authored
Added binding reference Azure#2995 (Azure#2996)
* Added binding reference Azure#2995 * Updated baseline metadata * Change log updates
1 parent f8b3053 commit df2d5ef

13 files changed

+316
-148
lines changed

docs/CHANGELOG-v1.md

+116-57
Large diffs are not rendered by default.

docs/concepts/policy-as-rules.md

+29-10
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ For example:
8686
Export-AzPolicyAssignmentRuleData -AssignmentFile '.\<subscriptionId>.assignment.json'
8787
```
8888

89+
## Running policy rules
90+
91+
Rules and an initial baseline are generated in a file ending in `.Rule.jsonc`.
92+
This file extension and format are automatically detected by PSRule when it is run from an included source path.
93+
To start using the policy rules, copy the file to the default include sub-directory (`.ps-rule/`) in the root of your repository.
94+
95+
Additionally, the following setup is required to scan Infrastructure as Code (IaC):
96+
97+
1. Set a binding configuration.
98+
2. Configure expansion for processing Bicep or ARM templates.
99+
3. Include the `PSRule.Rules.Azure` module.
100+
4. Optionally specify a baseline to limit the rules evaluated to policy rules.
101+
102+
### Generated baseline
103+
104+
<!-- module:version v1.33.0 -->
105+
106+
When exporting policies, PSRule for Azure will automatically generate a baseline including any generated rules.
107+
By default, this baseline is called `Azure.PolicyBaseline.All`.
108+
If you change the prefix of generated rules the baseline will be named `<Prefix>.PolicyBaseline.All`.
109+
110+
See [Using baselines](../working-with-baselines.md#using-baselines) for examples on how to use a baseline in a run.
111+
89112
## Customizing the generated rules
90113

91114
PSRule for Azure allows you to:
@@ -108,16 +131,6 @@ configuration:
108131
- /providers/Microsoft.Authorization/policyDefinitions/b54ed75b-3e1a-44ac-a333-05ba39b99ff0
109132
```
110133
111-
## Generated baseline
112-
113-
<!-- module:version v1.33.0 -->
114-
115-
When exporting policies, PSRule for Azure will automatically generate a baseline including any generated rules.
116-
By default, this baseline is called `Azure.PolicyBaseline.All`.
117-
If you change the prefix of generated rules the baseline will be named `<Prefix>.PolicyBaseline.All`.
118-
119-
See [Using baselines](../working-with-baselines.md#using-baselines) for examples on how to use a baseline in a run.
120-
121134
## Duplicate policies
122135
123136
<!-- module:version v1.33.0 -->
@@ -143,3 +156,9 @@ This allows you to:
143156
- Reduce noise reporting the same issue multiple times.
144157
145158
To override this behavior use the `-KeepDuplicates` parameter switch when running `Export-AzPolicyAssignmentRuleData`.
159+
160+
## Recommended content
161+
162+
- [Using custom rules](../customization/using-custom-rules.md)
163+
- [Creating your pipeline](../creating-your-pipeline.md)
164+
- [Working with baselines](../working-with-baselines.md)

docs/customization/enforce-codeowners.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ Some key points to call out with the rule snippet include:
6060
PSRule for Azure exposes a `Template` and `Parameter` source for resources originating from a template.
6161

6262
!!! Tip
63-
For recommendations on naming and storing rules see [storing custom rules][3].
63+
For recommendations on naming and storing rules see [using custom rules][3].
6464

65-
[3]: storing-custom-rules.md
65+
[3]: using-custom-rules.md
6666

6767
## Binding type
6868

@@ -78,8 +78,8 @@ To configure type binding:
7878
# Configure binding options
7979
binding:
8080
targetType:
81-
- 'resourceType'
82-
- 'type'
81+
- 'resourceType'
82+
- 'type'
8383
```
8484
8585
Some key points to call out include:

docs/customization/enforce-custom-tags.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ Some key points to call out with the rule snippet include:
4343
- The automatic variable `$TargetObject` automatically exposes the current resource being processed.
4444

4545
!!! Tip
46-
For recommendations on naming and storing rules see [storing custom rules][1].
46+
For recommendations on naming and storing rules see [using custom rules][1].
4747

48-
[1]: storing-custom-rules.md
48+
[1]: using-custom-rules.md
4949

5050
## Adding mandatory tags
5151

@@ -147,12 +147,12 @@ To configure type binding:
147147
- Create/ update the `ps-rule.yaml` file within the root of the repository.
148148
- Add the following configuration snippet.
149149

150-
```yaml
150+
```yaml title="ps-rule.yaml"
151151
# Configure binding options
152152
binding:
153153
targetType:
154-
- 'resourceType'
155-
- 'type'
154+
- 'resourceType'
155+
- 'type'
156156
```
157157
158158
Some key points to call out include:

docs/customization/storing-custom-rules.md

-62
This file was deleted.
+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
description: This topic covers how you can use custom rules to test Azure Infrastructure as Code.
3+
author: BernieWhite
4+
---
5+
6+
# Using custom rules
7+
8+
PSRule for Azure covers common use cases that align to the [Microsoft Azure Well-Architected Framework (WAF)][1].
9+
In addition to WAF alignment you may have a requirement to enforce organization specific rules.
10+
11+
For example:
12+
13+
- Required tags on a resource group.
14+
- Code ownership for sensitive resource types.
15+
- Apply similar controls to Infrastructure as Code that are deployed via Azure Policies.
16+
17+
PSRule allows custom rules to be layered on.
18+
These custom rules work side-by-side with PSRule for Azure.
19+
20+
[1]: https://learn.microsoft.com/azure/well-architected/
21+
22+
!!! Abstract
23+
This topic covers how you can use custom rules to test Azure Infrastructure as Code (IaC).
24+
25+
## Requirements
26+
27+
For custom rules to work with IaC the following requirements must be configured:
28+
29+
1. Set a binding configuration.
30+
2. Configure expansion for processing Bicep or ARM templates.
31+
3. Include the `PSRule.Rules.Azure` module.
32+
33+
### Set binding configuration
34+
35+
Rules packaged within PSRule for Azure will automatically detect Azure resources by their type properties.
36+
Standalone rules will get their type binding configuration from `ps-rule.yaml` instead.
37+
When binding is not configured, custom rules will typically be ignored.
38+
39+
To configure type binding:
40+
41+
- Create/ update the `ps-rule.yaml` file within the root of the repository.
42+
- Add the following configuration snippet.
43+
44+
```yaml title="ps-rule.yaml"
45+
# Configure binding options
46+
binding:
47+
targetType:
48+
- 'resourceType'
49+
- 'type'
50+
```
51+
52+
### Configuring expansion
53+
54+
PSRule for Azure performs [expansion][2] on Bicep and ARM template files it finds in your repository.
55+
Enabling expansion is required for testing any IaC in your repository.
56+
The requirements for custom rules are no different then using the built-in rules included within PSRule for Azure.
57+
58+
To configure expansion see either:
59+
60+
- [Using Bicep source](../using-bicep.md)
61+
- [Using templates](../using-templates.md)
62+
63+
[2]: ../faq.md#what-is-expansion
64+
65+
### Including PSRule for Azure
66+
67+
When creating custom rules to test Azure IaC including PSRule for Azure is required for most scenarios.
68+
PSRule for Azure performs [expansion][2] on Bicep and ARM template files it finds in your repository.
69+
70+
You can include PSRule for Azure by specifying `PSRule.Rules.Azure` in one of the following:
71+
72+
- **Pipeline** &mdash; The `modules:` parameter in [GitHub Actions or Azure Pipelines][3].
73+
- **PowerShell** &mdash; The `-Module` parameter with the [PowerShell cmdlets][4].
74+
- **Options** &mdash; - The `Include.Module` [option][5].
75+
76+
[3]: ../creating-your-pipeline.md
77+
[4]: ../creating-your-pipeline.md
78+
[5]: https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Options/#includemodule
79+
80+
## Using a standard file path
81+
82+
Rules can be standalone or packaged within a module.
83+
Standalone rules are ideal for a single project such as an Infrastructure as Code (IaC) repository.
84+
To reuse rules across multiple projects consider packaging these as a module.
85+
86+
The instructions for packaging rules in a module can be found here:
87+
88+
- [Packaging rules in a module][6]
89+
90+
To store standalone rules we recommend that you:
91+
92+
- **Use .ps-rule/** &mdash; Create a sub-directory called `.ps-rule` in the root of your repository.
93+
Use all lower-case in the sub-directory name.
94+
Put any custom rules within this sub-directory.
95+
- **Use files ending with .Rule.ps1 | .Rule.yaml | .Rule.jsonc** &mdash;
96+
PSRule uses a file naming convention to discover rules.
97+
We recommend using a file name that ends in `.Rule.ps1` or `.Rule.yaml` or `.Rule.jsonc`.
98+
99+
!!! note
100+
Build pipelines are often case-sensitive or run on Linux-based systems.
101+
Using the casing rule above reduces confusion latter when you configure continuous integration (CI).
102+
103+
[6]: https://microsoft.github.io/PSRule/stable/authoring/packaging-rules/
104+
105+
## Naming rules
106+
107+
When running PSRule, rule names must be unique.
108+
PSRule for Azure uses the name prefix of `Azure.` on all rules and resources included in the module.
109+
110+
!!! example
111+
The following names are examples of rules included within PSRule for Azure:
112+
113+
- `Azure.AKS.Version`
114+
- `Azure.AKS.AuthorizedIPs`
115+
- `Azure.SQL.MinTLS`
116+
117+
When naming custom rules we recommend that you:
118+
119+
- **Use a standard prefix** &mdash; You can use the `Local.` or `Org.` prefix for standalone rules.
120+
- Alternatively choose a short prefix that identifies your organization.
121+
- **Use dotted notation** &mdash; Use dots to separate rule name.
122+
- **Use a maximum length of 35 characters** &mdash; The default view of `Invoke-PSRule` truncates longer names.
123+
PSRule supports longer rule names however if `Invoke-PSRule` is called directly consider using `Format-List`.
124+
125+
## Related content
126+
127+
- [Using Bicep source](using-bicep.md)
128+
- [Using templates](using-templates.md)
129+
- [Creating your pipeline](creating-your-pipeline.md)
130+
131+
*[IaC]: Azure Resource Manager

docs/expanding-source-files.md

+6
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ properties:
179179

180180
To override, configure [`AZURE_MANAGEMENT_GROUP`](setup/configuring-expansion.md#deployment-management-group).
181181

182+
## Related content
183+
184+
- [Using Bicep source](using-bicep.md)
185+
- [Using templates](using-templates.md)
186+
- [Creating your pipeline](creating-your-pipeline.md)
187+
182188
*[WAF]: Well-Architected Framework
183189
*[ARM]: Azure Resource Manager
184190
*[PR]: Pull Request

docs/faq.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ For general FAQ see [PSRule - Frequently Asked Questions (FAQ)][ps-rule-faq], in
2626
## What is a rule?
2727

2828
A rule is a named set of checks and documentation.
29+
Each rule is tests a specific aspect of an Azure resource or deployment to determine if
30+
it is aligned with the [Microsoft Azure Well-Architected Framework][AWAF].
2931
You can find the documentation for each rule under [reference][1].
3032

3133
[1]: en/rules/module.md
34+
[AWAF]: https://learn.microsoft.com/azure/architecture/framework/
3235

3336
## What is a baseline?
3437

@@ -40,9 +43,22 @@ Continue reading [working with baselines][2] for a detailed breakdown.
4043

4144
[2]: working-with-baselines.md
4245

46+
## What is expansion?
47+
48+
Expansion is a feature of PSRule for Azure that converts Azure Infrastructure as Code (IaC) to a testable Azure resource.
49+
IaC format such as Bicep and ARM templates, support dynamic capabilities such parameters, variables, and conditions...
50+
These dynamic capabilities allow customers to create modular reusable code that can scale across an organization.
51+
However, to determine if a specific Azure resource meets the requirements of an organization the final state must be known.
52+
53+
Expansion resolves these dynamic capabilities so that a final state for each resource can be tested by rules.
54+
Noting the final expanded state provided by PSRule for Azure is a close approximation.
55+
This close approximation allows testing of Azure resources offline directly from code before deployment to Azure.
56+
57+
Continue reading [Expanding source files](expanding-source-files.md).
58+
4359
## Is Terraform supported?
4460

45-
Currently PSRule for Azure supports testing Azure resources from Infrastructure as Code (IaC) with:
61+
Currently PSRule for Azure supports testing Azure resources from IaC with:
4662

4763
- Azure Resource Manager (ARM) templates.
4864
- Azure Bicep deployments.
@@ -89,8 +105,6 @@ You may want to use PSRule to enforce tagging or something similar early in a De
89105

90106
We have a walk through scenario [Enforcing custom tags][9] to get you started.
91107

92-
[AWAF]: https://learn.microsoft.com/azure/architecture/framework/
93-
94108
## How do I create a custom rule to enforce code ownership?
95109

96110
GitHub, Azure DevOps, and other DevOps platforms may implement code ownership.

docs/troubleshooting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ There is a few common causes of this issue including:
140140
You may be able to use `git mv` to change the case of a file if it is committed to the repository incorrectly.
141141

142142
[5]: https://aka.ms/ps-rule/naming
143-
[6]: customization/enforce-custom-tags.md#binding-type
143+
[6]: customization/using-custom-rules.md#set-binding-configuration
144144
[12]: working-with-baselines.md#quarterly-baseline
145145
[13]: https://aka.ms/ps-rule/options#ruleincludelocal
146146
[14]: working-with-baselines.md#including-custom-rules

docs/working-with-baselines.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A baseline is a standard PSRule artifact that combines rules and configuration.
88
PSRule for Azure provides several baselines that can be referenced when running PSRule.
99

1010
!!! Abstract
11-
This topic covers how to use the baselines shipped with PSRule for Azure.
11+
This topic covers how to use standard baselines shipped with PSRule for Azure or custom baselines you define.
1212

1313
## Quarterly baselines
1414

mkdocs.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ nav:
6767
- Suppression: concepts/suppression.md
6868
- Policy as rules: concepts/policy-as-rules.md
6969
- Customization:
70-
- Storing custom rules: customization/storing-custom-rules.md
70+
- Using custom rules: customization/using-custom-rules.md
7171
- Enforcing custom tags: customization/enforce-custom-tags.md
7272
- Enforcing code ownership: customization/enforce-codeowners.md
7373
- Permit outbound management: customization/permit-outbound-management.md
@@ -148,7 +148,8 @@ plugins:
148148
install-instructions.md: install.md
149149
validating-locally.md: install.md
150150
using-metadata.md: using-templates.md
151-
customization/index.md: customization/storing-custom-rules.md
151+
customization/index.md: customization/using-custom-rules.md
152+
customization/storing-custom-rules.md: customization/using-custom-rules.md
152153
en/asb-v3.md: en/mcsb-v1.md
153154
setup/configuring-options.md: setup/index.md
154155

0 commit comments

Comments
 (0)