Bylaw

Gallery › Container Registry › Azure Community Policy

Container Registries enable soft delete policy

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Ensure registry has soft delete policy, to recover any accidentally deleted artifacts for a set retention period.

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

Azure Policy JSONazurepolicy.json · 45 lines
{
  "name": "243a97b3-575e-4513-be30-4f38fb52c1c4",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Container Registries enable soft delete policy",
    "description": "Ensure registry has soft delete policy, to recover any accidentally deleted artifacts for a set retention period.",
    "metadata": {
      "category": "Container Registry",
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "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": [
          {
            "equals": "Microsoft.ContainerRegistry/registries",
            "field": "type"
          },
          {
            "equals": "Disabled",
            "field": "Microsoft.ContainerRegistry/registries/policies.softDeletePolicy.status"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw243a97b3-575e-4513-be30-4f38fb52c1c4.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '243a97b3-575e-4513-be30-4f38fb52c1c4' {

    Properties @{
        DisplayName = 'Container Registries enable soft delete policy'
        Description = 'Ensure registry has soft delete policy, to recover any accidentally deleted artifacts for a set retention period.'
        Category    = 'Container Registry'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

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

    Resource 'Microsoft.ContainerRegistry/registries' {

        Require 'policies.softDeletePolicy.status is not Disabled' {
            Field policies.softDeletePolicy.status | Must -Not -Be 'Disabled' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Container Registry/container-registries-enable-soft-delete-policy/azurepolicy.json in Azure/Community-Policy, under the MIT licence.