Bylaw

Gallery › Batch › Azure built-in policies

Azure Batch pools should have disk encryption enabled

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Enabling Azure Batch disk encryption ensures that data is always encrypted at rest on your Azure Batch compute node. Learn more about disk encryption in Batch at https://docs.microsoft.com/azure/batch/disk-encryption.

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

Azure Policy JSONDiskEncryption_Audit.json · 56 lines
{
  "properties": {
    "displayName": "Azure Batch pools should have disk encryption enabled",
    "description": "Enabling Azure Batch disk encryption ensures that data is always encrypted at rest on your Azure Batch compute node. Learn more about disk encryption in Batch at https://docs.microsoft.com/azure/batch/disk-encryption.",
    "metadata": {
      "version": "1.0.0",
      "category": "Batch"
    },
    "version": "1.0.0",
    "policyType": "BuiltIn",
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled",
          "Deny"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Batch/batchAccounts/pools"
          },
          {
            "count": {
              "field": "Microsoft.Batch/batchAccounts/pools/deploymentConfiguration.virtualMachineConfiguration.diskEncryptionConfiguration.targets[*]",
              "where": {
                "field": "Microsoft.Batch/batchAccounts/pools/deploymentConfiguration.virtualMachineConfiguration.diskEncryptionConfiguration.targets[*]",
                "contains": "TemporaryDisk"
              }
            },
            "less": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/1760f9d4-7206-436e-a28f-d9f3a5c8a227",
  "name": "1760f9d4-7206-436e-a28f-d9f3a5c8a227"
}
Bylaw1760f9d4-7206-436e-a28f-d9f3a5c8a227.bylaw.ps1 · 30 lines
# Converted from DiskEncryption_Audit.json by ConvertTo-Bylaw.
Policy '1760f9d4-7206-436e-a28f-d9f3a5c8a227' {

    Properties @{
        DisplayName   = 'Azure Batch pools should have disk encryption enabled'
        Description   = 'Enabling Azure Batch disk encryption ensures that data is always encrypted at rest on your Azure Batch compute node. Learn more about disk encryption in Batch at https://docs.microsoft.com/azure/batch/disk-encryption.'
        Version       = '1.0.0'
        Category      = 'Batch'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

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

    Resource 'Microsoft.Batch/batchAccounts/pools' {

        Require 'deploymentConfiguration.virtualMachineConfiguration.diskEncryptionConfiguration.targets is as required' {
            Count 'deploymentConfiguration.virtualMachineConfiguration.diskEncryptionConfiguration.targets[*]' -Where {
                Element | Must -ContainText 'TemporaryDisk'
            } | Must -BeGreaterOrEqual 1
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Batch/DiskEncryption_Audit.json in Azure/azure-policy, under the MIT licence.