Skip to content

Instantly share code, notes, and snippets.

@rcabr
Created August 12, 2019 17:59
Show Gist options
  • Save rcabr/2830eda6e1192431198e376fa13ddbc6 to your computer and use it in GitHub Desktop.
Save rcabr/2830eda6e1192431198e376fa13ddbc6 to your computer and use it in GitHub Desktop.
Azure Policy that applies default IP Security Restrictions to a Web App
{
"properties": {
"displayName": "Web App default IP restrictions",
"mode": "indexed",
"description": "Configures Web App IP restriction to allow access from specified public IP addresses",
"metadata": {
"category": "Security v5"
},
"parameters": {},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Web/sites"
},
"then": {
"effect": "DeployIfNotExists",
"details": {
"type": "Microsoft.Web/sites/config",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
],
"existenceCondition": {
"not": {
"field": "Microsoft.Web/sites/config/web.ipSecurityRestrictions[*].action",
"Equals": "Allow"
}
},
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"name": {
"value": "[field('name')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('name'), '/web')]",
"type": "Microsoft.Web/sites/config",
"apiVersion": "2018-11-01",
"properties": {
"scmIpSecurityRestrictionsUseMain": true,
"ipSecurityRestrictions": [
{
"ipAddress": "[IP Address CIDR format]",
"action": "Allow",
"priority": 3000,
"name": "[Your name]"
},
{
"ipAddress": "[IP Address CIDR format]",
"action": "Allow",
"priority": 3001,
"name": "[Your name]"
}
]
}
}
]
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment