Bylaw

Gallery › Backup › Azure built-in policies

Soft delete should be enabled for Backup Vaults

Converted Policy Audit Disabled Mode Indexed Version 1.0.1

This policy audits if soft delete is enabled for Backup vaults in the scope. Soft delete can help you recover your data after it has been deleted. Learn more at https://aka.ms/AB-SoftDelete

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

Azure Policy JSONVaults_SoftDelete_Audit.json · 81 lines
{
  "properties": {
    "displayName": "Soft delete should be enabled for Backup Vaults",
    "description": "This policy audits if soft delete is enabled for Backup vaults in the scope. Soft delete can help you recover your data after it has been deleted. Learn more at https://aka.ms/AB-SoftDelete",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.0.1",
      "category": "Backup"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "checkAlwaysOnSoftDeleteOnly": {
        "type": "Boolean",
        "metadata": {
          "displayName": "CheckAlwaysOnSoftDeleteOnly",
          "description": "This parameter checks if Soft Delete is 'Locked' for Backup Vaults in scope. Selecting 'true' will mark only vaults with Soft Delete 'AlwaysOn' as compliant. Selecting 'false' will mark vaults that have Soft Delete either 'On' or 'AlwaysOn' as compliant."
        },
        "allowedValues": [
          true,
          false
        ],
        "defaultValue": true
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DataProtection/backupvaults"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.DataProtection/backupVaults/securitySettings.softDeleteSettings.state",
                "notIn": [
                  "On",
                  "AlwaysOn"
                ]
              },
              {
                "allOf": [
                  {
                    "value": "[parameters('checkAlwaysOnSoftDeleteOnly')]",
                    "equals": true
                  },
                  {
                    "field": "Microsoft.DataProtection/backupVaults/securitySettings.softDeleteSettings.state",
                    "notEquals": "AlwaysOn"
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/9798d31d-6028-4dee-8643-46102185c016",
  "name": "9798d31d-6028-4dee-8643-46102185c016"
}
Bylaw9798d31d-6028-4dee-8643-46102185c016.bylaw.ps1 · 42 lines
# Converted from Vaults_SoftDelete_Audit.json by ConvertTo-Bylaw.
Policy '9798d31d-6028-4dee-8643-46102185c016' {

    Properties @{
        DisplayName   = 'Soft delete should be enabled for Backup Vaults'
        Description   = 'This policy audits if soft delete is enabled for Backup vaults in the scope. Soft delete can help you recover your data after it has been deleted. Learn more at https://aka.ms/AB-SoftDelete'
        Version       = '1.0.1'
        Category      = 'Backup'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.DataProtection/backupvaults' {

        Require 'securitySettings.softDeleteSettings.state is one of 2 values' {
            Field securitySettings.softDeleteSettings.state | Must -BeIn @('On', 'AlwaysOn')
        }

        Require 'securitySettings.softDeleteSettings.state is as required' {
            AnyOf {
                Param CheckAlwaysOnSoftDeleteOnly | Must -Not -Be $true
                Field securitySettings.softDeleteSettings.state | Must -Be 'AlwaysOn'
            }
        }
    }

    Effect (Param Effect)
}

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