Bylaw

Gallery › Network › Azure Community Policy

Prevent inbound DNAT on Azure Firewalls

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Prevent inbound DNAT on Azure Firewalls.

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

Azure Policy JSONazurepolicy.json · 55 lines
{
  "name": "dc101f91-16d8-4991-826b-44a5709361d4",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Prevent inbound DNAT on Azure Firewalls",
    "description": "Prevent inbound DNAT on Azure Firewalls.",
    "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/firewallPolicies/ruleCollectionGroups"
          },
          {
            "count": {
              "field": "Microsoft.Network/firewallPolicies/ruleCollectionGroups/ruleCollections[*]",
              "where": {
                "allOf": [
                  {
                    "field": "Microsoft.Network/firewallPolicies/ruleCollectionGroups/ruleCollections[*].FirewallPolicyFilterRuleCollection.rules[*].ruleType",
                    "equals": "NatRule"
                  }
                ]
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawdc101f91-16d8-4991-826b-44a5709361d4.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'dc101f91-16d8-4991-826b-44a5709361d4' {

    Properties @{
        DisplayName = 'Prevent inbound DNAT on Azure Firewalls'
        Description = 'Prevent inbound DNAT on Azure Firewalls.'
        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/firewallPolicies/ruleCollectionGroups' {

        Require 'ruleCollections, FirewallPolicyFilterRuleCollection.rules and ruleType are as required' {
            Each 'ruleCollections[*]' {
                AnyOf {
                    AnyOf {
                        Field FirewallPolicyFilterRuleCollection.rules | Must -Not -Exist
                        Count 'FirewallPolicyFilterRuleCollection.rules[*]' -Where {
                            Field ruleType | Must -Not -Be 'NatRule'
                        } | Must -Not -Be 0
                    }
                }
            }
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/prevent-inbound-dnat-on-azure-firewalls/azurepolicy.json in Azure/Community-Policy, under the MIT licence.