Bylaw

Gallery › Container Registry › Azure built-in policies

Container registries should use private link

Converted Policy Audit Disabled Mode Indexed Version 1.0.1

Azure Private Link lets you connect your virtual network to Azure services without a public IP address at the source or destination. The private link platform handles the connectivity between the consumer and services over the Azure backbone network.By mapping private endpoints to your container registries instead of the entire service, you'll also be protected against data leakage risks. Learn more at: https://aka.ms/acr/private-link.

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

Azure Policy JSONACR_PrivateEndpointEnabled_Audit.json · 55 lines
{
  "properties": {
    "displayName": "Container registries should use private link",
    "description": "Azure Private Link lets you connect your virtual network to Azure services without a public IP address at the source or destination. The private link platform handles the connectivity between the consumer and services over the Azure backbone network.By mapping private endpoints to your container registries instead of the entire service, you'll also be protected against data leakage risks. Learn more at: https://aka.ms/acr/private-link.",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.0.1",
      "category": "Container Registry"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerRegistry/registries"
          },
          {
            "count": {
              "field": "Microsoft.ContainerRegistry/registries/privateEndpointConnections[*]",
              "where": {
                "field": "Microsoft.ContainerRegistry/registries/privateEndpointConnections[*].privateLinkServiceConnectionState.status",
                "equals": "Approved"
              }
            },
            "less": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/e8eef0a8-67cf-4eb4-9386-14b0e78733d4",
  "name": "e8eef0a8-67cf-4eb4-9386-14b0e78733d4"
}
Bylawe8eef0a8-67cf-4eb4-9386-14b0e78733d4.bylaw.ps1 · 31 lines
# Converted from ACR_PrivateEndpointEnabled_Audit.json by ConvertTo-Bylaw.
Policy 'e8eef0a8-67cf-4eb4-9386-14b0e78733d4' {

    Properties @{
        DisplayName   = 'Container registries should use private link'
        Description   = 'Azure Private Link lets you connect your virtual network to Azure services without a public IP address at the source or destination. The private link platform handles the connectivity between the consumer and services over the Azure backbone network.By mapping private endpoints to your container registries instead of the entire service, you''ll also be protected against data leakage risks. Learn more at: https://aka.ms/acr/private-link.'
        Version       = '1.0.1'
        Category      = 'Container Registry'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.ContainerRegistry/registries' {

        Require 'privateEndpointConnections and privateLinkServiceConnectionState.status are as required' {
            Count 'privateEndpointConnections[*]' -Where {
                Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
            } | Must -BeGreaterOrEqual 1
        }
    }

    Effect (Param Effect)
}

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