Gallery › Network › Azure Community Policy
Audit peering between two prefixes based on first octate
Uses Condition Policy Audit Disabled Mode All Version 1.0.0
This policy Audits peering between two prefixes based on first octate.
ConvertTo-Bylaw converted this policy, and proved it compiles back to the same definition. Conditions the language can't express yet are written as raw JSON with Condition.
Azure Policy JSONazurepolicy.json · 52 lines
{
"name": "66f16bf4-e60a-43a8-92d4-3d86926127be",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Audit peering between two prefixes based on first octate",
"description": "This policy Audits peering between two prefixes based on first octate.",
"metadata": {
"category": "Network",
"createdBy": "",
"updatedBy": "",
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Audit or Disabled the execution of the Policy"
},
"allowedValues": [
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"equals": "Microsoft.Network/virtualNetworks",
"field": "type"
},
{
"count": {
"field": "Microsoft.Network/virtualnetworks/virtualNetworkPeerings[*].remoteVirtualNetworkAddressSpace.addressPrefixes[*]",
"where": {
"equals": false,
"value": "[contains(string(field('Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes[*]')),concat('\"',split(current('Microsoft.Network/virtualnetworks/virtualNetworkPeerings[*].remoteVirtualNetworkAddressSpace.addressPrefixes[*]'),'.')[0]))]"
}
},
"greater": 0
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw66f16bf4-e60a-43a8-92d4-3d86926127be.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '66f16bf4-e60a-43a8-92d4-3d86926127be' {
Properties @{
DisplayName = 'Audit peering between two prefixes based on first octate'
Description = 'This policy Audits peering between two prefixes based on first octate.'
Category = 'Network'
Version = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Network/virtualNetworks' {
Require 'addressSpace.addressPrefixes and virtualNetworkPeerings.remoteVirtualNetworkAddressSpace.addressPrefixes are as required' {
Condition -Violation '{ "count": { "field": "Microsoft.Network/virtualnetworks/virtualNetworkPeerings[*].remoteVirtualNetworkAddressSpace.addressPrefixes[*]", "where": { "equals": false, "value": "[contains(string(field(''Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes[*]'')),concat(''\"'',split(current(''Microsoft.Network/virtualnetworks/virtualNetworkPeerings[*].remoteVirtualNetworkAddressSpace.addressPrefixes[*]''),''.'')[0]))]" } }, "greater": 0 }'
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/audit-peering-between-two-prefixes-based-on-first-octate/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw