Bylaw

Gallery › Event Hub › Azure built-in policies

Event Hub namespaces should use a customer-managed key for encryption

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

Azure Event Hubs supports the option of encrypting data at rest with either Microsoft-managed keys (default) or customer-managed keys. Choosing to encrypt data using customer-managed keys enables you to assign, rotate, disable, and revoke access to the keys that Event Hub will use to encrypt data in your namespace. Note that Event Hub only supports encryption with customer-managed keys for namespaces in dedicated clusters.

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

Azure Policy JSONCustomerManagedKeyEnabled_Audit.json · 55 lines
{
  "properties": {
    "displayName": "Event Hub namespaces should use a customer-managed key for encryption",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Azure Event Hubs supports the option of encrypting data at rest with either Microsoft-managed keys (default) or customer-managed keys. Choosing to encrypt data using customer-managed keys enables you to assign, rotate, disable, and revoke access to the keys that Event Hub will use to encrypt data in your namespace. Note that Event Hub only supports encryption with customer-managed keys for namespaces in dedicated clusters.",
    "metadata": {
      "version": "1.0.0",
      "category": "Event Hub"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.EventHub/namespaces"
          },
          {
            "field": "Microsoft.EventHub/namespaces/clusterArmId",
            "exists": "true"
          },
          {
            "not": {
              "field": "Microsoft.EventHub/namespaces/encryption.keySource",
              "equals": "Microsoft.Keyvault"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/a1ad735a-e96f-45d2-a7b2-9a4932cab7ec",
  "name": "a1ad735a-e96f-45d2-a7b2-9a4932cab7ec"
}
Bylawa1ad735a-e96f-45d2-a7b2-9a4932cab7ec.bylaw.ps1 · 32 lines
# Converted from CustomerManagedKeyEnabled_Audit.json by ConvertTo-Bylaw.
Policy 'a1ad735a-e96f-45d2-a7b2-9a4932cab7ec' {

    Properties @{
        DisplayName   = 'Event Hub namespaces should use a customer-managed key for encryption'
        Description   = 'Azure Event Hubs supports the option of encrypting data at rest with either Microsoft-managed keys (default) or customer-managed keys. Choosing to encrypt data using customer-managed keys enables you to assign, rotate, disable, and revoke access to the keys that Event Hub will use to encrypt data in your namespace. Note that Event Hub only supports encryption with customer-managed keys for namespaces in dedicated clusters.'
        Version       = '1.0.0'
        Category      = 'Event Hub'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.EventHub/namespaces' {

        When {
            Field clusterArmId | Must -Exist
        }

        Require 'encryption.keySource is Microsoft.Keyvault' {
            Field encryption.keySource | Must -Be 'Microsoft.Keyvault'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Event Hub/CustomerManagedKeyEnabled_Audit.json in Azure/azure-policy, under the MIT licence.