Gallery › Network › Azure Community Policy
Prevent route with next hop type Internet - nexthop FW
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This policy should prevent that there should be no nexthop that is to the Internet.
All routes should be next hop Azure Firewall.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 75 lines
{
"name": "8eed80dc-bb35-4d7f-9cce-5be046ab0c7c",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Prevent route with next hop type Internet - nexthop FW",
"description": "This policy should prevent that there should be no nexthop that is to the Internet.\nAll routes should be next hop Azure Firewall.",
"metadata": {
"category": "Network",
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"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": {
"field": "Microsoft.Network/routeTables/routes[*].nextHopType",
"equals": "Internet"
}
},
"greater": 0
},
{
"field": "Microsoft.Network/routeTables/subnets[*].id",
"notContains": "AzureFirewallSubnet"
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/routeTables/routes"
},
{
"field": "Microsoft.Network/routeTables/routes/nextHopType",
"equals": "Internet"
},
{
"field": "Microsoft.Network/routeTables/subnets[*].id",
"notContains": "AzureFirewallSubnet"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw8eed80dc-bb35-4d7f-9cce-5be046ab0c7c.bylaw.ps1 · 46 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '8eed80dc-bb35-4d7f-9cce-5be046ab0c7c' {
Properties @{
DisplayName = 'Prevent route with next hop type Internet - nexthop FW'
Description = 'This policy should prevent that there should be no nexthop that is to the Internet.
All routes should be next hop Azure Firewall.'
Category = 'Network'
Version = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource * {
Require 'type, routes, nextHopType and 2 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/routeTables' -IfPresent
Each 'Microsoft.Network/routeTables/routes[*]' {
Field nextHopType | Must -Not -Be 'Internet'
}
Count 'Microsoft.Network/routeTables/subnets[*]' -Where {
Field id | Must -ContainText 'AzureFirewallSubnet'
} | Must -Not -Be 0
}
}
Require 'type, nextHopType, subnets and 1 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/routeTables/routes' -IfPresent
Field 'Microsoft.Network/routeTables/routes/nextHopType' | Must -Not -Be 'Internet' -IfPresent
Count 'Microsoft.Network/routeTables/subnets[*]' -Where {
Field id | Must -ContainText 'AzureFirewallSubnet'
} | Must -Not -Be 0
}
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/prevent-route-with-next-hop-type-internet-nexthop-fw/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw