Gallery › Storage › Azure Landing Zones Library
Storage Accounts should use a container delete retention policy
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
Enforce container delete retention policies larger than seven days for storage account. Enable this for increased data loss protection.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONDeny-Storage-ContainerDeleteRetentionPolicy.alz_policy_definition.json · 72 lines
{
"name": "Deny-Storage-ContainerDeleteRetentionPolicy",
"properties": {
"description": "Enforce container delete retention policies larger than seven days for storage account. Enable this for increased data loss protection.",
"displayName": "Storage Accounts should use a container delete retention policy",
"metadata": {
"alzCloudEnvironments": [
"AzureCloud",
"AzureChinaCloud",
"AzureUSGovernment"
],
"category": "Storage",
"source": "https://github.com/Azure/Enterprise-Scale/",
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"effect": {
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Deny",
"metadata": {
"description": "Enable or disable the execution of the policy",
"displayName": "Effect"
},
"type": "String"
},
"minContainerDeleteRetentionInDays": {
"defaultValue": 7,
"metadata": {
"description": "Specifies the minimum number of days for the container delete retention policy",
"displayName": "Minimum Container Delete Retention in Days"
},
"type": "Integer"
}
},
"policyRule": {
"if": {
"allOf": [
{
"equals": "Microsoft.Storage/storageAccounts/blobServices",
"field": "type"
},
{
"anyOf": [
{
"exists": false,
"field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.enabled"
},
{
"field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.enabled",
"notEquals": true
},
{
"field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.days",
"less": "[parameters('minContainerDeleteRetentionInDays')]"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"policyType": "Custom"
},
"type": "Microsoft.Authorization/policyDefinitions"
}BylawDeny-Storage-ContainerDeleteRetentionPolicy.bylaw.ps1 · 42 lines
# Converted from Deny-Storage-ContainerDeleteRetentionPolicy.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-Storage-ContainerDeleteRetentionPolicy' {
Properties @{
DisplayName = 'Storage Accounts should use a container delete retention policy'
Description = 'Enforce container delete retention policies larger than seven days for storage account. Enable this for increased data loss protection.'
Category = 'Storage'
Version = '1.0.0'
Mode = 'All'
Metadata = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Deny'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter MinContainerDeleteRetentionInDays @{
Type = 'Integer'
Default = 7
DisplayName = 'Minimum Container Delete Retention in Days'
Description = 'Specifies the minimum number of days for the container delete retention policy'
}
Resource 'Microsoft.Storage/storageAccounts/blobServices' {
Require 'containerDeleteRetentionPolicy.enabled exists' {
Field containerDeleteRetentionPolicy.enabled | Must -Exist
}
Require 'containerDeleteRetentionPolicy.enabled is true' {
Field containerDeleteRetentionPolicy.enabled | Must -Be $true
}
Require 'containerDeleteRetentionPolicy.days is at least the MinContainerDeleteRetentionInDays parameter' {
Field containerDeleteRetentionPolicy.days | Must -BeGreaterOrEqual (Param MinContainerDeleteRetentionInDays) -IfPresent
}
}
Effect (Param Effect)
}Source: policy_definitions/Deny-Storage-ContainerDeleteRetentionPolicy.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.
Bylaw