Bylaw

Gallery › Machine Learning › Azure built-in policies

Configure Azure Machine Learning workspace to use private DNS zones

Uses Condition Policy DeployIfNotExists Disabled Mode Indexed Version 1.1.0

Use private DNS zones to override the DNS resolution for a private endpoint. A private DNS zone links to your virtual network to resolve to Azure Machine Learning workspaces. Learn more at: https://docs.microsoft.com/azure/machine-learning/how-to-network-security-overview.

ConvertTo-Bylaw converted this policy, and proved it compiles back to the same definition. Conditions the language can't express yet are written as raw JSON with Condition.

Azure Policy JSONWorkspace_PrivateDnsZones_DINE.json · 150 lines
{
  "properties": {
    "displayName": "Configure Azure Machine Learning workspace to use private DNS zones",
    "description": "Use private DNS zones to override the DNS resolution for a private endpoint. A private DNS zone links to your virtual network to resolve to Azure Machine Learning workspaces. Learn more at: https://docs.microsoft.com/azure/machine-learning/how-to-network-security-overview.",
    "metadata": {
      "version": "1.1.0",
      "category": "Machine Learning"
    },
    "version": "1.1.0",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "parameters": {
      "privateDnsZoneId": {
        "type": "String",
        "metadata": {
          "displayName": "Private DNS Zone id",
          "description": "A private DNS zone id to connect to the private endpoint.",
          "strongType": "Microsoft.Network/privateDnsZones"
        }
      },
      "secondPrivateDnsZoneId": {
        "type": "String",
        "metadata": {
          "displayName": "Second Private DNS Zone id",
          "description": "A private DNS zone id to connect to the private endpoint.",
          "strongType": "Microsoft.Network/privateDnsZones"
        },
        "defaultValue": ""
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/privateEndpoints"
          },
          {
            "count": {
              "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
              "where": {
                "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
                "equals": "amlworkspace"
              }
            },
            "greaterOrEquals": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "privateDnsZoneId": {
                    "type": "string"
                  },
                  "secondPrivateDnsZoneId": {
                    "type": "string"
                  },
                  "privateEndpointName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "variables": {
                  "bothPrivateDnsZoneConfigs": [
                    {
                      "name": "amlworkspace-privateDnsZone",
                      "properties": {
                        "privateDnsZoneId": "[parameters('privateDnsZoneId')]"
                      }
                    },
                    {
                      "name": "amlworkspace-secondPrivateDnsZone",
                      "properties": {
                        "privateDnsZoneId": "[parameters('secondPrivateDnsZoneId')]"
                      }
                    }
                  ],
                  "singlePrivateDnsZoneConfigs": [
                    {
                      "name": "amlworkspace-privateDnsZone",
                      "properties": {
                        "privateDnsZoneId": "[parameters('privateDnsZoneId')]"
                      }
                    }
                  ]
                },
                "resources": [
                  {
                    "name": "[concat(parameters('privateEndpointName'), '/deployedByPolicy')]",
                    "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
                    "apiVersion": "2020-03-01",
                    "location": "[parameters('location')]",
                    "properties": {
                      "privateDnsZoneConfigs": "[if(not(empty(parameters('secondPrivateDnsZoneId'))), variables('bothPrivateDnsZoneConfigs'), variables('singlePrivateDnsZoneConfigs') )]"
                    }
                  }
                ]
              },
              "parameters": {
                "privateDnsZoneId": {
                  "value": "[parameters('privateDnsZoneId')]"
                },
                "secondPrivateDnsZoneId": {
                  "value": "[parameters('secondPrivateDnsZoneId')]"
                },
                "privateEndpointName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ee40564d-486e-4f68-a5ca-7a621edae0fb",
  "name": "ee40564d-486e-4f68-a5ca-7a621edae0fb"
}
Bylawee40564d-486e-4f68-a5ca-7a621edae0fb.bylaw.ps1 · 47 lines
# Converted from Workspace_PrivateDnsZones_DINE.json by ConvertTo-Bylaw.
Policy 'ee40564d-486e-4f68-a5ca-7a621edae0fb' {

    Properties @{
        DisplayName   = 'Configure Azure Machine Learning workspace to use private DNS zones'
        Description   = 'Use private DNS zones to override the DNS resolution for a private endpoint. A private DNS zone links to your virtual network to resolve to Azure Machine Learning workspaces. Learn more at: https://docs.microsoft.com/azure/machine-learning/how-to-network-security-overview.'
        Version       = '1.1.0'
        Category      = 'Machine Learning'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter PrivateDnsZoneId @{
        Type        = 'String'
        DisplayName = 'Private DNS Zone id'
        Description = 'A private DNS zone id to connect to the private endpoint.'
        Metadata    = [ordered]@{ strongType = 'Microsoft.Network/privateDnsZones' }
    }
    Parameter SecondPrivateDnsZoneId @{
        Default     = ''
        DisplayName = 'Second Private DNS Zone id'
        Description = 'A private DNS zone id to connect to the private endpoint.'
        Metadata    = [ordered]@{ strongType = 'Microsoft.Network/privateDnsZones' }
    }
    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Network/privateEndpoints' {

        Require 'privateLinkServiceConnections.groupIds is as required' {
            Condition -Violation '{ "count": { "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]", "where": { "field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]", "equals": "amlworkspace" } }, "greaterOrEquals": 1 }'
        }
    }

    DeployIfNotExists 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups' -Role 'Network Contributor' -Effect (Param Effect) {
        Deployment -TemplateFile './templates/ee40564d-486e-4f68-a5ca-7a621edae0fb.json' -Parameters ([ordered]@{
                privateDnsZoneId       = (Param PrivateDnsZoneId)
                secondPrivateDnsZoneId = (Param SecondPrivateDnsZoneId)
                privateEndpointName    = (Arm '[field(''name'')]')
                location               = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: built-in-policies/policyDefinitions/Machine Learning/Workspace_PrivateDnsZones_DINE.json in Azure/azure-policy, under the MIT licence.