Bylaw

Gallery › Network › Azure Community Policy

Service Endpoints on Subnets

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This Policy will deny/audit Service Endpoints on subnets. Service Endpoints allows the network traffic to bypass Network appliances, such as the Azure Firewall.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONazurepolicy.json · 51 lines
{
  "name": "2ad7cecd-e246-44fa-8215-b366d5781129",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Service Endpoints on Subnets",
    "description": "This Policy will deny/audit Service Endpoints on subnets. Service Endpoints allows the network traffic to bypass Network appliances, such as the 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": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/virtualNetworks/subnets"
          },
          {
            "count": {
              "field": "Microsoft.Network/virtualNetworks/subnets/serviceEndpoints[*]",
              "where": {
                "field": "Microsoft.Network/virtualNetworks/subnets/serviceEndpoints[*].service",
                "exists": true
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw2ad7cecd-e246-44fa-8215-b366d5781129.bylaw.ps1 · 29 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '2ad7cecd-e246-44fa-8215-b366d5781129' {

    Properties @{
        DisplayName = 'Service Endpoints on Subnets'
        Description = 'This Policy will deny/audit Service Endpoints on subnets. Service Endpoints allows the network traffic to bypass Network appliances, such as the 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 'Microsoft.Network/virtualNetworks/subnets' {

        Require 'serviceEndpoints and service are as required' {
            Each 'serviceEndpoints[*]' {
                Field service | Must -Not -Exist
            }
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/service-endpoints-on-subnets/azurepolicy.json in Azure/Community-Policy, under the MIT licence.