Bylaw

Gallery › Monitoring › Azure Community Policy

Audit enabling of diagnostic logs in Event Hub

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0

Audit enabling of logs and retain them up to a year. This enables recreation of 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": "fc64cb3d-51bb-4985-b164-076ff1f88e8e",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit enabling of diagnostic logs in Event Hub",
    "description": "Audit enabling of logs and retain them up to a year. This enables recreation of 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.EventHub/namespaces"
      },
      "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')]"
              }
            ]
          }
        }
      }
    }
  }
}
Bylawfc64cb3d-51bb-4985-b164-076ff1f88e8e.bylaw.ps1 · 38 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'fc64cb3d-51bb-4985-b164-076ff1f88e8e' {

    Properties @{
        DisplayName = 'Audit enabling of diagnostic logs in Event Hub'
        Description = 'Audit enabling of logs and retain them up to a year. This enables recreation of 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.EventHub/namespaces'

    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-event-hub/azurepolicy.json in Azure/Community-Policy, under the MIT licence.