Gallery › Storage › Azure Community Policy
Storage Accounts firewall IP rules may only contain IPs from a list of approved IPs
Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0
Storage Account firewalls can have IP rules. Typically we don't want to allow users to add any IP or range to the firewall, but instead, as is more typical, we want only corporate public IP space to be allowed within the firewall. This Policy can detect if an IP or range of IPs being added to the firewall on a storage account is within a list of IPs that you pass into this Policy.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"name": "0eaf4df1-76b8-4278-9d73-5b4a6f122117",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Storage Accounts firewall IP rules may only contain IPs from a list of approved IPs",
"description": "Storage Account firewalls can have IP rules. Typically we don't want to allow users to add any IP or range to the firewall, but instead, as is more typical, we want only corporate public IP space to be allowed within the firewall. This Policy can detect if an IP or range of IPs being added to the firewall on a storage account is within a list of IPs that you pass into this Policy.",
"metadata": {
"version": "1.0.0",
"category": "Storage"
},
"mode": "Indexed",
"parameters": {
"allowedIps": {
"type": "Array"
},
"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.Storage/storageAccounts"
},
{
"count": {
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]",
"where": {
"count": {
"value": "[parameters('allowedIps')]",
"name": "approvedPrefix",
"where": {
"value": "[ipRangeContains(current('approvedPrefix'), current('Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].value'))]",
"equals": false
}
},
"greater": 0
}
},
"greater": 0
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '0eaf4df1-76b8-4278-9d73-5b4a6f122117' {
Properties @{
DisplayName = 'Storage Accounts firewall IP rules may only contain IPs from a list of approved IPs'
Description = 'Storage Account firewalls can have IP rules. Typically we don''t want to allow users to add any IP or range to the firewall, but instead, as is more typical, we want only corporate public IP space to be allowed within the firewall. This Policy can detect if an IP or range of IPs being added to the firewall on a storage account is within a list of IPs that you pass into this Policy.'
Version = '1.0.0'
Category = 'Storage'
Mode = 'Indexed'
}
Parameter AllowedIps @{
Type = 'Array'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Storage/storageAccounts' {
Require 'networkAcls.ipRules is as required' {
Each 'networkAcls.ipRules[*]' {
Count -Value (Param AllowedIps) -Name approvedPrefix -Where {
Arm '[ipRangeContains(current(''approvedPrefix''), current(''Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].value''))]' | Must -Be $false
} | Must -Be 0
}
}
}
Effect (Param Effect)
}Source: policyDefinitions/Storage/storage-accounts-firewall-ip-rules-may-only-contain-ips-from-a-list-of-approved-ips/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw