Bylaw

Gallery › Container Registry › Azure built-in policies

Container registries should be encrypted with a customer-managed key

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.2

Use customer-managed keys to manage the encryption at rest of the contents of your registries. By default, the data is encrypted at rest with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance standards. Customer-managed keys enable the data to be encrypted with an Azure Key Vault key created and owned by you. You have full control and responsibility for the key lifecycle, including rotation and management. Learn more at https://aka.ms/acr/CMK.

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

Azure Policy JSONACR_CMKEncryptionEnabled_Audit.json · 50 lines
{
  "properties": {
    "displayName": "Container registries should be encrypted with a customer-managed key",
    "description": "Use customer-managed keys to manage the encryption at rest of the contents of your registries. By default, the data is encrypted at rest with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance standards. Customer-managed keys enable the data to be encrypted with an Azure Key Vault key created and owned by you. You have full control and responsibility for the key lifecycle, including rotation and management. Learn more at https://aka.ms/acr/CMK.",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.1.2",
      "category": "Container Registry"
    },
    "version": "1.1.2",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerRegistry/registries"
          },
          {
            "field": "Microsoft.ContainerRegistry/registries/encryption.status",
            "notEquals": "enabled"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.2"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5b9159ae-1701-4a6f-9a7a-aa9c8ddd0580",
  "name": "5b9159ae-1701-4a6f-9a7a-aa9c8ddd0580"
}
Bylaw5b9159ae-1701-4a6f-9a7a-aa9c8ddd0580.bylaw.ps1 · 29 lines
# Converted from ACR_CMKEncryptionEnabled_Audit.json by ConvertTo-Bylaw.
Policy '5b9159ae-1701-4a6f-9a7a-aa9c8ddd0580' {

    Properties @{
        DisplayName   = 'Container registries should be encrypted with a customer-managed key'
        Description   = 'Use customer-managed keys to manage the encryption at rest of the contents of your registries. By default, the data is encrypted at rest with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance standards. Customer-managed keys enable the data to be encrypted with an Azure Key Vault key created and owned by you. You have full control and responsibility for the key lifecycle, including rotation and management. Learn more at https://aka.ms/acr/CMK.'
        Version       = '1.1.2'
        Category      = 'Container Registry'
        PolicyVersion = '1.1.2'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.ContainerRegistry/registries' {

        Require 'encryption.status is enabled' {
            Field encryption.status | Must -Be 'enabled'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Container Registry/ACR_CMKEncryptionEnabled_Audit.json in Azure/azure-policy, under the MIT licence.