Gallery › Cognitive Services › Azure Community Policy
Configure a private DNS Zone ID for Cognitive Services account groupID
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Configure private DNS zone group to override the DNS resolution for Cognitive Services 'account' groupID private endpoint. The policy distinguishes the correct Azure Private DNS Zone for Cognitive Services of kind OpenAI and other Cognitive Services. Reference: https://github.com/microsoft/industry/issues/380 Kudos @adforeman (GitHub)
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"name": "5d34e716-cc45-4649-8a05-f1f7deaf2f36",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Configure a private DNS Zone ID for Cognitive Services account groupID",
"mode": "Indexed",
"description": "Configure private DNS zone group to override the DNS resolution for Cognitive Services 'account' groupID private endpoint. The policy distinguishes the correct Azure Private DNS Zone for Cognitive Services of kind OpenAI and other Cognitive Services. Reference: https://github.com/microsoft/industry/issues/380 Kudos @adforeman (GitHub)",
"metadata": {
"version": "1.0.0",
"category": "Cognitive Services"
},
"parameters": {
"defaultPrivateDnsZoneId": {
"type": "String",
"metadata": {
"displayName": "Default Private DNS Zone ID",
"description": "The default Private DNS Zone ID for Cognitive Services resources (except Azure OpenAI).",
"strongType": "Microsoft.Network/privateDnsZones"
}
},
"openaiPrivateDnsZoneId": {
"type": "String",
"metadata": {
"displayName": "OpenAI Private DNS Zone ID",
"description": "The Private DNS Zone ID for Azure OpenAI resources.",
"strongType": "Microsoft.Network/privateDnsZones"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"equals": "Microsoft.Network/privateEndpoints",
"field": "type"
},
{
"count": {
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"contains": "Microsoft.CognitiveServices/accounts"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "account"
}
]
}
},
"greaterOrEquals": 1
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7",
"/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"defaultPrivateDnsZoneId": {
"type": "string"
},
"openaiPrivateDnsZoneId": {
"type": "string"
},
"privateEndpointName": {
"type": "string"
},
"location": {
"type": "string"
},
"privateLinkServiceId": {
"type": "array"
}
},
"resources": [
{
"name": "[concat(parameters('privateEndpointName'), '/deployedByPolicy')]",
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"apiVersion": "2022-07-01",
"location": "[parameters('location')]",
"properties": {
"privateDnsZoneConfigs": [
{
"name": "privateDnsZone",
"properties": {
"privateDnsZoneId": "[if(equals(reference(parameters('privateLinkServiceId')[0], '2022-12-01', 'Full').kind, 'OpenAI'), parameters('openaiPrivateDnsZoneId'), parameters('defaultPrivateDnsZoneId'))]"
}
}
]
}
}
]
},
"parameters": {
"defaultPrivateDnsZoneId": {
"value": "[parameters('defaultPrivateDnsZoneId')]"
},
"openaiPrivateDnsZoneId": {
"value": "[parameters('openaiPrivateDnsZoneId')]"
},
"privateEndpointName": {
"value": "[field('name')]"
},
"location": {
"value": "[field('location')]"
},
"privateLinkServiceId": {
"value": "[field('Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId')]"
}
}
}
}
}
}
}
}
}# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '5d34e716-cc45-4649-8a05-f1f7deaf2f36' {
Properties @{
DisplayName = 'Configure a private DNS Zone ID for Cognitive Services account groupID'
Description = 'Configure private DNS zone group to override the DNS resolution for Cognitive Services ''account'' groupID private endpoint. The policy distinguishes the correct Azure Private DNS Zone for Cognitive Services of kind OpenAI and other Cognitive Services. Reference: https://github.com/microsoft/industry/issues/380 Kudos @adforeman (GitHub)'
Version = '1.0.0'
Category = 'Cognitive Services'
Mode = 'Indexed'
}
Parameter DefaultPrivateDnsZoneId @{
Type = 'String'
DisplayName = 'Default Private DNS Zone ID'
Description = 'The default Private DNS Zone ID for Cognitive Services resources (except Azure OpenAI).'
Metadata = [ordered]@{ strongType = 'Microsoft.Network/privateDnsZones' }
}
Parameter OpenaiPrivateDnsZoneId @{
Type = 'String'
DisplayName = 'OpenAI Private DNS Zone ID'
Description = 'The Private DNS Zone ID for Azure OpenAI resources.'
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, privateLinkServiceId and groupIds are as required' {
Count 'privateLinkServiceConnections[*]' -Where {
Field privateLinkServiceId | Must -ContainText 'Microsoft.CognitiveServices/accounts'
Field groupIds | Must -Exist
Count 'groupIds[*]' -Where {
Element | Must -Not -Be 'account'
} | Must -Be 0
} | Must -Be 0
}
}
DeployIfNotExists 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups' -Role 'Network Contributor', 'Reader' -Effect (Param Effect) {
Deployment -TemplateFile './templates/5d34e716-cc45-4649-8a05-f1f7deaf2f36.json' -Parameters ([ordered]@{
defaultPrivateDnsZoneId = (Param DefaultPrivateDnsZoneId)
openaiPrivateDnsZoneId = (Param OpenaiPrivateDnsZoneId)
privateEndpointName = (Arm '[field(''name'')]')
location = (Arm '[field(''location'')]')
privateLinkServiceId = (Arm '[field(''Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId'')]')
})
}
}Its deployment templates are written beside it:
templates/5d34e716-cc45-4649-8a05-f1f7deaf2f36.json
Source: policyDefinitions/Cognitive Services/configure-a-private-dns-zone-id-for-cognitive-services-account-groupid/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw