Bylaw

Gallery › Monitoring › Azure Community Policy

Audit enabling of diagnostic logs in App Services

Converted Policy Audit Disabled Mode All Version 1.0.0

Audit enabling of diagnostic logs on the app. This enables you to recreate activity trails for investigation purposes if 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 · 60 lines
{
  "name": "65c3ae53-0826-4bd4-a9f2-6de16dd60762",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit enabling of diagnostic logs in App Services",
    "description": "Audit enabling of diagnostic logs on the app. This enables you to recreate activity trails for investigation purposes if a security incident occurs or your network is compromised",
    "metadata": {
      "category": "Monitoring",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites/config"
          },
          {
            "field": "name",
            "equals": "web"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Web/sites/config/detailedErrorLoggingEnabled",
                "notEquals": "true"
              },
              {
                "field": "Microsoft.Web/sites/config/httpLoggingEnabled",
                "notEquals": "true"
              },
              {
                "field": "Microsoft.Web/sites/config/requestTracingEnabled",
                "notEquals": "true"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw65c3ae53-0826-4bd4-a9f2-6de16dd60762.bylaw.ps1 · 39 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '65c3ae53-0826-4bd4-a9f2-6de16dd60762' {

    Properties @{
        DisplayName = 'Audit enabling of diagnostic logs in App Services'
        Description = 'Audit enabling of diagnostic logs on the app. This enables you to recreate activity trails for investigation purposes if a security incident occurs or your network is compromised'
        Category    = 'Monitoring'
        Version     = '1.0.0'
        Mode        = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Web/sites/config' {

        When {
            Field name | Must -Be 'web'
        }

        Require 'detailedErrorLoggingEnabled is true' {
            Field detailedErrorLoggingEnabled | Must -Be 'true'
        }

        Require 'httpLoggingEnabled is true' {
            Field httpLoggingEnabled | Must -Be 'true'
        }

        Require 'requestTracingEnabled is true' {
            Field requestTracingEnabled | Must -Be 'true'
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Monitoring/audit-enabling-of-diagnostic-logs-in-app-services/azurepolicy.json in Azure/Community-Policy, under the MIT licence.