Bylaw

Gallery › Network › Azure built-in policies

Key Vault should use a virtual network service endpoint

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

This policy audits any Key Vault not configured to use a virtual network service endpoint.

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

Azure Policy JSONVirtualNetworkServiceEndpoint_KeyVault_Audit.json · 57 lines
{
  "properties": {
    "displayName": "Key Vault should use a virtual network service endpoint",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy audits any Key Vault not configured to use a virtual network service endpoint.",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.KeyVault/vaults"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.KeyVault/vaults/networkAcls.defaultAction",
                "notEquals": "Deny"
              },
              {
                "field": "Microsoft.KeyVault/vaults/networkAcls.virtualNetworkRules[*].id",
                "exists": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ea4d6841-2173-4317-9747-ff522a45120f",
  "name": "ea4d6841-2173-4317-9747-ff522a45120f"
}
Bylawea4d6841-2173-4317-9747-ff522a45120f.bylaw.ps1 · 35 lines
# Converted from VirtualNetworkServiceEndpoint_KeyVault_Audit.json by ConvertTo-Bylaw.
Policy 'ea4d6841-2173-4317-9747-ff522a45120f' {

    Properties @{
        DisplayName   = 'Key Vault should use a virtual network service endpoint'
        Description   = 'This policy audits any Key Vault not configured to use a virtual network service endpoint.'
        Version       = '1.0.0'
        Category      = 'Network'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        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'
        }

        Require 'networkAcls.virtualNetworkRules and id are as required' {
            Count 'networkAcls.virtualNetworkRules[*]' -Where {
                Field id | Must -Exist
            } | Must -Not -Be 0
        }
    }

    Effect (Param Effect)
}

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