Bylaw

Gallery › Key Vault › Azure built-in policies

[Preview]: Configure Azure Key Vault Managed HSM to disable public network access

Converted Policy Disabled Modify Mode Indexed Version 2.0.0-preview Preview

Disable public network access for your Azure Key Vault Managed HSM so that it's not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://docs.microsoft.com/azure/key-vault/managed-hsm/private-link#allow-trusted-services-to-access-managed-hsm.

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

Azure Policy JSONManagedHsm_FirewallEnabled_Modify.json · 63 lines
{
  "properties": {
    "displayName": "[Preview]: Configure Azure Key Vault Managed HSM to disable public network access",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disable public network access for your Azure Key Vault Managed HSM so that it's not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://docs.microsoft.com/azure/key-vault/managed-hsm/private-link#allow-trusted-services-to-access-managed-hsm.",
    "metadata": {
      "version": "2.0.0-preview",
      "category": "Key Vault",
      "preview": true
    },
    "version": "2.0.0-preview",
    "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/managedHSMs"
          },
          {
            "field": "Microsoft.KeyVault/managedHSMs/networkAcls.defaultAction",
            "notEquals": "Deny"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "conflictEffect": "audit",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/18500a29-7fe2-46b2-a342-b16a415e101d"
          ],
          "operations": [
            {
              "operation": "addOrReplace",
              "field": "Microsoft.KeyVault/managedHSMs/networkAcls.defaultAction",
              "value": "Deny"
            }
          ]
        }
      }
    },
    "versions": [
      "2.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/84d327c3-164a-4685-b453-900478614456",
  "name": "84d327c3-164a-4685-b453-900478614456"
}
Bylaw84d327c3-164a-4685-b453-900478614456.bylaw.ps1 · 31 lines
# Converted from ManagedHsm_FirewallEnabled_Modify.json by ConvertTo-Bylaw.
Policy '84d327c3-164a-4685-b453-900478614456' {

    Properties @{
        DisplayName   = '[Preview]: Configure Azure Key Vault Managed HSM to disable public network access'
        Description   = 'Disable public network access for your Azure Key Vault Managed HSM so that it''s not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://docs.microsoft.com/azure/key-vault/managed-hsm/private-link#allow-trusted-services-to-access-managed-hsm.'
        Version       = '2.0.0-preview'
        Category      = 'Key Vault'
        Preview       = $true
        PolicyVersion = '2.0.0-preview'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.KeyVault/managedHSMs' {

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

    Modify -Role 'Managed HSM contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field networkAcls.defaultAction | AddOrReplace 'Deny'
    }
}

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