Bylaw

Gallery › Storage › Azure Community Policy

Deny permanent delete for soft deleted items

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Permanent delete enables you to permanently delete a soft-deleted snapshot or blob version before the retention period ends. https://docs.microsoft.com/rest/api/storageservices/delete-blob?WT.mc_id=Portal-Microsoft_Azure_Storage#remarks

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

Azure Policy JSONazurepolicy.json · 45 lines
{
  "name": "58635fc7-e7fa-45ae-92b8-07b9ad64307b",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Deny permanent delete for soft deleted items",
    "description": "Permanent delete enables you to permanently delete a soft-deleted snapshot or blob version before the retention period ends. https://docs.microsoft.com/rest/api/storageservices/delete-blob?WT.mc_id=Portal-Microsoft_Azure_Storage#remarks",
    "metadata": {
      "version": "1.0.0",
      "category": "Storage"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts/blobServices"
          },
          {
            "field": "Microsoft.Storage/storageAccounts/blobServices/deleteRetentionPolicy.allowPermanentDelete",
            "equals": true
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw58635fc7-e7fa-45ae-92b8-07b9ad64307b.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '58635fc7-e7fa-45ae-92b8-07b9ad64307b' {

    Properties @{
        DisplayName = 'Deny permanent delete for soft deleted items'
        Description = 'Permanent delete enables you to permanently delete a soft-deleted snapshot or blob version before the retention period ends. https://docs.microsoft.com/rest/api/storageservices/delete-blob?WT.mc_id=Portal-Microsoft_Azure_Storage#remarks'
        Version     = '1.0.0'
        Category    = 'Storage'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.Storage/storageAccounts/blobServices' {

        Require 'deleteRetentionPolicy.allowPermanentDelete is not true' {
            Field deleteRetentionPolicy.allowPermanentDelete | Must -Not -Be $true -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Storage/deny-permanent-delete-for-soft-deleted-items/azurepolicy.json in Azure/Community-Policy, under the MIT licence.