Bylaw

Gallery › Key Vault › Azure Community Policy

Audit if Key Vault has no virtual network rules

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

Audits Key Vault vaults if they do not have virtual network service endpoints set up. More information on virtual network service endpoints in Key Vault is available here: https://docs.microsoft.com/en-us/azure/key-vault/key-vault-overview-vnet-service-endpoints

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

Azure Policy JSONazurepolicy.json · 56 lines
{
  "name": "59c76be0-ecd5-41cb-b7f9-f60b11645db8",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit if Key Vault has no virtual network rules",
    "description": "Audits Key Vault vaults if they do not have virtual network service endpoints set up. More information on virtual network service endpoints in Key Vault is available here: https://docs.microsoft.com/en-us/azure/key-vault/key-vault-overview-vnet-service-endpoints",
    "metadata": {
      "version": "1.0.0",
      "category": "Key Vault"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.KeyVault/vaults"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.KeyVault/vaults/networkAcls.virtualNetworkRules[*].id",
                "exists": "false"
              },
              {
                "field": "Microsoft.KeyVault/vaults/networkAcls.virtualNetworkRules[*].id",
                "notLike": "*"
              },
              {
                "field": "Microsoft.KeyVault/vaults/networkAcls.defaultAction",
                "equals": "Allow"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw59c76be0-ecd5-41cb-b7f9-f60b11645db8.bylaw.ps1 · 39 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '59c76be0-ecd5-41cb-b7f9-f60b11645db8' {

    Properties @{
        DisplayName = 'Audit if Key Vault has no virtual network rules'
        Description = 'Audits Key Vault vaults if they do not have virtual network service endpoints set up. More information on virtual network service endpoints in Key Vault is available here: https://docs.microsoft.com/en-us/azure/key-vault/key-vault-overview-vnet-service-endpoints'
        Version     = '1.0.0'
        Category    = 'Key Vault'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.KeyVault/vaults' {

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

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

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

    Effect (Param Effect)
}

Source: policyDefinitions/Key Vault/audit-if-key-vault-has-no-virtual-network-rules/azurepolicy.json in Azure/Community-Policy, under the MIT licence.