Gallery › Mission › Azure built-in policies
Virtual Network should specify allowed service endpoints
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restricts which Azure service endpoints can be enabled on subnets to reduce the attack surface and ensure only approved services can be accessed from the virtual network.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONVNETAllowed-ServiceEndPoints_Audit.json · 135 lines
{
"properties": {
"displayName": "Virtual Network should specify allowed service endpoints",
"policyType": "BuiltIn",
"mode": "All",
"description": "This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restricts which Azure service endpoints can be enabled on subnets to reduce the attack surface and ensure only approved services can be accessed from the virtual network.",
"metadata": {
"version": "1.0.0",
"category": "Mission"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Audit"
},
"allowedServiceTypes": {
"type": "Array",
"metadata": {
"displayName": "Allowed Service Endpoint Service Types",
"description": " Allowed Service Endpoint Service Types for Subnets. Example: Microsoft.Storage, Microsoft.KeyVault"
},
"defaultValue": []
},
"subnetDelegationsToExclude": {
"type": "Array",
"metadata": {
"displayName": "Subnet Delegations to Exclude",
"description": " Exclude Subnets which have specific Subnet Delegations (ex. Microsoft.ApiManagement/service)"
},
"defaultValue": []
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"in": [
"Microsoft.Network/virtualNetworks",
"Microsoft.Network/virtualNetworks/subnets"
]
},
{
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks/subnets"
},
{
"count": {
"field": "Microsoft.Network/virtualNetworks/subnets/serviceEndpoints[*]",
"where": {
"value": "[current('Microsoft.Network/virtualNetworks/subnets/serviceEndpoints[*].service')]",
"notIn": "[parameters('allowedServiceTypes')]"
}
},
"greater": 0
},
{
"count": {
"field": "Microsoft.Network/virtualNetworks/subnets/delegations[*]",
"where": {
"field": "Microsoft.Network/virtualNetworks/subnets/delegations[*].serviceName",
"in": "[parameters('subnetDelegationsToExclude')]"
}
},
"equals": 0
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks"
},
{
"count": {
"field": "Microsoft.Network/virtualNetworks/subnets[*]",
"where": {
"allOf": [
{
"count": {
"field": "Microsoft.Network/virtualNetworks/subnets[*].serviceEndpoints[*]",
"where": {
"value": "[current('Microsoft.Network/virtualNetworks/subnets[*].serviceEndpoints[*].service')]",
"notIn": "[parameters('allowedServiceTypes')]"
}
},
"greater": 0
},
{
"count": {
"field": "Microsoft.Network/virtualNetworks/subnets[*].delegations[*]",
"where": {
"field": "Microsoft.Network/virtualNetworks/subnets[*].delegations[*].serviceName",
"in": "[parameters('subnetDelegationsToExclude')]"
}
},
"equals": 0
}
]
}
},
"greater": 0
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/918dcd3f-28e6-4fa5-8373-44919b46c98e",
"name": "918dcd3f-28e6-4fa5-8373-44919b46c98e"
}Bylaw918dcd3f-28e6-4fa5-8373-44919b46c98e.bylaw.ps1 · 68 lines
# Converted from VNETAllowed-ServiceEndPoints_Audit.json by ConvertTo-Bylaw.
Policy '918dcd3f-28e6-4fa5-8373-44919b46c98e' {
Properties @{
DisplayName = 'Virtual Network should specify allowed service endpoints'
Description = 'This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restricts which Azure service endpoints can be enabled on subnets to reduce the attack surface and ensure only approved services can be accessed from the virtual network.'
Version = '1.0.0'
Category = 'Mission'
PolicyVersion = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter AllowedServiceTypes @{
Type = 'Array'
Default = @()
DisplayName = 'Allowed Service Endpoint Service Types'
Description = ' Allowed Service Endpoint Service Types for Subnets. Example: Microsoft.Storage, Microsoft.KeyVault'
}
Parameter SubnetDelegationsToExclude @{
Type = 'Array'
Default = @()
DisplayName = 'Subnet Delegations to Exclude'
Description = ' Exclude Subnets which have specific Subnet Delegations (ex. Microsoft.ApiManagement/service)'
}
Resource * {
When {
Field type | Must -BeIn @('Microsoft.Network/virtualNetworks', 'Microsoft.Network/virtualNetworks/subnets')
}
Require 'type, serviceEndpoints, delegations and 1 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/virtualNetworks/subnets' -IfPresent
Count 'Microsoft.Network/virtualNetworks/subnets/serviceEndpoints[*]' -Where {
Arm '[current(''Microsoft.Network/virtualNetworks/subnets/serviceEndpoints[*].service'')]' | Must -Not -BeIn (Param AllowedServiceTypes)
} | Must -Be 0
Count 'Microsoft.Network/virtualNetworks/subnets/delegations[*]' -Where {
Field serviceName | Must -BeIn (Param SubnetDelegationsToExclude)
} | Must -Not -Be 0
}
}
Require 'type, subnets, serviceEndpoints and 2 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/virtualNetworks' -IfPresent
Each 'Microsoft.Network/virtualNetworks/subnets[*]' {
AnyOf {
Count 'serviceEndpoints[*]' -Where {
Arm '[current(''Microsoft.Network/virtualNetworks/subnets[*].serviceEndpoints[*].service'')]' | Must -Not -BeIn (Param AllowedServiceTypes)
} | Must -Be 0
Count 'delegations[*]' -Where {
Field serviceName | Must -BeIn (Param SubnetDelegationsToExclude)
} | Must -Not -Be 0
}
}
}
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Mission/VNETAllowed-ServiceEndPoints_Audit.json in Azure/azure-policy, under the MIT licence.
Bylaw