Bylaw

Gallery › Network › Azure Community Policy

Deny route with next hop type internet

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Deny route with next hop type internet to ensure data loss prevention. 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 · 67 lines
{
  "name": "0206980b-8fa9-4dc5-b9fb-0a7b706a00b9",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Deny route with next hop type internet",
    "description": "Deny route with next hop type internet to ensure data loss prevention. 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": {
      "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
              }
            ]
          },
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Network/routeTables/routes"
              },
              {
                "field": "Microsoft.Network/routeTables/routes/nextHopType",
                "equals": "Internet"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw0206980b-8fa9-4dc5-b9fb-0a7b706a00b9.bylaw.ps1 · 39 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '0206980b-8fa9-4dc5-b9fb-0a7b706a00b9' {

    Properties @{
        DisplayName = 'Deny route with next hop type internet'
        Description = 'Deny route with next hop type internet to ensure data loss prevention. 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 Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource * {

        Require 'type, routes and nextHopType are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Network/routeTables' -IfPresent
                Each 'Microsoft.Network/routeTables/routes[*]' {
                    Field nextHopType | Must -Not -Be 'Internet'
                }
            }
        }

        Require 'type and nextHopType 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
            }
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/deny-route-with-next-hop-type-internet/azurepolicy.json in Azure/Community-Policy, under the MIT licence.