Skip to content

Instantly share code, notes, and snippets.

@joxz
Last active June 20, 2022 08:12
Show Gist options
  • Save joxz/87db69131709ca8b3ad85db8712d9864 to your computer and use it in GitHub Desktop.
Save joxz/87db69131709ca8b3ad85db8712d9864 to your computer and use it in GitHub Desktop.
Azure Policy Collection

Azure Policy

{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkInterfaces"
},
{
"anyOf": [
{
"count": {
"field": "Microsoft.Network/networkInterfaces/dnsSettings.appliedDnsServers[*]"
},
"greater": 0
},
{
"count": {
"field": "Microsoft.Network/networkInterfaces/dnsSettings.dnsServers[*]"
},
"greater": 0
}
]
}
]
},
"then": {
"effect": "audit"
}
}
}
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/publicIPAddresses"
},
{
"field": "Microsoft.Network/publicIPAddresses/publicIPAllocationMethod",
"equals": "Static"
},
{
"field": "Microsoft.Network/publicIPAddresses/ipConfiguration",
"exists": false
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {}
}
{
"mode": "All",
"policyRule": {
"if": {
"not": {
"field": "Microsoft.Network/virtualNetworks/dhcpOptions.dnsServers[*]",
"in": "[parameters('allowedDns')]"
}
},
"then": {
"effect": "audit"
}
},
"parameters": {
"allowedDns": {
"type": "Array",
"metadata": {
"displayName": "Allowed DNS Servers",
"description": "The list of allowed DNS Servers for resources."
}
}
}
}
{
"mode": "All",
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Network/ddosProtectionPlans"
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
{
"mode": "Indexed",
"policyRule": {
"if": {
"anyOf": [
{
"allOf": [
{
"equals": "Microsoft.Network/routeTables",
"field": "type"
},
{
"count": {
"field": "Microsoft.Network/routeTables/routes[*]",
"where": {
"equals": "Internet",
"field": "Microsoft.Network/routeTables/routes[*].nextHopType"
}
},
"greater": 0
}
]
},
{
"allOf": [
{
"equals": "Microsoft.Network/routeTables/routes",
"field": "type"
},
{
"equals": "Internet",
"field": "Microsoft.Network/routeTables/routes/nextHopType"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "The effect of the policy"
},
"allowedValues": [
"audit",
"deny",
"disabled"
],
"defaultValue": "deny"
}
}
}
{
"mode": "All",
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Network/privateDnsZones"
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
// exclude the RG and subscription where deploying private dns zones is allowed from the policy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment