Gallery › Monitoring › Azure Community Policy
Audit enabling of diagnostic logs in Key Vault
Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0
Audit enabling of logs and retain them up to a year. This enables you to recreate activity trails for investigation purposes when a security incident occurs or your network is compromised
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 59 lines
{
"name": "647d9b72-05ae-410b-b5a3-b6c33b732632",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Audit enabling of diagnostic logs in Key Vault",
"description": "Audit enabling of logs and retain them up to a year. This enables you to recreate activity trails for investigation purposes when a security incident occurs or your network is compromised",
"metadata": {
"category": "Monitoring",
"version": "1.0.0"
},
"mode": "Indexed",
"parameters": {
"requiredRetentionDays": {
"type": "String",
"defaultValue": "365",
"metadata": {
"displayName": "Required retention (days)",
"description": "The required diagnostic logs retention in days"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.KeyVault/vaults"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled",
"equals": "true"
},
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days",
"equals": "[parameters('requiredRetentionDays')]"
}
]
}
}
}
}
}
}Bylaw647d9b72-05ae-410b-b5a3-b6c33b732632.bylaw.ps1 · 38 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '647d9b72-05ae-410b-b5a3-b6c33b732632' {
Properties @{
DisplayName = 'Audit enabling of diagnostic logs in Key Vault'
Description = 'Audit enabling of logs and retain them up to a year. This enables you to recreate activity trails for investigation purposes when a security incident occurs or your network is compromised'
Category = 'Monitoring'
Version = '1.0.0'
Mode = 'Indexed'
}
Parameter RequiredRetentionDays @{
Default = '365'
DisplayName = 'Required retention (days)'
Description = 'The required diagnostic logs retention in days'
}
Parameter Effect @{
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.KeyVault/vaults'
AuditIfNotExists 'Microsoft.Insights/diagnosticSettings' -Effect (Param Effect) {
Require 'logs, retentionPolicy.enabled and retentionPolicy.days are as required' {
Field logs | Must -Exist
Each 'logs[*]' {
Field retentionPolicy.enabled | Must -Be 'true' -Strict
}
Field logs | Must -Exist
Each 'logs[*]' {
Field retentionPolicy.days | Must -Be (Param RequiredRetentionDays) -Strict
}
}
}
}Source: policyDefinitions/Monitoring/audit-enabling-of-diagnostic-logs-in-key-vault/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw