Bylaw

Gallery › Monitoring › Azure built-in policies

Azure Front Door should have Resource logs enabled

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

Enable Resource logs for Azure Front Door (plus WAF) and stream to a Log Analytics workspace. Get detailed visibility into inbound web traffic and actions taken to mitigate attacks.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONAFD_DiagnosticLogEnabled_Audit.json · 60 lines
{
  "properties": {
    "displayName": "Azure Front Door should have Resource logs enabled",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Enable Resource logs for Azure Front Door (plus WAF) and stream to a Log Analytics workspace. Get detailed visibility into inbound web traffic and actions taken to mitigate attacks.",
    "metadata": {
      "version": "1.0.0",
      "category": "Monitoring"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Network/frontdoors"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
                "equals": "true"
              },
              {
                "field": "Microsoft.Insights/diagnosticSettings/metrics.enabled",
                "equals": "true"
              },
              {
                "field": "Microsoft.Insights/diagnosticSettings/workspaceId",
                "exists": "true"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/8a04f872-51e9-4313-97fb-fc1c35430fd8",
  "name": "8a04f872-51e9-4313-97fb-fc1c35430fd8"
}
Bylaw8a04f872-51e9-4313-97fb-fc1c35430fd8.bylaw.ps1 · 29 lines
# Converted from AFD_DiagnosticLogEnabled_Audit.json by ConvertTo-Bylaw.
Policy '8a04f872-51e9-4313-97fb-fc1c35430fd8' {

    Properties @{
        DisplayName   = 'Azure Front Door should have Resource logs enabled'
        Description   = 'Enable Resource logs for Azure Front Door (plus WAF) and stream to a Log Analytics workspace. Get detailed visibility into inbound web traffic and actions taken to mitigate attacks.'
        Version       = '1.0.0'
        Category      = 'Monitoring'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Network/frontdoors'

    AuditIfNotExists 'Microsoft.Insights/diagnosticSettings' -Effect (Param Effect) {
        Require 'logs.enabled is true, metrics.enabled is true and workspaceId exists' {
            Field logs.enabled | Must -Be 'true'
            Field metrics.enabled | Must -Be 'true'
            Field workspaceId | Must -Exist
        }
    }
}

Source: built-in-policies/policyDefinitions/Monitoring/AFD_DiagnosticLogEnabled_Audit.json in Azure/azure-policy, under the MIT licence.