Gallery › Network › Azure Community Policy
Deny route with address prefix 0.0.0.0/0 not pointing to the virtual appliance
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
Deny route with address prefix 0.0.0.0/0 not pointing to the virtual appliance. Both creating routes as a standalone resource or nested within their parent resource route table are considered.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 102 lines
{
"name": "00f51d76-8d35-478a-b447-aaee861e794e",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deny route with address prefix 0.0.0.0/0 not pointing to the virtual appliance",
"description": "Deny route with address prefix 0.0.0.0/0 not pointing to the virtual appliance. Both creating routes as a standalone resource or nested within their parent resource route table are considered.",
"metadata": {
"category": "Network",
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"routeTableSettings": {
"type": "Object",
"metadata": {
"displayName": "Route Table Settings",
"description": "Location-specific settings for route tables."
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Deny, Audit or Disabled the execution of the Policy"
},
"allowedValues": [
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/routeTables"
},
{
"count": {
"field": "Microsoft.Network/routeTables/routes[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Network/routeTables/routes[*].addressPrefix",
"equals": "0.0.0.0/0"
},
{
"anyOf": [
{
"field": "Microsoft.Network/routeTables/routes[*].nextHopType",
"notEquals": "VirtualAppliance"
},
{
"field": "Microsoft.Network/routeTables/routes[*].nextHopIpAddress",
"notEquals": "[parameters('routeTableSettings')[field('location')].virtualApplianceIpAddress]"
}
]
}
]
}
},
"greater": 0
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/routeTables/routes"
},
{
"field": "Microsoft.Network/routeTables/routes/addressPrefix",
"equals": "0.0.0.0/0"
},
{
"anyOf": [
{
"field": "Microsoft.Network/routeTables/routes/nextHopType",
"notEquals": "VirtualAppliance"
},
{
"field": "Microsoft.Network/routeTables/routes/nextHopIpAddress",
"notEquals": "[parameters('routeTableSettings')[field('location')].virtualApplianceIpAddress]"
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw00f51d76-8d35-478a-b447-aaee861e794e.bylaw.ps1 · 51 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '00f51d76-8d35-478a-b447-aaee861e794e' {
Properties @{
DisplayName = 'Deny route with address prefix 0.0.0.0/0 not pointing to the virtual appliance'
Description = 'Deny route with address prefix 0.0.0.0/0 not pointing to the virtual appliance. Both creating routes as a standalone resource or nested within their parent resource route table are considered.'
Category = 'Network'
Version = '1.0.0'
Mode = 'All'
}
Parameter RouteTableSettings @{
Type = 'Object'
DisplayName = 'Route Table Settings'
Description = 'Location-specific settings for route tables.'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource * {
Require 'type, routes, addressPrefix and 3 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/routeTables' -IfPresent
Each 'Microsoft.Network/routeTables/routes[*]' -Where {
Field addressPrefix | Must -Be '0.0.0.0/0'
} {
Field nextHopType | Must -Be 'VirtualAppliance' -Strict
Field nextHopIpAddress | Must -Be (Arm '[parameters(''routeTableSettings'')[field(''location'')].virtualApplianceIpAddress]') -Strict
}
}
}
Require 'type, addressPrefix, nextHopType and 2 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/routeTables/routes' -IfPresent
Field 'Microsoft.Network/routeTables/routes/addressPrefix' | Must -Not -Be '0.0.0.0/0' -IfPresent
AllOf {
Field 'Microsoft.Network/routeTables/routes/nextHopType' | Must -Be 'VirtualAppliance'
Field 'Microsoft.Network/routeTables/routes/nextHopIpAddress' | Must -Be (Arm '[parameters(''routeTableSettings'')[field(''location'')].virtualApplianceIpAddress]')
}
}
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/deny-route-with-address-prefix-0.0.0.0-0-not-pointing-to-the-virtual-appliance/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw