Bylaw

Gallery › Key Vault › Azure Community Policy

Deny Key Vault resource access - Azure Resource Manager

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Requires Key Vaults to be deployed with 'Azure Resource Manager for template deployment' disabled.

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

Azure Policy JSONazurepolicy.json · 45 lines
{
  "name": "b1f2a4d3-6e89-41a7-bb1f-2d8c5e7a9f25",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Deny Key Vault resource access - Azure Resource Manager",
    "description": "Requires Key Vaults to be deployed with 'Azure Resource Manager for template deployment' disabled.",
    "metadata": {
      "version": "1.0.0",
      "category": "Key Vault"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.KeyVault/vaults",
            "field": "type"
          },
          {
            "equals": "true",
            "field": "Microsoft.KeyVault/vaults/enabledForTemplateDeployment"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawb1f2a4d3-6e89-41a7-bb1f-2d8c5e7a9f25.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'b1f2a4d3-6e89-41a7-bb1f-2d8c5e7a9f25' {

    Properties @{
        DisplayName = 'Deny Key Vault resource access - Azure Resource Manager'
        Description = 'Requires Key Vaults to be deployed with ''Azure Resource Manager for template deployment'' disabled.'
        Version     = '1.0.0'
        Category    = 'Key Vault'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.KeyVault/vaults' {

        Require 'enabledForTemplateDeployment is not true' {
            Field enabledForTemplateDeployment | Must -Not -Be 'true' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Key Vault/deny-kv-resourceaccess-arm-template-deployment/azurepolicy.json in Azure/Community-Policy, under the MIT licence.