Bylaw

Gallery › Mission › Azure built-in policies

Key Vault should restrict IP and virtual network rules in mission platforms

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restrict Key Vault firewall IP and virtual network rules to approved entries to reduce access from unapproved networks. Only entries explicitly included in the configured allowlists are permitted.

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

Azure Policy JSONKeyVaultRestrictIPRules_Audit.json · 86 lines
{
  "properties": {
    "displayName": "Key Vault should restrict IP and virtual network rules in mission platforms",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restrict Key Vault firewall IP and virtual network rules to approved entries to reduce access from unapproved networks. Only entries explicitly included in the configured allowlists are permitted.",
    "metadata": {
      "version": "1.0.0",
      "category": "Mission"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Choose whether to audit, deny, or disable evaluation of unapproved Key Vault firewall rules."
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "allowedAddressRanges": {
        "type": "Array",
        "metadata": {
          "description": "Approved public IPv4 addresses or CIDR entries to match against Key Vault firewall IP rules. Entries are matched as values, not by subnet containment; an empty list permits no IP rules.",
          "displayName": "Allowed IP address ranges"
        },
        "defaultValue": []
      },
      "allowedVirtualNetworks": {
        "type": "Array",
        "metadata": {
          "description": "Approved subnet resource IDs to match against Key Vault virtual network firewall rules. An empty list permits no virtual network rules.",
          "displayName": "Allowed virtual network subnet IDs"
        },
        "defaultValue": []
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.KeyVault/vaults"
          },
          {
            "anyOf": [
              {
                "count": {
                  "field": "Microsoft.KeyVault/vaults/networkAcls.ipRules[*]",
                  "where": {
                    "field": "Microsoft.KeyVault/vaults/networkAcls.ipRules[*].value",
                    "notIn": "[parameters('allowedAddressRanges')]"
                  }
                },
                "greater": 0
              },
              {
                "count": {
                  "field": "Microsoft.KeyVault/vaults/networkAcls.virtualNetworkRules[*]",
                  "where": {
                    "field": "Microsoft.KeyVault/vaults/networkAcls.virtualNetworkRules[*].id",
                    "notIn": "[parameters('allowedVirtualNetworks')]"
                  }
                },
                "greater": 0
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/db98217a-80f5-4cbd-bc9c-91640765ed90",
  "name": "db98217a-80f5-4cbd-bc9c-91640765ed90"
}
Bylawdb98217a-80f5-4cbd-bc9c-91640765ed90.bylaw.ps1 · 48 lines
# Converted from KeyVaultRestrictIPRules_Audit.json by ConvertTo-Bylaw.
Policy 'db98217a-80f5-4cbd-bc9c-91640765ed90' {

    Properties @{
        DisplayName   = 'Key Vault should restrict IP and virtual network rules in mission platforms'
        Description   = 'This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restrict Key Vault firewall IP and virtual network rules to approved entries to reduce access from unapproved networks. Only entries explicitly included in the configured allowlists are permitted.'
        Version       = '1.0.0'
        Category      = 'Mission'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Choose whether to audit, deny, or disable evaluation of unapproved Key Vault firewall rules.'
    }
    Parameter AllowedAddressRanges @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Allowed IP address ranges'
        Description = 'Approved public IPv4 addresses or CIDR entries to match against Key Vault firewall IP rules. Entries are matched as values, not by subnet containment; an empty list permits no IP rules.'
    }
    Parameter AllowedVirtualNetworks @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Allowed virtual network subnet IDs'
        Description = 'Approved subnet resource IDs to match against Key Vault virtual network firewall rules. An empty list permits no virtual network rules.'
    }

    Resource 'Microsoft.KeyVault/vaults' {

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

        Require 'networkAcls.virtualNetworkRules and id are as required' {
            Each 'networkAcls.virtualNetworkRules[*]' {
                Field id | Must -BeIn (Param AllowedVirtualNetworks) -Strict
            }
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Mission/KeyVaultRestrictIPRules_Audit.json in Azure/azure-policy, under the MIT licence.