Gallery › App Service › Azure Community Policy
Function apps must have private endpoints enabled
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0
A private endpoint connection enables private connectivity to your function app via a private IP address inside a virtual network. This configuration improves your security posture and supports Azure networking tools and scenarios.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 170 lines
{
"name": "2255c71d-9f5e-43c6-b0e8-5b4f1ddc6c40",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Function apps must have private endpoints enabled",
"description": "A private endpoint connection enables private connectivity to your function app via a private IP address inside a virtual network. This configuration improves your security posture and supports Azure networking tools and scenarios.",
"metadata": {
"category": "App Service",
"version": "1.0.0"
},
"mode": "Indexed",
"parameters": {
"privateEndpointSubnetId": {
"type": "String",
"metadata": {
"displayName": "Subnet to use for Private Endpoints",
"description": "The name of the subnet within the virtual network that you would like to use for your Private Endpoint Connection deployment. Used by the DeployIfNotExists effect.",
"strongType": "Microsoft.Network/virtualNetworks/subnets"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites"
},
{
"field": "kind",
"contains": "functionapp"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Web/sites/privateEndpointConnections",
"existenceCondition": {
"field": "Microsoft.Web/sites/privateEndpointConnections/privateLinkServiceConnectionState.status",
"equals": "Approved"
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7",
"/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
],
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"name": {
"value": "[field('name')]"
},
"serviceId": {
"value": "[field('id')]"
},
"privateEndpointSubnetId": {
"value": "[parameters('privateEndpointSubnetId')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
},
"serviceId": {
"type": "string"
},
"privateEndpointSubnetId": {
"type": "string"
}
},
"variables": {
"privateEndpointName": "[concat('pe-',substring(parameters('name'),0,min(length(parameters('name')),50)),'-',uniquestring(deployment().name))]"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('privateEndpointName')]",
"apiVersion": "2020-06-01",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"name": {
"value": "[parameters('name')]"
},
"privateEndpointSubnetId": {
"value": "[parameters('privateEndpointSubnetId')]"
},
"serviceId": {
"value": "[parameters('serviceId')]"
},
"subnetlocation": {
"value": "[reference(first(take(split(parameters('privateEndpointSubnetId'),'/subnets'),1)),'2020-07-01','Full').location]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "String"
},
"serviceId": {
"type": "String"
},
"privateEndpointSubnetId": {
"type": "String"
},
"subnetlocation": {
"type": "String"
}
},
"variables": {
"privateEndpointName": "[deployment().name]"
},
"resources": [
{
"type": "Microsoft.Network/privateEndpoints",
"apiVersion": "2020-07-01",
"name": "[variables('privateEndpointName')]",
"location": "[parameters('subnetlocation')]",
"properties": {
"subnet": {
"id": "[parameters('privateEndpointSubnetId')]"
},
"privateLinkServiceConnections": [
{
"name": "[parameters('name')]",
"properties": {
"privateLinkServiceId": "[parameters('serviceId')]",
"groupIds": [
"sites"
]
}
}
]
}
}
]
}
}
}
]
}
}
}
}
}
}
}
}Bylaw2255c71d-9f5e-43c6-b0e8-5b4f1ddc6c40.bylaw.ps1 · 42 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '2255c71d-9f5e-43c6-b0e8-5b4f1ddc6c40' {
Properties @{
DisplayName = 'Function apps must have private endpoints enabled'
Description = 'A private endpoint connection enables private connectivity to your function app via a private IP address inside a virtual network. This configuration improves your security posture and supports Azure networking tools and scenarios.'
Category = 'App Service'
Version = '1.0.0'
Mode = 'Indexed'
}
Parameter PrivateEndpointSubnetId @{
Type = 'String'
DisplayName = 'Subnet to use for Private Endpoints'
Description = 'The name of the subnet within the virtual network that you would like to use for your Private Endpoint Connection deployment. Used by the DeployIfNotExists effect.'
Metadata = [ordered]@{ strongType = 'Microsoft.Network/virtualNetworks/subnets' }
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Web/sites' {
Require 'kind does not contain functionapp' {
Field kind | Must -Not -ContainText 'functionapp' -IfPresent
}
}
DeployIfNotExists 'Microsoft.Web/sites/privateEndpointConnections' -Role 'Network Contributor', 'Website Contributor' -Effect (Param Effect) {
Require 'privateLinkServiceConnectionState.status is Approved' {
Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
}
Deployment -TemplateFile './templates/2255c71d-9f5e-43c6-b0e8-5b4f1ddc6c40.json' -Parameters ([ordered]@{
name = (Arm '[field(''name'')]')
serviceId = (Arm '[field(''id'')]')
privateEndpointSubnetId = (Param PrivateEndpointSubnetId)
})
}
}Its deployment templates are written beside it:
templates/2255c71d-9f5e-43c6-b0e8-5b4f1ddc6c40.json
Source: policyDefinitions/App Service/function-apps-must-have-private-endpoints-enabled/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw