Gallery › Network › Azure Community Policy
Denies NSG rule changes that allow all inbound traffic
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
Denies the creation of network security group rules that allow all inbound traffic
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 87 lines
{
"name": "249037e5-31bc-4666-93d8-3801f80fc75f",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Denies NSG rule changes that allow all inbound traffic",
"description": "Denies the creation of network security group rules that allow all inbound traffic",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"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": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups/securityRules"
},
{
"allOf": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/access",
"equals": "Allow"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/direction",
"equals": "Inbound"
},
{
"anyOf": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
"equals": "*"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]",
"notEquals": "*"
}
}
]
},
{
"anyOf": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefix",
"in": [
"*",
"Internet"
]
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefixes[*]",
"notIn": [
"*",
"Internet"
]
}
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw249037e5-31bc-4666-93d8-3801f80fc75f.bylaw.ps1 · 44 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '249037e5-31bc-4666-93d8-3801f80fc75f' {
Properties @{
DisplayName = 'Denies NSG rule changes that allow all inbound traffic'
Description = 'Denies the creation of network security group rules that allow all inbound traffic'
Version = '1.0.0'
Category = 'Network'
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/networkSecurityGroups/securityRules' {
When {
Field access | Must -Be 'Allow'
Field direction | Must -Be 'Inbound'
AnyOf {
Field destinationPortRange | Must -Be '*'
Count 'destinationPortRanges[*]' -Where {
Element | Must -Be '*'
} | Must -BeGreaterThan 0
}
}
Require 'sourceAddressPrefix is not one of 2 values' {
Field sourceAddressPrefix | Must -Not -BeIn @('*', 'Internet') -IfPresent
}
Require 'sourceAddressPrefixes is as required' {
Each 'sourceAddressPrefixes[*]' {
Element | Must -Not -BeIn @('*', 'Internet')
}
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/denies-nsg-rule-changes-that-allow-all-inbound-traffic/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw