Bylaw

Gallery › Monitoring › Azure built-in policies

Saved-queries in Azure Monitor should be saved in customer storage account for logs encryption

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

Link storage account to Log Analytics workspace to protect saved-queries with storage account encryption. Customer-managed keys are commonly required to meet regulatory compliance and for more control over the access to your saved-queries in Azure Monitor. For more details on the above, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys?tabs=portal#customer-managed-key-for-saved-queries.

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

Azure Policy JSONLogAnalyticsWorkspaces_CMKBYOSQueryEnabled_Deny.json · 55 lines
{
  "properties": {
    "displayName": "Saved-queries in Azure Monitor should be saved in customer storage account for logs encryption",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Link storage account to Log Analytics workspace to protect saved-queries with storage account encryption. Customer-managed keys are commonly required to meet regulatory compliance and for more control over the access to your saved-queries in Azure Monitor. For more details on the above, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys?tabs=portal#customer-managed-key-for-saved-queries.",
    "metadata": {
      "version": "1.1.0",
      "category": "Monitoring"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match"
        },
        "allowedValues": [
          "audit",
          "Audit",
          "deny",
          "Deny",
          "disabled",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.OperationalInsights/workspaces"
          },
          {
            "not": {
              "field": "Microsoft.OperationalInsights/workspaces/forceCmkForQuery",
              "equals": "true"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/fa298e57-9444-42ba-bf04-86e8470e32c7",
  "name": "fa298e57-9444-42ba-bf04-86e8470e32c7"
}
Bylawfa298e57-9444-42ba-bf04-86e8470e32c7.bylaw.ps1 · 28 lines
# Converted from LogAnalyticsWorkspaces_CMKBYOSQueryEnabled_Deny.json by ConvertTo-Bylaw.
Policy 'fa298e57-9444-42ba-bf04-86e8470e32c7' {

    Properties @{
        DisplayName   = 'Saved-queries in Azure Monitor should be saved in customer storage account for logs encryption'
        Description   = 'Link storage account to Log Analytics workspace to protect saved-queries with storage account encryption. Customer-managed keys are commonly required to meet regulatory compliance and for more control over the access to your saved-queries in Azure Monitor. For more details on the above, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys?tabs=portal#customer-managed-key-for-saved-queries.'
        Version       = '1.1.0'
        Category      = 'Monitoring'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('audit', 'Audit', 'deny', 'Deny', 'disabled', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match'
    }

    Resource 'Microsoft.OperationalInsights/workspaces' {

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

    Effect (Param Effect)
}

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