Bylaw

Gallery › Key Vault › Azure built-in policies

Configure key vaults to enable firewall

Converted Policy Disabled Modify Mode Indexed Version 1.1.1

Enable the key vault firewall so that the key vault is not accessible by default to any public IPs. You can then configure specific IP ranges to limit access to those networks. Learn more at: https://docs.microsoft.com/azure/key-vault/general/network-security

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

Azure Policy JSONFirewallEnabled_Modify.json · 62 lines
{
  "properties": {
    "displayName": "Configure key vaults to enable firewall",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Enable the key vault firewall so that the key vault is not accessible by default to any public IPs. You can then configure specific IP ranges to limit access to those networks. Learn more at: https://docs.microsoft.com/azure/key-vault/general/network-security",
    "metadata": {
      "version": "1.1.1",
      "category": "Key Vault"
    },
    "version": "1.1.1",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Modify",
          "Disabled"
        ],
        "defaultValue": "Modify"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.KeyVault/vaults"
          },
          {
            "field": "Microsoft.KeyVault/vaults/networkAcls.defaultAction",
            "notEquals": "Deny"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "conflictEffect": "audit",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/f25e0fa2-a7c8-4377-a976-54943a77a395"
          ],
          "operations": [
            {
              "operation": "addOrReplace",
              "field": "Microsoft.KeyVault/vaults/networkAcls.defaultAction",
              "value": "Deny"
            }
          ]
        }
      }
    },
    "versions": [
      "1.1.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ac673a9a-f77d-4846-b2d8-a57f8e1c01dc",
  "name": "ac673a9a-f77d-4846-b2d8-a57f8e1c01dc"
}
Bylawac673a9a-f77d-4846-b2d8-a57f8e1c01dc.bylaw.ps1 · 30 lines
# Converted from FirewallEnabled_Modify.json by ConvertTo-Bylaw.
Policy 'ac673a9a-f77d-4846-b2d8-a57f8e1c01dc' {

    Properties @{
        DisplayName   = 'Configure key vaults to enable firewall'
        Description   = 'Enable the key vault firewall so that the key vault is not accessible by default to any public IPs. You can then configure specific IP ranges to limit access to those networks. Learn more at: https://docs.microsoft.com/azure/key-vault/general/network-security'
        Version       = '1.1.1'
        Category      = 'Key Vault'
        PolicyVersion = '1.1.1'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Modify', 'Disabled')
        Default       = 'Modify'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.KeyVault/vaults' {

        Require 'networkAcls.defaultAction is Deny' {
            Field networkAcls.defaultAction | Must -Be 'Deny'
        }
    }

    Modify -Role 'Key Vault Contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field networkAcls.defaultAction | AddOrReplace 'Deny'
    }
}

Source: built-in-policies/policyDefinitions/Key Vault/FirewallEnabled_Modify.json in Azure/azure-policy, under the MIT licence.