Bylaw

Gallery › Monitoring › Azure built-in policies

Azure Monitor Logs clusters should be encrypted with customer-managed key

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

Create Azure Monitor logs cluster with customer-managed keys encryption. By default, the log data is encrypted with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance. Customer-managed key in Azure Monitor gives you more control over the access to you data, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys.

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

Azure Policy JSONLogAnalyticsClusters_CMKEnabled_Deny.json · 83 lines
{
  "properties": {
    "displayName": "Azure Monitor Logs clusters should be encrypted with customer-managed key",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Create Azure Monitor logs cluster with customer-managed keys encryption. By default, the log data is encrypted with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance. Customer-managed key in Azure Monitor gives you more control over the access to you data, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys.",
    "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/clusters"
          },
          {
            "anyOf": [
              {
                "anyOf": [
                  {
                    "field": "Microsoft.OperationalInsights/clusters/keyVaultProperties.keyVaultUri",
                    "equals": ""
                  },
                  {
                    "field": "Microsoft.OperationalInsights/clusters/keyVaultProperties.keyVaultUri",
                    "exists": "false"
                  }
                ]
              },
              {
                "anyOf": [
                  {
                    "field": "Microsoft.OperationalInsights/clusters/keyVaultProperties.keyName",
                    "equals": ""
                  },
                  {
                    "field": "Microsoft.OperationalInsights/clusters/keyVaultProperties.keyName",
                    "exists": "false"
                  }
                ]
              },
              {
                "not": {
                  "field": "Microsoft.OperationalInsights/clusters/keyVaultProperties.keyVersion",
                  "exists": "true"
                }
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/1f68a601-6e6d-4e42-babf-3f643a047ea2",
  "name": "1f68a601-6e6d-4e42-babf-3f643a047ea2"
}
Bylaw1f68a601-6e6d-4e42-babf-3f643a047ea2.bylaw.ps1 · 38 lines
# Converted from LogAnalyticsClusters_CMKEnabled_Deny.json by ConvertTo-Bylaw.
Policy '1f68a601-6e6d-4e42-babf-3f643a047ea2' {

    Properties @{
        DisplayName   = 'Azure Monitor Logs clusters should be encrypted with customer-managed key'
        Description   = 'Create Azure Monitor logs cluster with customer-managed keys encryption. By default, the log data is encrypted with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance. Customer-managed key in Azure Monitor gives you more control over the access to you data, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys.'
        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/clusters' {

        Require 'keyVaultProperties.keyVaultUri is not and exists' {
            Field keyVaultProperties.keyVaultUri | Must -Not -Be '' -IfPresent
            Field keyVaultProperties.keyVaultUri | Must -Exist
        }

        Require 'keyVaultProperties.keyName is not and exists' {
            Field keyVaultProperties.keyName | Must -Not -Be '' -IfPresent
            Field keyVaultProperties.keyName | Must -Exist
        }

        Require 'keyVaultProperties.keyVersion exists' {
            Field keyVaultProperties.keyVersion | Must -Exist
        }
    }

    Effect (Param Effect)
}

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