-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change category from 'tags' to 'storage' and move policy definition f…
…older from 'tags' to 'storage' (#391) * Enforce or extend Storage Account IPRules if tag match * change category and move to storage (from tags)
- Loading branch information
1 parent
1c7df82
commit 9f4fe94
Showing
6 changed files
with
369 additions
and
1 deletion.
There are no files selected for viewing
190 changes: 190 additions & 0 deletions
190
Policies/Storage/enforce-or-extend-storage-account-iprules-if-tag-match/azurepolicy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
{ | ||
"name": "7e5e7a22-32fe-4537-aca8-786a5f871e13", | ||
"properties": { | ||
"displayName": "Enforce or extend Storage Account IPRules if tag match", | ||
"description": "This policy enforces or extends IP ranges if the Storage Account has a matching tag/value (deviating existing IP ranges may be kept or overwritten (parameter: existingIPRangesHandling)). 'publicNetworkAccess' will be enabled if disabled.", | ||
"mode": "Indexed", | ||
"metadata": { | ||
"version": "1.0.0", | ||
"category": "Storage" | ||
}, | ||
"parameters": { | ||
"effect": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "effect", | ||
"description": "policy effect" | ||
}, | ||
"allowedValues": [ | ||
"DeployIfNotExists", | ||
"AuditIfNotExists", | ||
"Disabled" | ||
], | ||
"defaultValue": "DeployIfNotExists" | ||
}, | ||
"tagName": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "tagName", | ||
"description": "name of the tag that must exist for the Storage Account" | ||
} | ||
}, | ||
"tagValue": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "tagValue", | ||
"description": "value of the tagName that must match in order to apply the policy" | ||
} | ||
}, | ||
"enforceIPRanges": { | ||
"type": "Array", | ||
"metadata": { | ||
"displayName": "enforceIPRanges", | ||
"description": "IP/ranges that must be applied" | ||
}, | ||
"defaultValue": [ | ||
"219.94.47.192/28", | ||
"209.127.0.0/16" | ||
] | ||
}, | ||
"existingIPRangesHandling": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "existingIPRangesHandling", | ||
"description": "retain: keep existing IP/ranges that are not defined in 'enforceIPRanges' (union exiting and enforced IP/ranges); remove: enforce 'enforceIPRanges' and remove the existing IP/ranges that are not defined in 'enforceIPRanges'" | ||
}, | ||
"allowedValues": [ | ||
"retain", | ||
"remove" | ||
], | ||
"defaultValue": "retain" | ||
} | ||
}, | ||
"policyRule": { | ||
"if": { | ||
"allOf": [ | ||
{ | ||
"field": "type", | ||
"equals": "Microsoft.Storage/storageAccounts" | ||
}, | ||
{ | ||
"field": "[concat('tags[', parameters('tagName'), ']')]", | ||
"equals": "[parameters('tagValue')]" | ||
} | ||
] | ||
}, | ||
"then": { | ||
"effect": "[parameters('effect')]", | ||
"details": { | ||
"evaluationDelay": "AfterProvisioningSuccess", | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"name": "[field('name')]", | ||
"existenceCondition": { | ||
"allOf": [ | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules", | ||
"exists": "true" | ||
}, | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction", | ||
"equals": "Deny" | ||
}, | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/publicNetworkAccess", | ||
"equals": "Enabled" | ||
}, | ||
{ | ||
"count": { | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]", | ||
"where": { | ||
"anyOf": [ | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].value", | ||
"in": "[parameters('enforceIPRanges')]" | ||
} | ||
] | ||
} | ||
}, | ||
"equals": "[length(parameters('enforceIPRanges'))]" | ||
} | ||
] | ||
}, | ||
"roleDefinitionIds": [ | ||
"/providers/microsoft.authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab" | ||
], | ||
"deployment": { | ||
"properties": { | ||
"mode": "Incremental", | ||
"template": { | ||
"`$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"resourceName": { | ||
"type": "String" | ||
}, | ||
"enforceIPRanges": { | ||
"type": "Array" | ||
}, | ||
"location": { | ||
"type": "String" | ||
}, | ||
"ipRulesExisting": { | ||
"type": "Array" | ||
}, | ||
"existingIPRangesHandling": { | ||
"type": "String" | ||
} | ||
}, | ||
"variables": { | ||
"varIPRangesToApply": "[if(equals(parameters('existingIPRangesHandling'), 'retain'), union(parameters('enforceIPRanges'), parameters('ipRulesExisting')), parameters('enforceIPRanges'))]" | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"apiVersion": "2022-09-01", | ||
"name": "[parameters('resourceName')]", | ||
"location": "[parameters('location')]", | ||
"properties": { | ||
"publicNetworkAccess": "Enabled", | ||
"networkAcls": { | ||
"defaultAction": "Deny", | ||
"copy": [ | ||
{ | ||
"name": "ipRules", | ||
"count": "[length(variables('varIPRangesToApply'))]", | ||
"input": { | ||
"value": "[variables('varIPRangesToApply')[copyIndex('ipRules')]]", | ||
"action": "Allow" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"outputs": {} | ||
}, | ||
"parameters": { | ||
"resourceName": { | ||
"value": "[field('name')]" | ||
}, | ||
"enforceIPRanges": { | ||
"value": "[parameters('enforceIPRanges')]" | ||
}, | ||
"location": { | ||
"value": "[field('location')]" | ||
}, | ||
"ipRulesExisting": { | ||
"value": "[field('Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].value')]" | ||
}, | ||
"existingIPRangesHandling": { | ||
"value": "[parameters('existingIPRangesHandling')]" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...torage/enforce-or-extend-storage-account-iprules-if-tag-match/azurepolicy.parameters.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"effect": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "effect", | ||
"description": "policy effect" | ||
}, | ||
"allowedValues": [ | ||
"DeployIfNotExists", | ||
"AuditIfNotExists", | ||
"Disabled" | ||
], | ||
"defaultValue": "DeployIfNotExists" | ||
}, | ||
"tagName": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "tagName", | ||
"description": "name of the tag that must exist for the Storage Account" | ||
} | ||
}, | ||
"tagValue": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "tagValue", | ||
"description": "value of the tagName that must match in order to apply the policy" | ||
} | ||
}, | ||
"enforceIPRanges": { | ||
"type": "Array", | ||
"metadata": { | ||
"displayName": "enforceIPRanges", | ||
"description": "IP/ranges that must be applied" | ||
}, | ||
"defaultValue": [ | ||
"219.94.47.192/28", | ||
"209.127.0.0/16" | ||
] | ||
}, | ||
"existingIPRangesHandling": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "existingIPRangesHandling", | ||
"description": "retain: keep existing IP/ranges that are not defined in 'enforceIPRanges' (union exiting and enforced IP/ranges); remove: enforce 'enforceIPRanges' and remove the existing IP/ranges that are not defined in 'enforceIPRanges'" | ||
}, | ||
"allowedValues": [ | ||
"retain", | ||
"remove" | ||
], | ||
"defaultValue": "retain" | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
...ies/Storage/enforce-or-extend-storage-account-iprules-if-tag-match/azurepolicy.rules.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
{ | ||
"if": { | ||
"allOf": [ | ||
{ | ||
"field": "type", | ||
"equals": "Microsoft.Storage/storageAccounts" | ||
}, | ||
{ | ||
"field": "[concat('tags[', parameters('tagName'), ']')]", | ||
"equals": "[parameters('tagValue')]" | ||
} | ||
] | ||
}, | ||
"then": { | ||
"effect": "[parameters('effect')]", | ||
"details": { | ||
"evaluationDelay": "AfterProvisioningSuccess", | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"name": "[field('name')]", | ||
"existenceCondition": { | ||
"allOf": [ | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules", | ||
"exists": "true" | ||
}, | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction", | ||
"equals": "Deny" | ||
}, | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/publicNetworkAccess", | ||
"equals": "Enabled" | ||
}, | ||
{ | ||
"count": { | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]", | ||
"where": { | ||
"anyOf": [ | ||
{ | ||
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].value", | ||
"in": "[parameters('enforceIPRanges')]" | ||
} | ||
] | ||
} | ||
}, | ||
"equals": "[length(parameters('enforceIPRanges'))]" | ||
} | ||
] | ||
}, | ||
"roleDefinitionIds": [ | ||
"/providers/microsoft.authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab" | ||
], | ||
"deployment": { | ||
"properties": { | ||
"mode": "Incremental", | ||
"template": { | ||
"`$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"resourceName": { | ||
"type": "String" | ||
}, | ||
"enforceIPRanges": { | ||
"type": "Array" | ||
}, | ||
"location": { | ||
"type": "String" | ||
}, | ||
"ipRulesExisting": { | ||
"type": "Array" | ||
}, | ||
"existingIPRangesHandling": { | ||
"type": "String" | ||
} | ||
}, | ||
"variables": { | ||
"varIPRangesToApply": "[if(equals(parameters('existingIPRangesHandling'), 'retain'), union(parameters('enforceIPRanges'), parameters('ipRulesExisting')), parameters('enforceIPRanges'))]" | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"apiVersion": "2022-09-01", | ||
"name": "[parameters('resourceName')]", | ||
"location": "[parameters('location')]", | ||
"properties": { | ||
"publicNetworkAccess": "Enabled", | ||
"networkAcls": { | ||
"defaultAction": "Deny", | ||
"copy": [ | ||
{ | ||
"name": "ipRules", | ||
"count": "[length(variables('varIPRangesToApply'))]", | ||
"input": { | ||
"value": "[variables('varIPRangesToApply')[copyIndex('ipRules')]]", | ||
"action": "Allow" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"outputs": {} | ||
}, | ||
"parameters": { | ||
"resourceName": { | ||
"value": "[field('name')]" | ||
}, | ||
"enforceIPRanges": { | ||
"value": "[parameters('enforceIPRanges')]" | ||
}, | ||
"location": { | ||
"value": "[field('location')]" | ||
}, | ||
"ipRulesExisting": { | ||
"value": "[field('Microsoft.Storage/storageAccounts/networkAcls.ipRules[*].value')]" | ||
}, | ||
"existingIPRangesHandling": { | ||
"value": "[parameters('existingIPRangesHandling')]" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.