Bylaw

Gallery › Key Vault › Azure Community Policy

Deny deployment with access to specific services (VM, ARM, ADE)

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

This policy prevent specific services (VM, ARM, ADE) access to kv.

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

Azure Policy JSONazurepolicy.json · 60 lines
{
  "name": "f902833b-4f12-4958-bc74-4b4068d2697e",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Deny deployment with access to specific services (VM, ARM, ADE)",
    "description": "This policy prevent specific services (VM, ARM, ADE) access to kv.",
    "metadata": {
      "category": "Key Vault",
      "createdBy": "",
      "updatedBy": null,
      "updatedOn": null,
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.KeyVault/vaults",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "equals": "true",
                "field": "Microsoft.KeyVault/vaults/enabledForDeployment"
              },
              {
                "equals": "true",
                "field": "Microsoft.KeyVault/vaults/enabledForDiskEncryption"
              },
              {
                "equals": "true",
                "field": "Microsoft.KeyVault/vaults/enabledForTemplateDeployment"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawf902833b-4f12-4958-bc74-4b4068d2697e.bylaw.ps1 · 35 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'f902833b-4f12-4958-bc74-4b4068d2697e' {

    Properties @{
        DisplayName = 'Deny deployment with access to specific services (VM, ARM, ADE)'
        Description = 'This policy prevent specific services (VM, ARM, ADE) access to kv.'
        Category    = 'Key Vault'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

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

    Resource 'Microsoft.KeyVault/vaults' {

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

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

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

    Effect (Param Effect)
}

Source: policyDefinitions/Key Vault/deny-deployment-with-access-to-specific-services-vm,-arm,-ade/azurepolicy.json in Azure/Community-Policy, under the MIT licence.