Gallery › Network › Azure Community Policy
Prevent cross subscription Private Link
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This policy prevents private link between subscriptions.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 72 lines
{
"name": "42f607e8-489b-44e2-ad9d-6df23127734e",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Prevent cross subscription Private Link",
"description": "This policy prevents private link between subscriptions.",
"metadata": {
"category": "Network",
"createdBy": "",
"updatedBy": null,
"updatedOn": null,
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Deny, Audit or Disabled the execution of the Policy"
},
"allowedValues": [
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"equals": "Microsoft.Network/privateEndpoints",
"field": "type"
},
{
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"notContains": "[concat('/subscriptions/',split(field('id'),'/')[2])]"
},
{
"value": "[length(field('Microsoft.Network/privateEndpoints/privateLinkServiceConnections'))]",
"greater": 0
}
]
},
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/manualPrivateLinkServiceConnections[*].privateLinkServiceId",
"notContains": "[concat('/subscriptions/',split(field('id'),'/')[2])]"
},
{
"value": "[length(field('Microsoft.Network/privateEndpoints/manualPrivateLinkServiceConnections'))]",
"greater": 0
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw42f607e8-489b-44e2-ad9d-6df23127734e.bylaw.ps1 · 41 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '42f607e8-489b-44e2-ad9d-6df23127734e' {
Properties @{
DisplayName = 'Prevent cross subscription Private Link'
Description = 'This policy prevents private link between subscriptions.'
Category = 'Network'
Version = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Network/privateEndpoints' {
Require 'privateLinkServiceConnections, privateLinkServiceId and id are as required' {
AnyOf {
Count 'privateLinkServiceConnections[*]' -Where {
Field privateLinkServiceId | Must -ContainText (Arm '[concat(''/subscriptions/'',split(field(''id''),''/'')[2])]')
} | Must -Not -Be 0
Arm '[length(field(''Microsoft.Network/privateEndpoints/privateLinkServiceConnections''))]' | Must -BeLessOrEqual 0
}
}
Require 'manualPrivateLinkServiceConnections, privateLinkServiceId and id are as required' {
AnyOf {
Count 'manualPrivateLinkServiceConnections[*]' -Where {
Field privateLinkServiceId | Must -ContainText (Arm '[concat(''/subscriptions/'',split(field(''id''),''/'')[2])]')
} | Must -Not -Be 0
Arm '[length(field(''Microsoft.Network/privateEndpoints/manualPrivateLinkServiceConnections''))]' | Must -BeLessOrEqual 0
}
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/prevent-cross-subscription-private-link/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw