Bylaw

Gallery › Backup › Azure built-in policies

Soft delete must be enabled for Recovery Services Vaults.

Converted Policy Audit Disabled Mode Indexed Version 1.0.1

This policy audits if soft delete is enabled for Recovery Services Vaults in the scope. Soft delete can help you recover your data even 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 JSONAzBackupRecoveryServicesVault_SoftDelete_Audit.json · 81 lines
{
  "properties": {
    "displayName": "Soft delete must be enabled for Recovery Services Vaults.",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy audits if soft delete is enabled for Recovery Services Vaults in the scope. Soft delete can help you recover your data even after it has been deleted. Learn more at https://aka.ms/AB-SoftDelete.",
    "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 status is 'Locked', making it irreversible for Recovery Services Vaults in scope. Selecting 'true' will mark only vaults with Soft Delete status 'AlwaysOn' as compliant. Selecting 'false' will mark vaults that have Soft Delete status either 'On' or 'AlwaysOn' as compliant."
        },
        "allowedValues": [
          true,
          false
        ],
        "defaultValue": true
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.RecoveryServices/Vaults"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.RecoveryServices/vaults/securitySettings.softDeleteSettings.softDeleteState",
                "notIn": [
                  "Enabled",
                  "AlwaysOn"
                ]
              },
              {
                "allOf": [
                  {
                    "value": "[parameters('checkAlwaysOnSoftDeleteOnly')]",
                    "equals": true
                  },
                  {
                    "field": "Microsoft.RecoveryServices/vaults/securitySettings.softDeleteSettings.softDeleteState",
                    "notEquals": "AlwaysOn"
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/31b8092a-36b8-434b-9af7-5ec844364148",
  "name": "31b8092a-36b8-434b-9af7-5ec844364148"
}
Bylaw31b8092a-36b8-434b-9af7-5ec844364148.bylaw.ps1 · 42 lines
# Converted from AzBackupRecoveryServicesVault_SoftDelete_Audit.json by ConvertTo-Bylaw.
Policy '31b8092a-36b8-434b-9af7-5ec844364148' {

    Properties @{
        DisplayName   = 'Soft delete must be enabled for Recovery Services Vaults.'
        Description   = 'This policy audits if soft delete is enabled for Recovery Services Vaults in the scope. Soft delete can help you recover your data even 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 status is ''Locked'', making it irreversible for Recovery Services Vaults in scope. Selecting ''true'' will mark only vaults with Soft Delete status ''AlwaysOn'' as compliant. Selecting ''false'' will mark vaults that have Soft Delete status either ''On'' or ''AlwaysOn'' as compliant.'
    }

    Resource 'Microsoft.RecoveryServices/Vaults' {

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

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

    Effect (Param Effect)
}

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