Gallery › VirtualEnclaves › Azure built-in policies
Network interfaces should be connected to an approved subnet of the approved virtual network
Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0
This policy blocks network interfaces from connecting to a virtual network or subnet that is not approved. https://aka.ms/VirtualEnclaves
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONApprovedVirtualNetworkSubnets_Deny.json · 107 lines
{
"properties": {
"displayName": "Network interfaces should be connected to an approved subnet of the approved virtual network",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "This policy blocks network interfaces from connecting to a virtual network or subnet that is not approved. https://aka.ms/VirtualEnclaves",
"metadata": {
"version": "1.0.0",
"category": "VirtualEnclaves"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "String",
"defaultValue": "Deny",
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "The effect determines what happens when the policy rule is evaluated to match"
}
},
"virtualNetworkId": {
"type": "String",
"metadata": {
"displayName": "Virtual network Id",
"description": "Resource Id of the approved virtual network. Example: /subscriptions/YourSubscriptionId/resourceGroups/YourResourceGroupName/providers/Microsoft.Network/virtualNetworks/Name",
"strongType": "Microsoft.Network/virtualNetworks"
}
},
"allowedSubnetList": {
"type": "Array",
"metadata": {
"displayName": "Subnet names",
"description": "List of string subnet names that the virtual machine can connect to. By default, all subnets are approved."
},
"defaultValue": []
},
"allowAllSubnets": {
"type": "Boolean",
"metadata": {
"displayName": "Allow all subnets",
"description": "Set this value to true to allow NICs to connect to all subnets within the virtual network."
},
"defaultValue": true
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkInterfaces"
},
{
"anyOf": [
{
"allOf": [
{
"value": "[parameters('allowAllSubnets')]",
"equals": true
},
{
"not": {
"field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].subnet.id",
"like": "[concat(parameters('virtualNetworkId'),'/*')]"
}
}
]
},
{
"allOf": [
{
"value": "[parameters('allowAllSubnets')]",
"equals": false
},
{
"count": {
"value": "[parameters('allowedSubnetList')]",
"name": "subnetName",
"where": {
"field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].subnet.id",
"equals": "[concat(parameters('virtualNetworkId'),'/subnets/',current('subnetName'))]"
}
},
"equals": 0
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/f3a7bbfd-a810-47a6-b5ba-8e17d8cffb96",
"name": "f3a7bbfd-a810-47a6-b5ba-8e17d8cffb96"
}Bylawf3a7bbfd-a810-47a6-b5ba-8e17d8cffb96.bylaw.ps1 · 66 lines
# Converted from ApprovedVirtualNetworkSubnets_Deny.json by ConvertTo-Bylaw.
Policy 'f3a7bbfd-a810-47a6-b5ba-8e17d8cffb96' {
Properties @{
DisplayName = 'Network interfaces should be connected to an approved subnet of the approved virtual network'
Description = 'This policy blocks network interfaces from connecting to a virtual network or subnet that is not approved. https://aka.ms/VirtualEnclaves'
Version = '1.0.0'
Category = 'VirtualEnclaves'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Deny'
DisplayName = 'Effect'
Description = 'The effect determines what happens when the policy rule is evaluated to match'
}
Parameter VirtualNetworkId @{
Type = 'String'
DisplayName = 'Virtual network Id'
Description = 'Resource Id of the approved virtual network. Example: /subscriptions/YourSubscriptionId/resourceGroups/YourResourceGroupName/providers/Microsoft.Network/virtualNetworks/Name'
Metadata = [ordered]@{ strongType = 'Microsoft.Network/virtualNetworks' }
}
Parameter AllowedSubnetList @{
Type = 'Array'
Default = @()
DisplayName = 'Subnet names'
Description = 'List of string subnet names that the virtual machine can connect to. By default, all subnets are approved.'
}
Parameter AllowAllSubnets @{
Type = 'Boolean'
Default = $true
DisplayName = 'Allow all subnets'
Description = 'Set this value to true to allow NICs to connect to all subnets within the virtual network.'
}
Resource 'Microsoft.Network/networkInterfaces' {
Require 'ipConfigurations and subnet.id are as required' {
AnyOf {
Param AllowAllSubnets | Must -Not -Be $true
AllOf {
Field ipConfigurations | Must -Exist
Each 'ipconfigurations[*]' {
Field subnet.id | Must -BeLike (Arm '[concat(parameters(''virtualNetworkId''),''/*'')]') -Strict
}
}
}
}
Require 'ipConfigurations and subnet.id are as required' {
AnyOf {
Param AllowAllSubnets | Must -Not -Be $false
Count -Value (Param AllowedSubnetList) -Name subnetName -Where {
Field ipConfigurations | Must -Exist
Count 'ipconfigurations[*]' -Where {
Field subnet.id | Must -Not -Be (Arm '[concat(parameters(''virtualNetworkId''),''/subnets/'',current(''subnetName''))]')
} | Must -Be 0
} | Must -Not -Be 0
}
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/VirtualEnclaves/ApprovedVirtualNetworkSubnets_Deny.json in Azure/azure-policy, under the MIT licence.
Bylaw