Bylaw

Gallery › Key Vault › Azure built-in policies

[Preview]: Azure Key Vault Managed HSM should use private link

Converted Policy Audit Disabled Mode Indexed Version 1.0.0-preview Preview

Private link provides a way to connect Azure Key Vault Managed HSM to your Azure resources without sending traffic over the public internet. Private link provides defense in depth protection against data exfiltration. Learn more at: https://docs.microsoft.com/azure/key-vault/managed-hsm/private-link

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

Azure Policy JSONManagedHsm_PrivateEndpointEnabled_Audit.json · 64 lines
{
  "properties": {
    "displayName": "[Preview]: Azure Key Vault Managed HSM should use private link",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Private link provides a way to connect Azure Key Vault Managed HSM to your Azure resources without sending traffic over the public internet. Private link provides defense in depth protection against data exfiltration. Learn more at: https://docs.microsoft.com/azure/key-vault/managed-hsm/private-link",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Key Vault",
      "preview": true
    },
    "version": "1.0.0-preview",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.KeyVault/managedHSMs"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.KeyVault/managedHSMs/privateEndpointConnections",
                "exists": "false"
              },
              {
                "count": {
                  "field": "Microsoft.KeyVault/managedHSMs/privateEndpointConnections[*]",
                  "where": {
                    "field": "Microsoft.KeyVault/managedHSMs/privateEndpointConnections[*].privateLinkServiceConnectionState.status",
                    "equals": "Approved"
                  }
                },
                "equals": 0
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/59fee2f4-d439-4f1b-9b9a-982e1474bfd8",
  "name": "59fee2f4-d439-4f1b-9b9a-982e1474bfd8"
}
Bylaw59fee2f4-d439-4f1b-9b9a-982e1474bfd8.bylaw.ps1 · 35 lines
# Converted from ManagedHsm_PrivateEndpointEnabled_Audit.json by ConvertTo-Bylaw.
Policy '59fee2f4-d439-4f1b-9b9a-982e1474bfd8' {

    Properties @{
        DisplayName   = '[Preview]: Azure Key Vault Managed HSM should use private link'
        Description   = 'Private link provides a way to connect Azure Key Vault Managed HSM to your Azure resources without sending traffic over the public internet. Private link provides defense in depth protection against data exfiltration. Learn more at: https://docs.microsoft.com/azure/key-vault/managed-hsm/private-link'
        Version       = '1.0.0-preview'
        Category      = 'Key Vault'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.KeyVault/managedHSMs' {

        Require 'privateEndpointConnections exists' {
            Field privateEndpointConnections | Must -Exist
        }

        Require 'privateEndpointConnections and privateLinkServiceConnectionState.status are as required' {
            Count 'privateEndpointConnections[*]' -Where {
                Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
            } | Must -Not -Be 0
        }
    }

    Effect (Param Effect)
}

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