Skip to content

Commit d6b282d

Browse files
Merge pull request #270827 from davidsmatlak/ds-restructure-policy-definition-20240401
Restructure content for Azure Policy definition structure
2 parents cfa1ec5 + dc44e39 commit d6b282d

12 files changed

+1221
-1324
lines changed

articles/governance/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ productDirectory:
4747
text: Overview
4848
- url: ./policy/policy-glossary.md
4949
text: Azure Policy glossary
50-
- url: ./policy/concepts/definition-structure.md
50+
- url: ./policy/concepts/definition-structure-basics.md
5151
text: Policy definition structure
5252
- url: ./policy/concepts/effects.md
5353
text: Azure Policy effects

articles/governance/policy/.openpublishing.redirection.policy.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@
809809
"source_path_from_root": "/articles/governance/policy/samples/nz-ism-restricted-3-5.md",
810810
"redirect_url": "/azure/governance/policy/concepts/regulatory-compliance",
811811
"redirect_document_id": false
812+
},
813+
{
814+
"source_path_from_root": "/articles/governance/policy/concepts/definition-structure.md",
815+
"redirect_url": "/azure/governance/policy/concepts/definition-structure-basics",
816+
"redirect_document_id": false
812817
}
813818
]
814819
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Overrides have the following properties:
254254

255255
- `notIn`: The list of not-allowed values for the specified `kind`. Can't be used with `in`. Can contain up to 50 values.
256256

257-
Note that one override can be used to replace the effect of many policies by specifying multiple values in the policyDefinitionReferenceId array. A single override can be used for up to 50 policyDefinitionReferenceIds, and a single policy assignment can contain up to 10 overrides, evaluated in the order in which they're specified. Before the assignment is created, the effect chosen in the override is validated against the policy rule and parameter allowed value list (in cases where the effect is [parameterized](definition-structure.md#parameters)).
257+
Note that one override can be used to replace the effect of many policies by specifying multiple values in the policyDefinitionReferenceId array. A single override can be used for up to 50 policyDefinitionReferenceIds, and a single policy assignment can contain up to 10 overrides, evaluated in the order in which they're specified. Before the assignment is created, the effect chosen in the override is validated against the policy rule and parameter allowed value list (in cases where the effect is [parameterized](./definition-structure-parameters.md)).
258258

259259
## Enforcement mode
260260

@@ -338,7 +338,7 @@ the initiative definition. For details, see
338338
## Parameters
339339

340340
This segment of the policy assignment provides the values for the parameters defined in the
341-
[policy definition or initiative definition](./definition-structure.md#parameters). This design
341+
[policy definition or initiative definition](./definition-structure-parameters.md). This design
342342
makes it possible to reuse a policy or initiative definition with different resources, but check for
343343
different business values or outcomes.
344344

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Details of the policy definition structure aliases
3+
description: Describes how policy definition aliases are used to establish conventions for Azure resources in your organization.
4+
ms.date: 04/01/2024
5+
ms.topic: conceptual
6+
---
7+
8+
# Azure Policy definition structure aliases
9+
10+
You use property aliases to access specific properties for a resource type. Aliases enable you to restrict what values or conditions are allowed for a property on a resource. Each alias maps to paths in different API versions for a given resource type. During policy evaluation, the policy engine gets the property path for that API version.
11+
12+
The list of aliases is always growing. To find which aliases Azure Policy supports, use one of the following methods:
13+
14+
- Azure Policy extension for Visual Studio Code (recommended)
15+
16+
Use the [Azure Policy extension for Visual Studio Code](../how-to/extension-for-vscode.md) to view and discover aliases for resource properties.
17+
18+
:::image type="content" source="../media/extension-for-vscode/extension-hover-shows-property-alias.png" alt-text="Screenshot of the Azure Policy extension for Visual Studio Code hovering over a property to display the alias names.":::
19+
20+
- Azure PowerShell
21+
22+
```azurepowershell-interactive
23+
# Login first with Connect-AzAccount if not using Cloud Shell
24+
25+
# Use Get-AzPolicyAlias to list available providers
26+
Get-AzPolicyAlias -ListAvailable
27+
28+
# Use Get-AzPolicyAlias to list aliases for a Namespace (such as Azure Compute -- Microsoft.Compute)
29+
(Get-AzPolicyAlias -NamespaceMatch 'compute').Aliases
30+
```
31+
32+
> [!NOTE]
33+
> To find aliases that can be used with the [modify](./effects.md#modify) effect, use the
34+
> following command in Azure PowerShell **4.6.0** or higher:
35+
>
36+
> ```azurepowershell-interactive
37+
> Get-AzPolicyAlias | Select-Object -ExpandProperty 'Aliases' | Where-Object { $_.DefaultMetadata.Attributes -eq 'Modifiable' }
38+
> ```
39+
40+
- Azure CLI
41+
42+
```azurecli-interactive
43+
# Login first with az login if not using Cloud Shell
44+
45+
# List namespaces
46+
az provider list --query [*].namespace
47+
48+
# Get Azure Policy aliases for a specific Namespace (such as Azure Compute -- Microsoft.Compute)
49+
az provider show --namespace Microsoft.Compute --expand "resourceTypes/aliases" --query "resourceTypes[].aliases[].name"
50+
```
51+
52+
- REST API
53+
54+
```http
55+
GET https://management.azure.com/providers/?api-version=2019-10-01&$expand=resourceTypes/aliases
56+
```
57+
58+
## Understanding the array alias
59+
60+
Several of the aliases that are available have a version that appears as a _normal_ name and another that has `[*]` attached to it, which is an array alias. For example:
61+
62+
- `Microsoft.Storage/storageAccounts/networkAcls.ipRules`
63+
- `Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]`
64+
65+
- The _normal_ alias represents the field as a single value. This field is for exact match comparison scenarios when the entire set of values must be exactly as defined.
66+
- The array alias `[*]` represents a collection of values selected from the elements of an array resource property. For example:
67+
68+
| Alias | Selected values |
69+
|:---|:---|
70+
| `Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]` | The elements of the `ipRules` array. |
71+
| `Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].action` | The values of the `action` property from each element of the `ipRules` array. |
72+
73+
When used in a [field](./definition-structure-policy-rule.md#fields) condition, array aliases make it possible to compare each individual array element to a target value. When used with [count](./definition-structure-policy-rule.md#count) expression, it's possible to:
74+
75+
- Check the size of an array.
76+
- Check if all\any\none of the array elements meet a complex condition.
77+
- Check if exactly `n` array elements meet a complex condition.
78+
79+
For more information and examples, see [Referencing array resource properties](../how-to/author-policies-for-arrays.md#referencing-array-resource-properties).
80+
81+
## Next steps
82+
83+
- For more information about policy definition structure, go to [basics](./definition-structure-basics.md), [parameters](./definition-structure-parameters.md), and [policy rule](./definition-structure-policy-rule.md).
84+
- For initiatives, go to [initiative definition structure](./initiative-definition-structure.md).
85+
- Review examples at [Azure Policy samples](../samples/index.md).
86+
- Review [Understanding policy effects](effects.md).
87+
- Understand how to [programmatically create policies](../how-to/programmatically-create.md).
88+
- Learn how to [get compliance data](../how-to/get-compliance-data.md).
89+
- Learn how to [remediate non-compliant resources](../how-to/remediate-resources.md).
90+
- Review what a management group is with [Organize your resources with Azure management groups](../../management-groups/overview.md).
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
title: Details of the policy definition structure basics
3+
description: Describes how policy definition basics are used to establish conventions for Azure resources in your organization.
4+
ms.date: 04/01/2024
5+
ms.topic: conceptual
6+
---
7+
8+
# Azure Policy definition structure basics
9+
10+
Azure Policy definitions describe resource compliance [conditions](./definition-structure-policy-rule.md#conditions) and the effect to take if a condition is met. A condition compares a resource property [field](./definition-structure-policy-rule.md#fields) or a [value](./definition-structure-policy-rule.md#value) to a required value. Resource property fields are accessed by using [aliases](./definition-structure-alias.md). When a resource property field is an array, a special [array alias](./definition-structure-alias.md#understanding-the-array-alias) can be used to select values from all array members and apply a condition to each one. Learn more about [conditions](./definition-structure-policy-rule.md#conditions).
11+
12+
By using policy assignments, you can control costs and manage your resources. For example, you can specify that only certain types of virtual machines are allowed. Or, you can require that resources have a particular tag. Assignments at a scope apply to all resources at that scope and below. If a policy assignment is applied to a resource group, it's applicable to all the resources in that resource group.
13+
14+
You use JSON to create a policy definition that contains elements for:
15+
16+
- `displayName`
17+
- `description`
18+
- `mode`
19+
- `metadata`
20+
- `parameters`
21+
- `policyRule`
22+
- logical evaluations
23+
- `effect`
24+
25+
For example, the following JSON shows a policy that limits where resources are deployed:
26+
27+
```json
28+
{
29+
"properties": {
30+
"displayName": "Allowed locations",
31+
"description": "This policy enables you to restrict the locations your organization can specify when deploying resources.",
32+
"mode": "Indexed",
33+
"metadata": {
34+
"version": "1.0.0",
35+
"category": "Locations"
36+
},
37+
"parameters": {
38+
"allowedLocations": {
39+
"type": "array",
40+
"metadata": {
41+
"description": "The list of locations that can be specified when deploying resources",
42+
"strongType": "location",
43+
"displayName": "Allowed locations"
44+
},
45+
"defaultValue": [
46+
"westus2"
47+
]
48+
}
49+
},
50+
"policyRule": {
51+
"if": {
52+
"not": {
53+
"field": "location",
54+
"in": "[parameters('allowedLocations')]"
55+
}
56+
},
57+
"then": {
58+
"effect": "deny"
59+
}
60+
}
61+
}
62+
}
63+
```
64+
65+
For more information, go to the [policy definition schema](https://schema.management.azure.com/schemas/2020-10-01/policyDefinition.json). Azure Policy built-ins and patterns are at [Azure Policy samples](../samples/index.md).
66+
67+
## Display name and description
68+
69+
You use `displayName` and `description` to identify the policy definition and provide context for when the definition is used. The `displayName` has a maximum length of _128_ characters and `description` a maximum length of _512_ characters.
70+
71+
> [!NOTE]
72+
> During the creation or updating of a policy definition, `id`, `type`, and `name` are defined
73+
> by properties external to the JSON and aren't necessary in the JSON file. Fetching the policy
74+
> definition via SDK returns the `id`, `type`, and `name` properties as part of the JSON, but
75+
> each are read-only information related to the policy definition.
76+
77+
## Policy type
78+
79+
While the `policyType` property can't be set, there are three values returned by SDK and visible in the portal:
80+
81+
- `Builtin`: Microsoft provides and maintains these policy definitions.
82+
- `Custom`: All policy definitions created by customers have this value.
83+
- `Static`: Indicates a [Regulatory Compliance](./regulatory-compliance.md) policy definition with
84+
Microsoft **Ownership**. The compliance results for these policy definitions are the results of
85+
non-Microsoft audits of Microsoft infrastructure. In the Azure portal, this value is sometimes
86+
displayed as **Microsoft managed**. For more information, see
87+
[Shared responsibility in the cloud](../../../security/fundamentals/shared-responsibility.md).
88+
89+
## Mode
90+
91+
The `mode` is configured depending on if the policy is targeting an Azure Resource Manager property or a Resource Provider property.
92+
93+
### Resource Manager modes
94+
95+
The `mode` determines which resource types are evaluated for a policy definition. The supported modes are:
96+
97+
- `all`: evaluate resource groups, subscriptions, and all resource types
98+
- `indexed`: only evaluate resource types that support tags and location
99+
100+
For example, resource `Microsoft.Network/routeTables` supports tags and location and is evaluated in both modes. However, resource `Microsoft.Network/routeTables/routes` can't be tagged and isn't evaluated in `Indexed` mode.
101+
102+
We recommend that you set `mode` to `all` in most cases. All policy definitions created through the portal use the `all` mode. If you use PowerShell or Azure CLI, you can specify the `mode` parameter manually. If the policy definition doesn't include a `mode` value, it defaults to `all` in Azure PowerShell and to `null` in Azure CLI. A `null` mode is the same as using `indexed` to support backward compatibility.
103+
104+
`indexed` should be used when creating policies that enforce tags or locations. While not required, it prevents resources that don't support tags and locations from showing up as non-compliant in the compliance results. The exception is resource groups and subscriptions. Policy definitions that enforce location or tags on a resource group or subscription should set `mode` to `all` and specifically target the `Microsoft.Resources/subscriptions/resourceGroups` or `Microsoft.Resources/subscriptions` type. For an example, see [Pattern: Tags - Sample #1](../samples/pattern-tags.md). For a list of resources that support tags, see [Tag support for Azure resources](../../../azure-resource-manager/management/tag-support.md).
105+
106+
### Resource Provider modes
107+
108+
The following Resource Provider modes are fully supported:
109+
110+
- `Microsoft.Kubernetes.Data` for managing Kubernetes clusters and components such as pods, containers, and ingresses. Supported for Azure Kubernetes Service clusters and [Azure Arc-enabled Kubernetes clusters](../../../aks/intro-kubernetes.md). Definitions using this Resource Provider mode use the effects _audit_, _deny_, and _disabled_.
111+
- `Microsoft.KeyVault.Data` for managing vaults and certificates in [Azure Key Vault](../../../key-vault/general/overview.md). For more information on these policy definitions, see [Integrate Azure Key Vault with Azure Policy](../../../key-vault/general/azure-policy.md).
112+
- `Microsoft.Network.Data` for managing [Azure Virtual Network Manager](../../../virtual-network-manager/overview.md) custom membership policies using Azure Policy.
113+
114+
The following Resource Provider modes are currently supported as a [preview](https://azure.microsoft.com/support/legal/preview-supplemental-terms/):
115+
116+
- `Microsoft.ManagedHSM.Data` for managing [Managed Hardware Security Module (HSM)](../../../key-vault/managed-hsm/azure-policy.md) keys using Azure Policy.
117+
- `Microsoft.DataFactory.Data` for using Azure Policy to deny [Azure Data Factory](../../../data-factory/introduction.md) outbound traffic domain names not specified in an allowlist. This Resource Provider mode is enforcement only and doesn't report compliance in public preview.
118+
- `Microsoft.MachineLearningServices.v2.Data` for managing [Azure Machine Learning](../../../machine-learning/overview-what-is-azure-machine-learning.md) model deployments. This Resource Provider mode reports compliance for newly created and updated components. During public preview, compliance records remain for 24 hours. Model deployments that exist before these policy definitions are assigned don't report compliance.
119+
120+
> [!NOTE]
121+
>Unless explicitly stated, Resource Provider modes only support built-in policy definitions, and exemptions are not supported at the component-level.
122+
123+
## Metadata
124+
125+
The optional `metadata` property stores information about the policy definition. Customers can define any properties and values useful to their organization in `metadata`. However, there are some _common_ properties used by Azure Policy and in built-ins. Each `metadata` property has a limit of 1,024 characters.
126+
127+
### Common metadata properties
128+
129+
- `version` (string): Tracks details about the version of the contents of a policy definition.
130+
- `category` (string): Determines under which category in the Azure portal the policy definition is displayed.
131+
- `preview` (boolean): True or false flag for if the policy definition is _preview_.
132+
- `deprecated` (boolean): True or false flag for if the policy definition is marked as _deprecated_.
133+
- `portalReview` (string): Determines whether parameters should be reviewed in the portal, regardless of the required input.
134+
135+
> [!NOTE]
136+
> The Azure Policy service uses `version`, `preview`, and `deprecated` properties to convey level of
137+
> change to a built-in policy definition or initiative and state. The format of `version` is:
138+
> `{Major}.{Minor}.{Patch}`. Specific states, such as _deprecated_ or _preview_, are appended to the
139+
> `version` property or in another property as a **boolean**. For more information about the way
140+
> Azure Policy versions built-ins, see
141+
> [Built-in versioning](https://github.com/Azure/azure-policy/blob/master/built-in-policies/README.md).
142+
> To learn more about what it means for a policy to be _deprecated_ or in _preview_, see [Preview and deprecated policies](https://github.com/Azure/azure-policy/blob/master/built-in-policies/README.md#preview-and-deprecated-policies).
143+
144+
## Definition location
145+
146+
While creating an initiative or policy, it's necessary to specify the definition location. The definition location must be a management group or a subscription. This location determines the scope to which the initiative or policy can be assigned. Resources must be direct members of or children within the hierarchy of the definition location to target for assignment.
147+
148+
If the definition location is a:
149+
150+
- **Subscription** - Only resources within that subscription can be assigned the policy definition.
151+
- **Management group** - Only resources within child management groups and child subscriptions can be assigned the policy definition. If you plan to apply the policy definition to several subscriptions, the location must be a management group that contains each subscription.
152+
153+
For more information, see [Understand scope in Azure Policy](./scope.md#definition-location).
154+
155+
## Next steps
156+
157+
- For more information about policy definition structure, go to [parameters](./definition-structure-parameters.md), [policy rule](./definition-structure-policy-rule.md), and [alias](./definition-structure-alias.md).
158+
- For initiatives, go to [initiative definition structure](./initiative-definition-structure.md).
159+
- Review examples at [Azure Policy samples](../samples/index.md).
160+
- Review [Understanding policy effects](effects.md).
161+
- Understand how to [programmatically create policies](../how-to/programmatically-create.md).
162+
- Learn how to [get compliance data](../how-to/get-compliance-data.md).
163+
- Learn how to [remediate non-compliant resources](../how-to/remediate-resources.md).
164+
- Review what a management group is with [Organize your resources with Azure management groups](../../management-groups/overview.md).

0 commit comments

Comments
 (0)