GithubHelp home page GithubHelp logo

azure / azure-policy Goto Github PK

View Code? Open in Web Editor NEW
1.4K 127.0 1.0K 12.8 MB

Repository for Azure Resource Policy built-in definitions and samples

License: MIT License

Open Policy Agent 100.00%
azure policy

azure-policy's Introduction

Azure Policy Samples

This repository contains the direct representation of built-in definitions published to Azure. For easy search of all built-in with descriptions, see Policy samples on docs.microsoft.com.

For custom policy samples, check out our Community repo! (https://github.com/Azure/Community-Policy)

Contributing

To contribute, please submit your policies to our Community repo! (https://github.com/Azure/Community-Policy)

Reporting Issues

The support for addressing built-in definition issues is handled by Azure Customer Support. Open a new Azure Customer Support ticket if you believe a definition has a bug or error.

Azure Policy Known Issues

Check here for a current list of known issues for Azure Policy.

Azure Policy Resources

Articles

References

Getting Support

The general Azure Policy support role of this repository has transitioned to standard Azure support channels. See below for information about getting support help for Azure Policy.

Alias Requests

An alias enables you to restrict what values or conditions are permitted for a property on a resource. Each alias maps to the paths in different API versions for a given resource type. During policy evaluation, the policy engine gets the property path for that API version. See the documentation page on aliases here. For additional information about Azure Policy and aliases, visit this blog post.

Support for requesting aliases is handled by Azure Customer Support. Open a new Azure Customer Support ticket if you believe you need new aliases to be published.

This page documents the commands for discovering existing aliases.

General Questions

If you have questions you haven't been able to answer from the Azure Policy documentation, there are a few places that host discussions on Azure Policy:

If your questions are more in-depth or involve information that is not public, open a new Azure Customer Support ticket.

Documentation Corrections

To report issues in the Azure Policy online documentation, look for a feedback area at the bottom of the page. If you don't see a place to enter feedback, you can also directly open a new issue at the Microsoft Docs GitHub.

Other Support for Azure Policy

If you are encountering livesite issues or difficulties in implementing new policies that may be due to problems in Azure Policy itself, open a support ticket at Azure Customer Support. If you want to submit an idea for consideration, add an idea or upvote an existing idea at Azure Governance Ideas.

Known Issues

Azure Policy operates at a level above other Azure services by applying policy rules against PUT requests and GET responses of resource types going between Azure Resource Manager and the owning resource provider (RP). In a few cases, the behavior of a given RP is unexpected or incompatible in some way with Azure Policy. The Azure Policy team works with the RP teams to close these gaps as soon as possible after they are discovered. Usually aliases for properties of these resource types will be removed after the anomalous behavior is discovered. Issues of this nature will be documented here until final resolution.

All cases of known resource types with anomalous policy behavior are listed here. Currently there is no way to make these resource types invisible at policy authoring time, so writing policies that attempt to manage these resource types cannot be prevented, despite the fact that the results of such policies may be either incomplete or incorrect.

Resource Type query results incomplete, missing, or non-standard format

In some cases, certain RPs may return incomplete or otherwise limited or missing information about resources of a given type. The Azure Policy engine is unable to determine the compliance of any resources of such a type. Below are listed the known resource types exhibiting this problem.

  • Microsoft.Web/sites/config/* (except Microsoft.Web/sites/config/web)
  • Microsoft.Web/sites/slots/config/* (except Microsoft.Web/sites/slots/config/web)

Currently, there is no plan to change this behavior for the above Microsoft.Web resource types. If this scenario is important to you, please open a support ticket with the Web team.

  • Microsoft.HDInsights/clusters/computeProfile.roles[*].scriptActions
  • Microsoft.Sql/servers/auditingSettings
    • This type will work correctly as the related resource in AuditIfNotExists and DeployIfNotExists policies, as long as a name for the resource is provided, e.g:
              "details": {
                "type": "Microsoft.Sql/servers/auditingSettings",
                "name": "default"
              }
    
  • Microsoft.DataLakeStore/accounts
    • This type behaves similarly to Microsoft.Sql/servers/auditingSettings. Compliance of some fields cannot be determined except in AuditIfNotExists and DeployIfNotExists policies.
  • Microsoft.DataLakeStore/accounts/encryptionState
    • This property of this type is populated differently when queried than when created or updated unless non-standard parameters are provided. This means deny policies will work, but compliance audits will generally not be correct.
  • Microsoft.Sql 'master' database
    • This type behaves similarly to Microsoft.Sql/servers/auditingSettings. Compliance of some fields cannot be determined except in AuditIfNotExists and DeployIfNotExists policies.
  • Microsoft.Compute/virtualMachines/instanceView
    • Collection query of this type is missing many properties, which means compliance checks may not work.
  • Microsoft.Network/virtualNetworks/subnets
    • The routeTable property of this type is populated differently when queried than when created or updated unless non-standard parameters are provided. This means deny policies will work, but compliance audits will generally not be correct.
  • Microsoft.Insights/workbooks
    • The collection GET API call for this type doesn't return all workbooks, which could result in some or all workbook resources being incorrectly flagged as non-compliant.
  • Microsoft.Maintenance/configurationAssignments
    • This type does not support LIST API which does not allow for compliance results to be populated.
  • Microsoft.Maintenance/applyUpdates
    • This type does not support LIST API which does not allow for compliance results to be populated.
  • Microsoft.Cdn/CdnWebApplicationFirewallPolicies
    • This type does not support LIST API which does not allow for compliance results to be populated. This type also does not support GET API calls at a subscription level which can lead to incorrect compliance results over time.
  • Microsoft.EventGrid/eventSubscriptions
    • This type does not support LIST API which does not allow for compliance results to be populated.

Resource Type not correctly published by resource provider

In some cases, a resource provider may implement a resource type, but not correctly publish it to the Azure Resource Manager. The result of this is that Azure Policy is unable to discover the type in order to determine compliance. In some cases, this still allows deny policies to work, but compliance results will usually be incorrect. These are the resource types known to have this behavior:

  • Microsoft.DBforPostgreSQL/serverGroupsv2
  • Microsoft.AppConfiguration/ConfigurationStores

In some cases the unpublished resource type is actually a subtype of a published type, which causes aliases to refer to a parent type instead of the unpublished type. Evaluation of such policies fails, causing the policy to never apply to any resource.

These resource types previously exhibited this behavior but have been fixed:

  • Microsoft.EventHub/namespaces/networkrulesets
  • Microsoft.ServiceBus/namespaces/networkrulesets
  • Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies
  • Microsoft.ApiManagement/service/portalsettings/delegation
  • Microsoft.Storage/storageAccounts/blobServices

Resource management that bypasses Azure Resource Manager

Resource providers are free to implement their own resource management operations outside of Azure Resource Manager ("dataplane" operations). In almost every Azure resource type, the distinction between resource management and dataplane operations is clear and the resource provider only implements resource management one way. Occasionally, a resource provider may choose to implement a type that can be managed both ways. In this case, Azure Policy controls the standard Azure Resource Manager API normally, but operations on the direct resource provider API to create, modify and delete resources of that type bypass Azure Resource Manager so they are invisible to Azure Policy. Since policy enforcement is incomplete, we recommend that customers do not implement policies targeting such a resource type. This is the list of known such resource types:

  • Microsoft.Storage/storageAccounts/blobServices/containers

The storage team has implemented blob public access control on storage accounts to address this scenario. Per-account public access control of blobs can be controlled by Azure Policy using the new alias Microsoft.Storage/storageAccounts/allowBlobPublicAccess.

  • Microsoft.Sql/servers/firewallRules

Firewall rules can be created/deleted/modified via T-SQL commands, which bypasses Azure Policy. There is currently no plan to address this.

  • Microsoft.ServiceFabric/clusters/applications

Service Fabric applications created via direct requests to the Service Fabric cluster (i.e. via New-ServiceFabricApplication) will not appear in the Azure Resource Manager representation of the Service Fabric cluster. Policy will not be able to audit/enforce these applications.

Note that Azure policies for dataplane operations of certain targeted resource providers is also supported or under active development. Please see the Resource Provider modes.

Nonstandard creation pattern

In a few instances, the creation pattern of a resource type doesn't follow normal REST patterns. In these cases, deny policies may not work or may only work for some properties. For example, certain resource types may PUT only a subset of the properties of the resource type to create the entire resource. With such types the resource provider selects the values for properties not provided in the payload. Such a resource might be created with a non-compliant value even though a deny policy exists to prevent it. A similar result may occur if a set of resource types can be created using a collection PUT. Known resource types that exhibit this class of behavior:

  • Microsoft.Automation/certificates
  • Microsoft.Security/securityContacts

There is currently no plan to change this behavior for these types. If this scenario is important to you, please open a support ticket with the Azure SQL or Automation team.

Nonstandard update pattern through Azure Portal

In some cases, a resource provider can choose not to follow normal REST patterns when a resource is updated via the portal. In these cases, a partial PUT request is done instead of a PATCH request causing the policy engine to evaluate as if some properties do not have values.

  • Microsoft.Web/sites

Provider pass-through to non Azure Resource Manager resources

There are examples where a resource provider publishes a resource type to Azure Resource Manager, but the resources it represents cannot be managed by Azure Resource Manager. For example, Microsoft.Web has published several resource types to Azure Resource Manager that actually represent resources of the customer's site rather than Azure Resource Manager resources. Such resources cannot or should not be managed by Azure policy, and are explicitly excluded. All known examples are listed here:

  • Microsoft.Web/sites/deployments
  • Microsoft.Web/sites/functions
  • Microsoft.Web/sites/instances/deployments
  • Microsoft.Web/sites/siteextensions
  • Microsoft.Web/sites/slots/deployments
  • Microsoft.Web/sites/slots/functions
  • Microsoft.Web/sites/slots/instances/deployments
  • Microsoft.Web/sites/slots/siteextensions
  • Microsoft.Web/sites/sourcecontrols
  • Microsoft.Web/sites/slots/sourcecontrols
  • Microsoft.Web/sites/privateaccess

Legacy or incorrect aliases

Since custom policies use aliases directly, it is usually not possible to update them without causing unintended side effects to existing custom policies. This means that aliases referring to incorrect information or following legacy naming conventions must be left in place, even though it may cause confusion. In certain cases where an alias is known to refer to the wrong information, another alias may be created as a corrected alternative to the known bad one. In these cases, the new alias will be given the name of the bad alias with .v2 appended. For example a bad alias named Microsoft.ResourceProvider/someType/someAlias would result in the addition of a corrected version named Microsoft.ResourceProvider/someType/someAlias.v2. If an alias is added to correct a .v2 alias it will be named by replacing v2 with v3. All known corrected aliases are listed here:

  • Microsoft.Sql/servers/databases/requestedServiceObjectiveName.v2

To enforce around SQL databases transparentDataEncryption, please use both the legacy alias (api versions between 2014-04-01 and 2022-05-01-preview) Microsoft.Sql/transparentDataEncryption.status and the new alias (post api version 2022-05-01-preview) Microsoft.Sql/servers/databases/transparentDataEncryption/state.

Resource property names that include symbols or numbers such as dashings '-' or slashes '/' are a nonstandard creation pattern and alias for those properities are not generated.

Optional or auto-generated resource property that bypasses policy evaluation

In a few instances, when creating a resource from Azure Portal, the property is not set in the PUT request payload. When the request reaches the resource provider, the resource provider generates the property and sets the value. Because the property is not in the request payload, the policy cannot evaluate the property. Known resource fields that exhibit this class of behavior:

  • Microsoft.Storage/storageAccounts/networkAcls.defaultAction
  • Microsoft.Authorization/roleAssignments/principalType
  • Microsoft.Compute/virtualMachines/storageProfile.osDisk.osType
  • Microsoft.Compute/virtualMachines/storageProfile.osDisk.diskSizeGB
  • Microsoft.Compute/virtualMachineScaleSets/virtualMachineProfile.storageProfile.osDisk.diskSizeGB
  • Microsoft.Compute/virtualMachineScaleSets/virtualMachines/storageProfile.osDisk.diskSizeGB
  • Microsoft.Authorization/roleAssignmentScheduleInstances/* (all aliases)
  • Microsoft.Cache/Redis/privateEndpointConnections[*]
  • Microsoft.Cache/Redis/privateEndpointConnections[*].provisioningState
  • Microsoft.Cache/Redis/privateEndpointConnections[*].privateLinkServiceConnectionState.status

Using this type of alias in the existence condition of auditIfNotExists or deployIfNotExists policies works correctly. These two kinds of effects will get the full resource content to evaluate the existence condition. The property is always present in GET request payloads.

Using this type of alias in audit/deny/append effect policies works partially. The compliance scan result will be correct for existing resources. However, when creating/updating the resource, there will be no audit events for audit effect policies and no deny or append behaviors for deny/append effect policies because of the missing property in the request payload.

  • Microsoft.Databricks/* (Creation time only)

All Databricks resources bypass policy enforcement at creation time. Databricks resources will have policy enforcement post-creation. To provide feedback on this, please leverage the Databricks UserVoice.

Resources that are exempt from policy evaluation

  • Microsoft.Resources/*, except resource groups and subscriptions.
    • For example, Microsoft.Resources/deployments and Microsoft.Resources/templateSpecs are not evaluated by policy.
  • Microsoft.Billing/*
  • Microsoft.Capacity/reservationOrders/*
  • Microsoft.Help/*
  • Microsoft.Diagnostics/*

Resource types that exceed current enforcement and compliance scale

There some resource types that are generated at very high scale. These are not suitable for management by Azure Policy because the enforcement and compliance checks create overhead that can negatively impact the performance of the API itself. Most of these are not significant policy scenarios, but there are a few exceptions.

These are resource types that have significant policy scenarios, but are not supported by Azure Policy due to the above scalability considerations:

  • Microsoft.ServiceBus/namespaces/topics
  • Microsoft.ServiceBus/namespaces/topics/authorizationRules
  • Microsoft.ServiceBus/namespaces/topics/subscriptions
  • Microsoft.ServiceBus/namespaces/topics/subscriptions/rules

Work to increase the scale that policy can be performantly applied to resource types is in progress. Planned availability date is not yet determined.

Alias changes

May 2020: Microsoft.DocumentDB/databaseAccounts/ipRangeFilter updated from a string property to an array. Please re-author your custom definitions to support the property as an array.
July 2020: The alias Microsoft.Sql/servers/securityAlertPolicies/emailAddresses[] and related policies were deprecated.

Resource types that do not display non-compliance messages in the portal during preflight validation

There are resource types that do not properly display non-compliance messages in the portal during preflight validation, but instead they show a link to the activity log.

This behavior is seen in the following resource types:

  • Microsoft.Kusto/clusters
  • Microsoft.Cdn/profiles
  • Microsoft.ContainerRegistry/registries
  • Microsoft.Cache/Redis

This behavior is also seen in resource types from the following RPs:

  • Microsoft.DataLakeAnalytics
  • Microsoft.DataLakeStore
  • Microsoft.DBforMySQL
  • Microsoft.HDInsight

Azure Policy Extension for Arc is not compatible on Kubernetes 1.25 (preview) version

Policy extension for Arc installation will fail on 1.25 clusters with the following error code and message: Code: ExtensionOperationFailed "err [unable to build kubernetes objects from release manifest: unable to recognize "": no matches for kind "PodSecurityPolicy" in version "policy/v1beta1"]} occurred while doing the operation :"

Mitigation: Avoid using K8s 1.25 (preview) with the Azure Policy Extension for Arc. The extension can be used with any GA supported version such as 1.22, 1.23, or 1.24. Feature team is actively working on fixing this issue. We will update this known issue once the resolution is available.

For support involving these compliance message issues, please first follow up with the respective RP listed above.

Resource types that do not support creation of Policy exemptions

These resource types do not allow Policy exemptions on resources due to deny assignments. Workaround is to use exclusions at the assignment level.

  • Microsoft.Databricks/*

Resource types with unsupported property names

Currently Azure Policy supports only alphanumeric characters for property and alias names. There are a handful of resource types with property names containing non-alphanumeric characters. These properties cannot currently be onboarded to Azure Policy:

Microsoft.Cache/Redis/

  • redisConfiguration.rdb-backup-enabled
  • redisConfiguration.rdb-backup-frequency
  • redisConfiguration.rdb-backup-max-snapshot-count
  • redisConfiguration.rdb-storage-connection-string
  • redisConfiguration.aof-storage-connection-string-0
  • redisConfiguration.aof-storage-connection-string-1
  • redisConfiguration.maxfragmentationmemory-reserved
  • redisConfiguration.maxmemory-policy
  • redisConfiguration.maxmemory-reserved
  • redisConfiguration.maxmemory-delta
  • redisConfiguration.aof-backup-enabled
  • redisConfiguration.zonal-configuration
  • redisConfiguration.preferred-data-archive-auth-method
  • redisConfiguration.preferred-data-persistence-auth-method

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

azure-policy's People

Contributors

bigshika avatar calecarter avatar camillemarie avatar carpenike avatar cmendible avatar cyl33922072 avatar dcthegeek avatar dependabot[bot] avatar gokmen-msft avatar gunnarcampo avatar gunnarcms avatar jimgbritt avatar kenieva avatar krnese avatar kyleburnsdev avatar mentat9 avatar mgreenegit avatar microsoftopensource avatar nehakulkarni123 avatar nreisch avatar pilor avatar prkuma avatar ramyasreechakka avatar rjygraham avatar robga avatar sajudaniel avatar shanhix1 avatar sotkarras avatar sw47 avatar weeyin83 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-policy's Issues

Alias request: "Microsoft.Web/sites/config/http20Enabled"

  • Scenario
    Permit to check that webapp have http 2.0 Enabled

  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/http20Enabled",
"equals": "true"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

Support to manage parameter value inside jSON file

Saying that I would like to allow a few subnets with public IP addresses similar to the following example

{
	"if": {
		"allOf": [
			{
				"field": "type",
				"equals": "Microsoft.Network/networkInterfaces"
			},
			{
				"not": {
					"field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].publicIpAddress.id",
					"exists": false
				}
			},
			{
				"not": {
					"field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].subnet.id",
					"in": "[parameters('subnetIds')]"
				}
			}
		]
	},
	"then": {
		"effect": "deny"
	}
}

Is there a backlog that Microsoft supports adding whitelist directly in my JSON definition? It is similar to strongType location which allows me to do as follows:

      {
        "field": "location",
        "notIn": [
          "southeastasia"
          "westeurope",
        ]
      },

@pilor

Alias request: "Microsoft.Web/sites/config/minTlsVersion"

  • Scenario
    Permit to check that webapp are secure by using only TLS 1.2

  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/minTlsVersion",
"equals": "1.2"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

Alias request: Microsoft.Network/networkInterfaces/ipConfigurations[*].privateIPAllocationMethod

Scenario

Deny Dynamic IP Address allocation on subnet.

Definition

{
	"properties": {
		"displayName": "Enforce Static IP",
		"description": "Enforce Static IP",
		"parameters": {
			
			"effect": {
                "type": "String",
                "allowedValues": [
                    "auditIfNotExists",
                    "deny"
                ],
                "metadata": {
                    "displayName": "Policy Effect"
                }
            },
			
			"setting": {
                "type": "String",
                "allowedValues": [
                    "Dynamic",
                    "Static"
                ],
                "metadata": {
                    "displayName": "Threat Detection Setting"
                }
            }
		
		},
		"policyRule": {
			"if": {
				"allOf": [
					{
						"field": "type",
						"equals": "Microsoft.Network/networkInterfaces"
					},
					{
						"field": "Microsoft.Network/networkInterfaces/ipConfigurations[*].privateIPAllocationMethod",
						"notEquals": "[parameters('setting')]"
					}
				]
			},
			"then": {
				"effect": "[parameters('effect')]",
				"details": {

                    "type": "Microsoft.Network/networkInterfaces",

                    "name": "default",

                    "existenceCondition": {

                        "allOf": [

                            {

                                "field": "Microsoft.Network/networkInterfaces/ipConfigurations[*].privateIPAllocationMethod",

                                "notEquals": "[parameters('effect')]"

                            }

                        ]

                    }

                }
			}
			
		}
	}
}
'''

Alias Request: webApplicationFirewallConfiguration.enabled

Scenario
Use Azure Policy to validate that the WAF is enabled should the SKU allow it.
Definition

{
  "properties": {
    "displayName": "Allowed Application Gateway WAF Configuration",
    "description": "This policy enables you to specify whether the WAF is enabled.",
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/applicationGateways"
          },
          {
            "not": {
              "field": "Microsoft.Network/applicationGateways/sku.name",
              "equals": "Standard"
            }
          },
          {
            "not": {
              "field": "Microsoft.Network/applicationGateways/webApplicationFirewallConfiguration.enabled",
              "equals": "true"
            }
          }
        ]
      },
      "then": {
        "effect": "Deny"
      }
    }
  }
}

Enforce AHUB Policy

Hi,

FTE here, feel free to reach out. Wanted to provide some general feedback as well as some feedback/raise an issue specific to the Enforcing AHUB policy.

I tested the Enforce AHUB policy in a subscription of mine and ran into an issue where Linux distros could no longer be deployed as they do not have the Microsoft.Compute/LicenseType attribute. My understanding is that Microsoft.Compute/LicenseType will return $null, and $null IS in fact not equal to "Windows_Server" which will register as $true and deny the build. I see a few way to get around this, 1) adding a condition that Microsoft.Compute/LicenseType notequals $null, or 2) adding some logic to ensure the ImageOffer is also "WindowsServer" or "WindowsServerSemiAnnual. These aren't fully flushed out, as certain offer types, like Nano server are contained, but don't offer AHUB. I've attached a work around that I use, however I manually checked which Microsoft Published Offers/Skus had AHUB available. Hoping I can get help vetting and testing a more flushed out solution that doesn't block Linux VMs.

As for general feedback, Azure Policy is a super powerful tool, but more documentation and PowerShell options would be really helpful here. It seems like there is a bit of overlap in Aliases within policy, e.g. Microsoft.Compute/imageSku & Microsoft.Compute/virtualMachines/imageSku. Mapping the aliases to REST API attributes might be helpful. This led to some of my confusion with modifying the sample AHUB template. Also would be useful to provide some cmdlets regarding policy initiatives, as I only see the option to create these in the Portal. Would be happy to help in this effort in any way possible or answer/ask additional questions.

sampleAHUBDeny.txt

Alias request: Microsoft.Security/complianceResults/pricings

** Scenario **

Need to use Azure Policy to ensure all subscriptions in a Management Group are using standard tier of Security Center

** Definition **

{
"policyRule": {
"if": {
"not": {
"field": "Microsoft.Security/complianceResults/pricings",
"equals": "Standard"
}
},
"then": {
"effect": "deny"
}
}
}

Alias Request: "Microsoft.Network/networkInterfaces/networkSecurityGroup.IpConfigurations[*].ApplicationSecurityGroups.Id"

Scenario: force application of a default Application Security Group to a VM NIC.
Definition:
{
"type": "Microsoft.Authorization/policyDefinitions",
"name": "enforce-asg-on-nic-test",
"properties": {
"displayName": "ASG X on every nic",
"description": "This policy enforces a specific app security group on every virtual network interface",
"parameters": {
"asgId": {
"type": "string",
"metadata": {
"description": "Resource Id of the App Security Group",
"displayName": "App Security Group Id",
"strongType": "appsecuritygroup"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkInterfaces"
},
{
"not": {
"field": "Microsoft.Network/networkInterfaces/networkSecurityGroup.IpConfigurations[0].ApplicationSecurityGroups.Id",
"equals": "[parameters('asgId')]"
}
}
]
},
"then": {
"effect": "append",
"details": [
{
"field": "Microsoft.Network/networkInterfaces/networkSecurityGroup.IpConfigurations[0].ApplicationSecurityGroups.Id",
"value": "[parameters('asgId')]"
}
]
}
}
}
}

The policy 'effect' property value cannot be 'DeployIfNotExists'.

Deploy if not exist doesnt work with the given example for network watcher

New-AzureRmPolicyDefinition : InvalidPolicyRuleEffect : The policy definition 'deploy-NW-in-vnet-regions' rule is invalid. The policy 'effect' property value cannot be 'DeployIfNotExists'.
At line:1 char:15

  • ... efinition = New-AzureRmPolicyDefinition -Name "deploy-NW-in-vnet-regi ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [New-AzureRmPolicyDefinition], ErrorResponseMessageException
    • FullyQualifiedErrorId : InvalidPolicyRuleEffect,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicyDefinitionCmdlet

Any idea what to do ?

Access Control (IAM) in Azure Policy

Like other Azure services, Access Control (IAM) should be in place to see who have rights to read and create policy. It'd be good for policy access control so nobody can edit and modify policy without rights.

Microsoft.HDInsight/clusters/properties.clusterVersion

Scenario : Allow Provisioning of HDInsight Cluster which supports Secure data transfer (https). HDInsight with version 3.6 or newer only supports secured https connection with storage accounts.

Definition:
{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.HDInsight/clusters"
},
{
"not": {
"field": "Microsoft.HDInsight/clusters/properties.clusterVersion",
"equals": "3.6.1000.0"
}
}
]
},
"then": {
"effect": "audit"
}
}
}

Alias request: Microsoft.Network/virtualNetworks/subnets/addressPrefix

Scenario

Would like to be able to create policies based on subnet address prefixes.
For example see below:

Definition

{
    "type": "Microsoft.Authorization/policyDefinitions",
    "name": "disallow-subnet-address-prefix",
    "properties": {
        "displayName": "Disallow certain subnet address prefixes",
        "description": "This policy disallows specified address prefixes",
        "parameters": {
            "addrPrefix": {
                "type": "String",
                "metadata": {
                    "description": "Subnet Address Prefix",
                    "displayName": "AddressPrefix"
                }
            }
        },
        "policyRule": {
            "if": {
                "anyOf": [
                    {
                        "allOf": [
                            {
                                "field": "type",
                                "equals": "Microsoft.Network/virtualNetworks/subnets"
                            },
                            {
                                "not": {
                                    "field": "Microsoft.Network/virtualNetworks/subnets/addressPrefix",
                                    "like": "[parameters('addrPrefix')]"
                                }
                            }
                        ]
                    }
                ]
            },
            "then": {
                "effect": "deny"
            }
        }
    }
}

Policy not being enforced

Hi guys,

I've created the policy definition and assigned to my VS Pro subscription.
However, I am still able to create a Resource Group without fail.
I have tried changed the resource type from "Microsoft.Resources/subscriptions/resourceGroups" to "Microsoft.Resources/resourceGroups" wondering if it was an issue with that. But that didn't work either.

Wondering if I'm missing something?

Cheers,
Tim

Alias request for Microsoft.HDInsight/clusters/properties/securityProfile.domain and Microsoft.HDInsight/clusters/properties/securityProfile.ldapUrls

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.HDInsight/clusters"
},
{
"not": {
"field": "Microsoft.HDInsight/clusters/properties/securityProfile.domain",
"equals": "dummy ad"
}
},
{
"not": {
"field": "Microsoft.HDInsight/clusters/properties/securityProfile.ldapUrls",
"equals": "dummy ldap"
}
}

            ]
        },
        "then": {
            "effect": "audit"
        }
    }
}

Alias request: "Microsoft.Web/sites/config/ipSecurityRestrictions"

  • Scenario
    Permit to check that webapp are correctly compliant with IP restrictions, for allow only IP Adress allowed
  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/siteAuthEnabled",
"in": ["1.2.3.4,1.2.3.5"]
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

Policy Initiative Assignment created from PowerShell cannot be edited in the Portal

I am using the examples to create a policy initiative, and then assign this to a subscription. Upon doing so, I am able to view the configuration using Powershell, however, when viewing in the portal, you get a 'broken' Azure blade (Dark cloud with raindrop). If I create the same assignment via the portal, this works fine. I can see that by using powershell, there are some properties missing - i.e. metadata, and notScopes (the latter is actually an array with a count of zero in the configuration via the portal)

Any ideas why this might be?

Alias Request: webApplicationFirewallConfiguration.firewallMode

Scenario
Use Azure Policy to check/enforce the WAF firewall mode.
Definition
{
"properties": {
"displayName": "Allowed Application Gateway WAF Mode",
"description": "This policy enables you to detect if the WAF is in detection or prevention mode.",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/applicationGateways"
},
{
"not": {
"field": "Microsoft.Network/applicationGateways/webApplicationFirewallConfiguration.firewallMode",
"equals": "Prevention"
}
}
]
},
"then": {
"effect": "Deny"
}
}
}
}

Alias Request: Microsoft.Network/networkSecurityGroups/subnets[*].id, Microsoft.Network/networkSecurityGroups/networkinterfaces[*].id

Scenario
Need to use Azure Policy to audit empty Network Security Groups. NSGs that are not associated with any Interface or Subnet.

Alias:
Microsoft.Network/networkSecurityGroups/subnets[].id
Microsoft.Network/networkSecurityGroups/subnets/id
Microsoft.Network/networkSecurityGroups/networkinterfaces[
].id
Microsoft.Network/networkSecurityGroups/networkinterfaces/id

** Definition **

{
"type": "Microsoft.Authorization/policyDefinitions",
"name": "audit-empty-nsg",
"properties": {
"displayName": "Check if the NSG is empty",
"description": "This policy will audit any empty NSG.",
"parameters": {
"subnetsId": {
"type": "String",
"metadata": {
"description": "Resource Id of the Subnet",
"displayName": "NSG Id"
}
},
"interfacesId": {
"type": "String",
"metadata": {
"description": "Resource Id of the Interface",
"displayName": "NSG Id"
}
}
},
"policyRule": {
"if": {
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/subnets[].id",
"equals": "[parameters('subnetsId')]"
}
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups/subnets"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/subnets/id",
"equals": "[parameters('subnetsId')]"
}
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/networkinterfaces[
].id",
"equals": "[parameters('interfacesId')]"
}
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups/networkinterfaces"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/networkinterfaces/id",
"equals": "[parameters('interfacesId')]"
}
}
]
}
]
},
"then": {
"effect": "audit"
}
}
}
}

Alias request: "Microsoft.Web/site/config/httpsOnly"

To ensure confidentiality, I'd like to audit https enablement on my web app which can be found in httpsOnly. Below is the sample definition

{
  "policyRule":{
    "if":{
      "allOf":[
        {
          "field":"type",
          "equals":"Microsoft.Web/sites/config"
        },
        {
          "field":"Microsoft.Web/sites/config/httpsOnly",
          "equals":"true"
        }
        ]},
        "then":
        {
          "effect":"audit"
        }},
        "parameter":{},
        "metadata":{
          "category":"Web App Security"
        }
} 

SQL DB/Server deny policy for auditing/TDE/threat detection?

Hi,

I am trying to create policies for SQL Server /db resources where auditing/TDE/threat detection is not enabled. I am using the definition provided ate below url and only changing the effect from auditIfNotExists to deny, but it's not working as per the compliance screen(it shows correctly configured db's also as non-compliante). We have the elastic pool setup configured in our db's.

Please suggest how to apply deny policy for db's/servers which are not configured for auditing/TDE/threat detection?

policy deifnition for tde;

{
  "if": {
    "field": "type",
    "equals": "Microsoft.SQL/servers/databases"
  },
  "then": {
    "effect": "deny",
    "details": {
      "type": "Microsoft.SQL/servers/databases/transparentDataEncryption",
      "name": "current",
      "existenceCondition": {
        "field": "Microsoft.Sql/transparentDataEncryption.status",
        "equals": "Disabled" //I tried enabled too
      }
    }
  }
}

Thanks

Events tab shows no event

As far as my understanding, when Azure Policy scans, events are recorded and displayed in Events tab. But from what I've noticed, there is no event shown.

What does exactly Event mean? The tooltip seems to show a hint but still not to be clear (Events are recorded when policy effect is exercised after resource evaluation).

Alias request: Microsoft.Web/hostingEnvironments.clusterSettings for DisableTls1.0 and FrontEndSSLCipherSuiteOrder

Scenario

Disable TLS 1.0 & FrontEndSSLCipherSuiteOrder on App Service Environment.

customers who are dealing with PCI compliance audits, is how to explicitly disable TLS 1.0 for their apps.

This policy will provide required governance assurance to deny ASE createion with TLS 1.0 enabled

Definition

I am not sure how properties settings will surface in policy definition as this is KV pair under properties.

"resources": [
{
   "apiVersion": "2015-08-01",
   "type": "Microsoft.Web/hostingEnvironments",
   "name": ...,
   "location": ...,
   "properties": {
      "clusterSettings": [
         {
                         "name": "DisableTls1.0",
                         "value": "1"

         }
      ],
      "workerPools": [ ...],
      etc...
   }
}


'''

Need Alias for Microsoft.Storage/storageAccounts/networkAcls.bypass

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"not": {
"field": "Microsoft.Storage/storageAccounts/networkAcls.bypass",
"contains": "[parameters('Exceptions')]"
}
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"Exceptions": {
"type": "String",
"metadata": {
"displayName": "Exceptions",
"description": "Exceptions"
}
}
},
"metadata": {}
}

Alias request: "Microsoft.Web/site/config/clientCertEnabled"

To ensure my web app to use mutual client authentication which is considered a security practice, I'd like to audit clientCertEnabled. Below is the sample definition

{
  "policyRule":{
    "if":{
      "allOf":[
        {
          "field":"type",
          "equals":"Microsoft.Web/sites/config"
        },
        {
          "field":"Microsoft.Web/sites/config/clientCertEnabled",
          "equals":"true"
        }
        ]},
        "then":
        {
          "effect":"audit"
        }},
        "parameter":{},
        "metadata":{
          "category":"Web App Security"
        }
} 

Alias request: "Microsoft.Web/sites/config/siteAuthEnabled"

  • Scenario
    Permit to check that webapp are correctly authentification settings enabled

  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/siteAuthEnabled",
"equals": "true"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

Alias request for Microsoft.Devices/IotHubs/sku.name

Scenario
Use Azure policy to validate SKUs on Azure IoT Hub services.

Rule

{
	"if": {
		"allOf": [
			{
				"field": "type",
				"equals": "Microsoft.Devices/IotHubs"
			},
			{
				"not": {
                    "field": "Microsoft.Devices/IotHubs/sku.name",
                    "in": "[parameters('listOfSKUId')]"
				}
			}
		]
	},
	"then": {
		"effect": "deny"
	}
}

Alias Request: webApplicationFirewallConfiguration.disabledRuleGroups

Scenario
Use Azure Policy to audit the existence of any disabled OWASP rule groups. This may require the addition of a count property to query if there are any items in the collection, as I think the property will always exist regardless of its contents.
Definition

{
  "properties": {
    "displayName": "Disabled Application Gateway WAF Rules",
    "description": "This policy allows you to detect if any of the OWASP rule sets used in the WAF are disabled.",
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/applicationGateways"
          },
          {
            "field": "Microsoft.Network/applicationGateways/webApplicationFirewallConfiguration.disabledRuleGroups",
            "exists": "true"
          }
        ]
      },
      "then": {
        "effect": "Audit"
      }
    }
  }
}

Location isn't indicated in my Allowed locations template

I created a built-in policy Allowed location and assigned to my target resource. The policy is effective. However, when I checked definition template I didn't see location indicated.

{
  "if": {
    "allOf": [
      {
        "field": "location",
        "notIn": "[parameters('listOfAllowedLocations')]"
      },
      {
        "field": "location",
        "notEquals": "global"
      },
      {
        "field": "type",
        "notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
      }
    ]
  },
  "then": {
    "effect": "deny"
  }
}

There must be a value inside this element notIn": "[parameters('listOfAllowedLocations')]" but where exactly I can find to adjust?

Make policy scan activities to be more transparent

I've realized that the policy scan activities are not transparent and almost time I have nothing to know if a scan or batch of scan is done and when.

Moreover, if I change my condition in policy definition and click Save, when does the assignment get triggered? Is it an immediate trigger?

Alias request: Microsoft.compute/virtualMachines/networkInterfaces

Scenario

There is a scenario in which controlled virtual machines should not have any Public IP addresses associated with its relatively NICs.

Definition

{
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Network/networkInterfaces"
        },
        {
          "not": {
            "field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].publicIpAddress.id",
            "exists": false
          }
        },
        {
            "field":"type",
            "equals": "Microsoft.Compute/virtualMachine/networkProfile[*].networkInterfaces.id"
        }
      ]
    },
    "then": {
      "effect": "audit"
    }
  }

Remark

Currently Azure Policy supports listing out all NICs with PIP (Public IP) but I'd love to know which non-compliant VMs are in place.

[Update] I also tested with NIC field`` as follows:

        {
            "not":{
            "field":"Microsoft.Compute/virtualMachines/networkInterfaces[*].id",
            "exists": false
            }
        }

But it seems like the result is not going to be out as expected (displaying non-compliant VMs)

@pilor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.