Bylaw

Gallery › Network › Azure Community Policy

Enforce disabling of snat in load balancer rules

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

This policy enforce disabling of snat in load balancer rules.

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

Azure Policy JSONazurepolicy.json · 54 lines
{
  "name": "886b21a3-18e1-4385-9ae1-36c3eebb5103",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Enforce disabling of snat in load balancer rules",
    "description": "This policy enforce disabling of snat in load balancer rules.",
    "metadata": {
      "category": "Network",
      "createdBy": "",
      "updatedBy": null,
      "updatedOn": null,
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "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": [
          {
            "equals": "Microsoft.Network/loadBalancers",
            "field": "type"
          },
          {
            "count": {
              "field": "Microsoft.Network/loadBalancers/loadBalancingRules[*]",
              "where": {
                "equals": false,
                "field": "Microsoft.Network/loadBalancers/loadBalancingRules[*].disableOutboundSnat"
              }
            },
            "greaterOrEquals": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw886b21a3-18e1-4385-9ae1-36c3eebb5103.bylaw.ps1 · 29 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '886b21a3-18e1-4385-9ae1-36c3eebb5103' {

    Properties @{
        DisplayName = 'Enforce disabling of snat in load balancer rules'
        Description = 'This policy enforce disabling of snat in load balancer rules.'
        Category    = 'Network'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Network/loadBalancers' {

        Require 'loadBalancingRules and disableOutboundSnat are as required' {
            Count 'loadBalancingRules[*]' -Where {
                Field disableOutboundSnat | Must -Be $false
            } | Must -Be 0
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/enforce-disabling-of-snat-in-load-balancer-rules/azurepolicy.json in Azure/Community-Policy, under the MIT licence.