Gallery › App Service › Azure Community Policy
Configure App Service apps to use private DNS zones with corresponding domain suffix
Converted Policy DeployIfNotExists Disabled Mode All Version 1.0.0
Use private DNS zones to override the DNS resolution for a private endpoint. A private DNS zone links a virtual network to an App Service. This policy deploys the DNS zone configuration to the private DNS zone that corresponds with the domainsuffix of the app (either azurewebsites.net or appserviceenvironment.net).
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 142 lines
{
"name": "ceb2837a-37cc-4210-b801-e7ab055dc14f",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Configure App Service apps to use private DNS zones with corresponding domain suffix",
"mode": "All",
"description": "Use private DNS zones to override the DNS resolution for a private endpoint. A private DNS zone links a virtual network to an App Service. This policy deploys the DNS zone configuration to the private DNS zone that corresponds with the domainsuffix of the app (either azurewebsites.net or appserviceenvironment.net).",
"metadata": {
"version": "1.0.0",
"category": "App Service"
},
"parameters": {
"privateDnsZoneIdAzureWebsites": {
"type": "String",
"metadata": {
"displayName": "Private Dns Zone Id for azurewebsites.net",
"description": "The private DNS zone to deploy in a new private DNS zone group and link to the private endpoint for apps on azurewebsites.net",
"strongType": "Microsoft.Network/privateDnsZones"
}
},
"privateDnsZoneIdAppServiceEnvironment": {
"type": "String",
"metadata": {
"displayName": "Private Dns Zone Id for appserviceenvironment.net",
"description": "The private DNS zone to deploy in a new private DNS zone group and link to the private endpoint for apps on appserviceenvironment.net",
"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": [
{
"field": "type",
"equals": "Microsoft.Network/privateEndpoints"
},
{
"count": {
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"contains": "Microsoft.Web/sites"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "sites"
}
]
}
},
"greaterOrEquals": 1
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"evaluationDelay": "AfterProvisioning",
"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": {
"privateDnsZoneIdAzureWebsites": {
"type": "string"
},
"privateDnsZoneIdAppServiceEnvironment": {
"type": "string"
},
"privateEndpointName": {
"type": "string"
},
"location": {
"type": "string"
},
"privateLinkServiceId": {
"type": "array"
}
},
"resources": [
{
"name": "[concat(parameters('privateEndpointName'), '/deployedByPolicy')]",
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"apiVersion": "2020-03-01",
"location": "[parameters('location')]",
"properties": {
"privateDnsZoneConfigs": [
{
"name": "websites-privateDnsZone",
"properties": {
"privateDnsZoneId": "[if(endsWith(reference(parameters('privateLinkServiceId')[0], '2023-12-01').defaultHostname, 'appserviceenvironment.net'), parameters('privateDnsZoneIdAppServiceEnvironment'), if(endsWith(reference(parameters('privateLinkServiceId')[0], '2023-12-01').defaultHostname, 'azurewebsites.net'), parameters('privateDnsZoneIdAzureWebsites'), parameters('privateDnsZoneIdAzureWebsites')))]"
}
}
]
}
}
]
},
"parameters": {
"privateDnsZoneIdAzureWebsites": {
"value": "[parameters('privateDnsZoneIdAzureWebsites')]"
},
"privateDnsZoneIdAppServiceEnvironment": {
"value": "[parameters('privateDnsZoneIdAppServiceEnvironment')]"
},
"privateEndpointName": {
"value": "[field('name')]"
},
"location": {
"value": "[field('location')]"
},
"privateLinkServiceId": {
"value": "[field('Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId')]"
}
}
}
}
}
}
}
}
}Bylawceb2837a-37cc-4210-b801-e7ab055dc14f.bylaw.ps1 · 53 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'ceb2837a-37cc-4210-b801-e7ab055dc14f' {
Properties @{
DisplayName = 'Configure App Service apps to use private DNS zones with corresponding domain suffix'
Description = 'Use private DNS zones to override the DNS resolution for a private endpoint. A private DNS zone links a virtual network to an App Service. This policy deploys the DNS zone configuration to the private DNS zone that corresponds with the domainsuffix of the app (either azurewebsites.net or appserviceenvironment.net).'
Version = '1.0.0'
Category = 'App Service'
Mode = 'All'
}
Parameter PrivateDnsZoneIdAzureWebsites @{
Type = 'String'
DisplayName = 'Private Dns Zone Id for azurewebsites.net'
Description = 'The private DNS zone to deploy in a new private DNS zone group and link to the private endpoint for apps on azurewebsites.net'
Metadata = [ordered]@{ strongType = 'Microsoft.Network/privateDnsZones' }
}
Parameter PrivateDnsZoneIdAppServiceEnvironment @{
Type = 'String'
DisplayName = 'Private Dns Zone Id for appserviceenvironment.net'
Description = 'The private DNS zone to deploy in a new private DNS zone group and link to the private endpoint for apps on appserviceenvironment.net'
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.Web/sites'
Field groupIds | Must -Exist
Count 'groupIds[*]' -Where {
Element | Must -Not -Be 'sites'
} | Must -Be 0
} | Must -Be 0
}
}
DeployIfNotExists 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups' -Role 'Network Contributor' -EvaluationDelay AfterProvisioning -Effect (Param Effect) {
Deployment -TemplateFile './templates/ceb2837a-37cc-4210-b801-e7ab055dc14f.json' -Parameters ([ordered]@{
privateDnsZoneIdAzureWebsites = (Param PrivateDnsZoneIdAzureWebsites)
privateDnsZoneIdAppServiceEnvironment = (Param PrivateDnsZoneIdAppServiceEnvironment)
privateEndpointName = (Arm '[field(''name'')]')
location = (Arm '[field(''location'')]')
privateLinkServiceId = (Arm '[field(''Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId'')]')
})
}
}Its deployment templates are written beside it:
templates/ceb2837a-37cc-4210-b801-e7ab055dc14f.json
Source: policyDefinitions/App Service/deploy-app-private-endpoint-private-dns-zone-link-domainbased/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw