Bylaw

Gallery › Backup › Azure built-in policies

Immutability must be enabled for backup vaults

Converted Policy Audit Disabled Mode Indexed Version 1.0.2

This policy audits if the immutable vaults property is enabled for Backup vaults in the scope. This helps protect your backup data from being deleted before its intended expiry. Learn more at https://aka.ms/AB-ImmutableVaults.

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

Azure Policy JSONVaults_Immutability_Audit.json · 81 lines
{
  "properties": {
    "displayName": "Immutability must be enabled for backup vaults",
    "description": "This policy audits if the immutable vaults property is enabled for Backup vaults in the scope. This helps protect your backup data from being deleted before its intended expiry. Learn more at https://aka.ms/AB-ImmutableVaults.",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.0.2",
      "category": "Backup"
    },
    "version": "1.0.2",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "checkLockedImmutabiltyOnly": {
        "type": "Boolean",
        "metadata": {
          "displayName": "CheckLockedImmutabiltyOnly",
          "description": "This parameter checks if Immutability is locked for Backup Vaults in scope. Selecting 'true' will mark only vaults with Immutability 'Locked' as compliant. Selecting 'false' will mark vaults that have Immutability either 'Enabled' or 'Locked' as compliant."
        },
        "allowedValues": [
          true,
          false
        ],
        "defaultValue": true
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DataProtection/backupvaults"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.DataProtection/backupVaults/securitySettings.immutabilitySettings.State",
                "notIn": [
                  "Locked",
                  "Unlocked"
                ]
              },
              {
                "allOf": [
                  {
                    "value": "[parameters('checkLockedImmutabiltyOnly')]",
                    "equals": true
                  },
                  {
                    "field": "Microsoft.DataProtection/backupVaults/securitySettings.immutabilitySettings.State",
                    "notEquals": "Locked"
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.2",
      "1.0.1-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/2514263b-bc0d-4b06-ac3e-f262c0979018",
  "name": "2514263b-bc0d-4b06-ac3e-f262c0979018"
}
Bylaw2514263b-bc0d-4b06-ac3e-f262c0979018.bylaw.ps1 · 42 lines
# Converted from Vaults_Immutability_Audit.json by ConvertTo-Bylaw.
Policy '2514263b-bc0d-4b06-ac3e-f262c0979018' {

    Properties @{
        DisplayName   = 'Immutability must be enabled for backup vaults'
        Description   = 'This policy audits if the immutable vaults property is enabled for Backup vaults in the scope. This helps protect your backup data from being deleted before its intended expiry. Learn more at https://aka.ms/AB-ImmutableVaults.'
        Version       = '1.0.2'
        Category      = 'Backup'
        PolicyVersion = '1.0.2'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy.'
    }
    Parameter CheckLockedImmutabiltyOnly @{
        Type          = 'Boolean'
        AllowedValues = @($true, $false)
        Default       = $true
        DisplayName   = 'CheckLockedImmutabiltyOnly'
        Description   = 'This parameter checks if Immutability is locked for Backup Vaults in scope. Selecting ''true'' will mark only vaults with Immutability ''Locked'' as compliant. Selecting ''false'' will mark vaults that have Immutability either ''Enabled'' or ''Locked'' as compliant.'
    }

    Resource 'Microsoft.DataProtection/backupvaults' {

        Require 'securitySettings.immutabilitySettings.state is one of 2 values' {
            Field securitySettings.immutabilitySettings.state | Must -BeIn @('Locked', 'Unlocked')
        }

        Require 'securitySettings.immutabilitySettings.state is as required' {
            AnyOf {
                Param CheckLockedImmutabiltyOnly | Must -Not -Be $true
                Field securitySettings.immutabilitySettings.state | Must -Be 'Locked'
            }
        }
    }

    Effect (Param Effect)
}

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