Bylaw

Gallery › Container Registry › Azure Community Policy

Container Registries enable retention policy

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Ensure registry has a retention policy for stored image manifests that don't have any associated tags (untagged manifests), which are then automatically deleted. This feature prevents the registry from filling up with artifacts that aren't needed and helps you save on storage costs.

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

Azure Policy JSONazurepolicy.json · 48 lines
{
  "name": "8b36505e-b96f-4ab9-a5ed-aefd19476d2c",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Container Registries enable retention policy",
    "description": "Ensure registry has a retention policy for stored image manifests that don't have any associated tags (untagged manifests), which are then automatically deleted. This feature prevents the registry from filling up with artifacts that aren't needed and helps you save on storage costs.",
    "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"
          },
          {
            "in": [
              "disabled",
              "Disabled"
            ],
            "field": "Microsoft.ContainerRegistry/registries/policies.retentionPolicy.status"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw8b36505e-b96f-4ab9-a5ed-aefd19476d2c.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '8b36505e-b96f-4ab9-a5ed-aefd19476d2c' {

    Properties @{
        DisplayName = 'Container Registries enable retention policy'
        Description = 'Ensure registry has a retention policy for stored image manifests that don''t have any associated tags (untagged manifests), which are then automatically deleted. This feature prevents the registry from filling up with artifacts that aren''t needed and helps you save on storage costs.'
        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.retentionPolicy.status is not one of 2 values' {
            Field policies.retentionPolicy.status | Must -Not -BeIn @('disabled', 'Disabled') -IfPresent
        }
    }

    Effect (Param Effect)
}

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