Bylaw

Gallery › Network › Azure built-in policies

[Preview]: Container Registry should use a virtual network service endpoint

Converted Policy Audit Disabled Mode Indexed Version 1.0.0-preview Preview

This policy audits any Container Registry not configured to use a virtual network service endpoint.

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

Azure Policy JSONVirtualNetworkServiceEndpoint_ContainerRegistry_Audit.json · 58 lines
{
  "properties": {
    "displayName": "[Preview]: Container Registry should use a virtual network service endpoint",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy audits any Container Registry not configured to use a virtual network service endpoint.",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Network",
      "preview": true
    },
    "version": "1.0.0-preview",
    "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"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.ContainerRegistry/registries/networkRuleSet.defaultAction",
                "notEquals": "Deny"
              },
              {
                "field": "Microsoft.ContainerRegistry/registries/networkRuleSet.virtualNetworkRules[*].action",
                "exists": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/c4857be7-912a-4c75-87e6-e30292bcdf78",
  "name": "c4857be7-912a-4c75-87e6-e30292bcdf78"
}
Bylawc4857be7-912a-4c75-87e6-e30292bcdf78.bylaw.ps1 · 36 lines
# Converted from VirtualNetworkServiceEndpoint_ContainerRegistry_Audit.json by ConvertTo-Bylaw.
Policy 'c4857be7-912a-4c75-87e6-e30292bcdf78' {

    Properties @{
        DisplayName   = '[Preview]: Container Registry should use a virtual network service endpoint'
        Description   = 'This policy audits any Container Registry not configured to use a virtual network service endpoint.'
        Version       = '1.0.0-preview'
        Category      = 'Network'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        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 'networkRuleSet.defaultAction is Deny' {
            Field networkRuleSet.defaultAction | Must -Be 'Deny'
        }

        Require 'networkRuleSet.virtualNetworkRules and action are as required' {
            Count 'networkRuleSet.virtualNetworkRules[*]' -Where {
                Field action | Must -Exist
            } | Must -Not -Be 0
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Network/VirtualNetworkServiceEndpoint_ContainerRegistry_Audit.json in Azure/azure-policy, under the MIT licence.