Gallery › Network › Azure Landing Zones Library
Deny vNet peering cross subscription.
Converted Policy Audit Deny Disabled Mode All Version 1.1.0
This policy denies the creation of vNet Peerings outside of the same subscriptions under the assigned scope.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONDeny-VNET-Peer-Cross-Sub.alz_policy_definition.json · 68 lines
{
"name": "Deny-VNET-Peer-Cross-Sub",
"properties": {
"description": "This policy denies the creation of vNet Peerings outside of the same subscriptions under the assigned scope.",
"displayName": "Deny vNet peering cross subscription.",
"metadata": {
"alzCloudEnvironments": [
"AzureCloud",
"AzureChinaCloud",
"AzureUSGovernment"
],
"category": "Network",
"source": "https://github.com/Azure/Enterprise-Scale/",
"version": "1.1.0"
},
"mode": "All",
"parameters": {
"allowedVnets": {
"defaultValue": [],
"metadata": {
"description": "Array of allowed vNets that can be peered with. Must be entered using their resource ID. Example: /subscriptions/{subId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{vnetName}",
"displayName": "Allowed vNets to peer with"
},
"type": "Array"
},
"effect": {
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Deny",
"metadata": {
"description": "Enable or disable the execution of the policy",
"displayName": "Effect"
},
"type": "String"
}
},
"policyRule": {
"if": {
"allOf": [
{
"equals": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
"field": "type"
},
{
"allOf": [
{
"field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/remoteVirtualNetwork.id",
"notIn": "[parameters('allowedVnets')]"
},
{
"field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/remoteVirtualNetwork.id",
"notLike": "[concat(subscription().id, '/*')]"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"policyType": "Custom"
},
"type": "Microsoft.Authorization/policyDefinitions"
}BylawDeny-VNET-Peer-Cross-Sub.bylaw.ps1 · 38 lines
# Converted from Deny-VNET-Peer-Cross-Sub.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-VNET-Peer-Cross-Sub' {
Properties @{
DisplayName = 'Deny vNet peering cross subscription.'
Description = 'This policy denies the creation of vNet Peerings outside of the same subscriptions under the assigned scope.'
Category = 'Network'
Version = '1.1.0'
Mode = 'All'
Metadata = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
}
Parameter AllowedVnets @{
Type = 'Array'
Default = @()
DisplayName = 'Allowed vNets to peer with'
Description = 'Array of allowed vNets that can be peered with. Must be entered using their resource ID. Example: /subscriptions/{subId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{vnetName}'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Deny'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.Network/virtualNetworks/virtualNetworkPeerings' {
When {
Field remoteVirtualNetwork.id | Must -Not -BeIn (Param AllowedVnets)
}
Require 'remoteVirtualNetwork.id is like (Arm ''[concat(subscription().id, ''''/*'''')]'')' {
Field remoteVirtualNetwork.id | Must -BeLike (Arm '[concat(subscription().id, ''/*'')]')
}
}
Effect (Param Effect)
}Source: policy_definitions/Deny-VNET-Peer-Cross-Sub.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.
Bylaw