Bylaw

Gallery › Security Center › Azure built-in policies

Configure Microsoft Defender for Key Vault plan

Converted Policy DeployIfNotExists Disabled Mode All Version 2.0.0

Microsoft Defender for Key Vault provides an additional layer of protection and security intelligence by detecting unusual and potentially harmful attempts to access or exploit key vault accounts.

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

Azure Policy JSONASC_Azure_Defender_KeyVault_DINE.json · 108 lines
{
  "properties": {
    "displayName": "Configure Microsoft Defender for Key Vault plan",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Microsoft Defender for Key Vault provides an additional layer of protection and security intelligence by detecting unusual and potentially harmful attempts to access or exploit key vault accounts.",
    "metadata": {
      "version": "2.0.0",
      "category": "Security Center"
    },
    "version": "2.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "DeployIfNotExists",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ]
      },
      "subPlan": {
        "type": "String",
        "metadata": {
          "displayName": "Key Vaults bundle's sub plan",
          "description": "Select a Defender for Key Vault plan"
        },
        "allowedValues": [
          "PerKeyVault"
        ],
        "defaultValue": "PerKeyVault"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Resources/subscriptions"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/pricings",
          "name": "KeyVaults",
          "deploymentScope": "subscription",
          "existenceScope": "subscription",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/fb1c8493-542b-48eb-b624-b4c8fea62acd"
          ],
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Security/pricings/pricingTier",
                "equals": "Standard"
              },
              {
                "field": "Microsoft.Security/pricings/subPlan",
                "equals": "[parameters('subPlan')]"
              }
            ]
          },
          "deployment": {
            "location": "westeurope",
            "properties": {
              "mode": "incremental",
              "parameters": {
                "subPlan": {
                  "value": "[parameters('subPlan')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "subPlan": {
                    "type": "String"
                  }
                },
                "variables": {},
                "resources": [
                  {
                    "type": "Microsoft.Security/pricings",
                    "apiVersion": "2023-01-01",
                    "name": "KeyVaults",
                    "properties": {
                      "pricingTier": "Standard",
                      "subPlan": "[parameters('subPlan')]"
                    }
                  }
                ],
                "outputs": {}
              }
            }
          }
        }
      }
    },
    "versions": [
      "2.0.0",
      "1.1.0",
      "1.0.2"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/1f725891-01c0-420a-9059-4fa46cb770b7",
  "name": "1f725891-01c0-420a-9059-4fa46cb770b7"
}
Bylaw1f725891-01c0-420a-9059-4fa46cb770b7.bylaw.ps1 · 43 lines
# Converted from ASC_Azure_Defender_KeyVault_DINE.json by ConvertTo-Bylaw.
Policy '1f725891-01c0-420a-9059-4fa46cb770b7' {

    Properties @{
        DisplayName   = 'Configure Microsoft Defender for Key Vault plan'
        Description   = 'Microsoft Defender for Key Vault provides an additional layer of protection and security intelligence by detecting unusual and potentially harmful attempts to access or exploit key vault accounts.'
        Version       = '2.0.0'
        Category      = 'Security Center'
        PolicyVersion = '2.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter SubPlan @{
        AllowedValues = @('PerKeyVault')
        Default       = 'PerKeyVault'
        DisplayName   = 'Key Vaults bundle''s sub plan'
        Description   = 'Select a Defender for Key Vault plan'
    }

    Resource 'Microsoft.Resources/subscriptions'

    DeployIfNotExists 'Microsoft.Security/pricings' -Role 'Security Admin' -Name 'KeyVaults' -ExistenceScope Subscription -Effect (Param Effect) {
        Require 'pricingTier is Standard and subPlan is the SubPlan parameter' {
            Field pricingTier | Must -Be 'Standard'
            Field subPlan | Must -Be (Param SubPlan)
        }
        Deployment @{
            TemplateFile = './templates/1f725891-01c0-420a-9059-4fa46cb770b7.json'
            Scope        = 'Subscription'
            Location     = 'westeurope'
            Parameters   = [ordered]@{
                subPlan = (Param SubPlan)
            }
        }
    }
}

Its deployment templates are written beside it:

Source: built-in-policies/policyDefinitions/Security Center/ASC_Azure_Defender_KeyVault_DINE.json in Azure/azure-policy, under the MIT licence.