Gallery › Monitoring › Azure built-in policies
Activity log should be retained for at least one year
Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0
This policy audits the activity log if the retention is not set for 365 days or forever (retention days set to 0).
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONActivityLogRetention_365orGreater.json · 72 lines
{
"properties": {
"displayName": "Activity log should be retained for at least one year",
"policyType": "BuiltIn",
"mode": "All",
"description": "This policy audits the activity log if the retention is not set for 365 days or forever (retention days set to 0).",
"metadata": {
"version": "1.0.0",
"category": "Monitoring"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "string",
"defaultValue": "AuditIfNotExists",
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Resources/subscriptions"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/logProfiles",
"existenceCondition": {
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Insights/logProfiles/retentionPolicy.enabled",
"equals": "true"
},
{
"field": "Microsoft.Insights/logProfiles/retentionPolicy.days",
"equals": "365"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Insights/logProfiles/retentionPolicy.enabled",
"equals": "false"
},
{
"field": "Microsoft.Insights/logProfiles/retentionPolicy.days",
"equals": "0"
}
]
}
]
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/b02aacc0-b073-424e-8298-42b22829ee0a",
"name": "b02aacc0-b073-424e-8298-42b22829ee0a"
}Bylawb02aacc0-b073-424e-8298-42b22829ee0a.bylaw.ps1 · 37 lines
# Converted from ActivityLogRetention_365orGreater.json by ConvertTo-Bylaw.
Policy 'b02aacc0-b073-424e-8298-42b22829ee0a' {
Properties @{
DisplayName = 'Activity log should be retained for at least one year'
Description = 'This policy audits the activity log if the retention is not set for 365 days or forever (retention days set to 0).'
Version = '1.0.0'
Category = 'Monitoring'
PolicyVersion = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
Type = 'string'
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.Resources/subscriptions'
AuditIfNotExists 'Microsoft.Insights/logProfiles' -Effect (Param Effect) {
Require 'retentionPolicy.enabled and retentionPolicy.days are as required' {
AnyOf {
AllOf {
Field retentionPolicy.enabled | Must -Be 'true'
Field retentionPolicy.days | Must -Be '365'
}
AllOf {
Field retentionPolicy.enabled | Must -Be 'false'
Field retentionPolicy.days | Must -Be '0'
}
}
}
}
}Source: built-in-policies/policyDefinitions/Monitoring/ActivityLogRetention_365orGreater.json in Azure/azure-policy, under the MIT licence.
Bylaw