Bylaw

Gallery › Key Vault › Azure Community Policy

Key vault - Firewall Settings DENY

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This Azure Policy denies the deployment of an Azure Key Vault when the 'Allow access from' setting is not set to 'Private endpoints and selected networks' or when the Firewall does contain any IP addresses outside of the approved ones.

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

Azure Policy JSONazurepolicy.json · 72 lines
{
  "name": "864b2733-2252-425c-ba49-2742a6c4baed",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Key vault - Firewall Settings DENY",
    "description": "This Azure Policy denies the deployment of an Azure Key Vault when the 'Allow access from' setting is not set to 'Private endpoints and selected networks' or when the Firewall does contain any IP addresses outside of the approved ones.",
    "metadata": {
      "version": "1.0.0",
      "category": "Key Vault"
    },
    "mode": "All",
    "parameters": {
      "allowedAddressRanges": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Address Ranges",
          "description": "The list of IP Addresses or IP Address Ranges that are allowed for the Firewall Setting on the Key Vault"
        }
      },
      "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.KeyVault/vaults"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "count": {
                      "field": "Microsoft.KeyVault/vaults/networkAcls.ipRules[*]"
                    },
                    "greater": 0
                  },
                  {
                    "not": {
                      "field": "Microsoft.KeyVault/vaults/networkAcls.ipRules[*].value",
                      "in": "[parameters('allowedAddressRanges')]"
                    }
                  }
                ]
              },
              {
                "field": "Microsoft.KeyVault/vaults/networkAcls.defaultAction",
                "equals": "Allow"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw864b2733-2252-425c-ba49-2742a6c4baed.bylaw.ps1 · 44 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '864b2733-2252-425c-ba49-2742a6c4baed' {

    Properties @{
        DisplayName = 'Key vault - Firewall Settings DENY'
        Description = 'This Azure Policy denies the deployment of an Azure Key Vault when the ''Allow access from'' setting is not set to ''Private endpoints and selected networks'' or when the Firewall does contain any IP addresses outside of the approved ones.'
        Version     = '1.0.0'
        Category    = 'Key Vault'
        Mode        = 'All'
    }

    Parameter AllowedAddressRanges @{
        Type        = 'Array'
        DisplayName = 'Allowed Address Ranges'
        Description = 'The list of IP Addresses or IP Address Ranges that are allowed for the Firewall Setting on the Key Vault'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.KeyVault/vaults' {

        Require 'networkAcls.ipRules and value are as required' {
            AnyOf {
                Count 'networkAcls.ipRules[*]' | Must -Be 0
                AllOf {
                    Field networkAcls.ipRules | Must -Exist
                    Each 'networkAcls.ipRules[*]' {
                        Field value | Must -BeIn (Param AllowedAddressRanges) -Strict
                    }
                }
            }
        }

        Require 'networkAcls.defaultAction is not Allow' {
            Field networkAcls.defaultAction | Must -Not -Be 'Allow' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Key Vault/key-vault-firewall-settings-deny/azurepolicy.json in Azure/Community-Policy, under the MIT licence.