Gallery › Network › Azure Community Policy
NSG rule ports without IP source
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
need to add description
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 59 lines
{
"name": "cd44e22b-0b26-49a2-8199-e596a17b3560",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "NSG rule ports without IP source",
"description": "need to add description",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"mode": "All",
"parameters": {
"ipAddresses": {
"type": "Array",
"metadata": {
"displayname": "Destination Port Ranges"
}
},
"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"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
"in": "[parameters('ipAddresses')]"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefix",
"equals": "*"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/access",
"equals": "Allow"
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylawcd44e22b-0b26-49a2-8199-e596a17b3560.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'cd44e22b-0b26-49a2-8199-e596a17b3560' {
Properties @{
DisplayName = 'NSG rule ports without IP source'
Description = 'need to add description'
Version = '1.0.0'
Category = 'Network'
Mode = 'All'
}
Parameter IpAddresses @{
Type = 'Array'
DisplayName = 'Destination Port Ranges'
}
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 destinationPortRange | Must -BeIn (Param IpAddresses)
Field sourceAddressPrefix | Must -Be '*'
}
Require 'access is not Allow' {
Field access | Must -Not -Be 'Allow' -IfPresent
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/nsg-rule-ports-without-ip-source/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw