Bylaw

Gallery › Service Bus › Azure Community Policy

Service Bus Namespace - Customer Managed Keys DENY

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This Azure Policy denies the deployment of a Service Bus Namespace when the 'Customer-managed key' setting is not enabled as this implies that a Microsoft Managed Key is used.

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

Azure Policy JSONazurepolicy.json · 51 lines
{
  "name": "c4639a6d-2ec5-470a-8e8f-0a2c150c48fc",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Service Bus Namespace - Customer Managed Keys DENY",
    "description": "This Azure Policy denies the deployment of a Service Bus Namespace when the 'Customer-managed key' setting is not enabled as this implies that a Microsoft Managed Key is used.",
    "metadata": {
      "version": "1.0.0",
      "category": "Service Bus"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ServiceBus/namespaces"
          },
          {
            "field": "Microsoft.ServiceBus/namespaces/sku.tier",
            "equals": "Premium"
          },
          {
            "not": {
              "field": "Microsoft.ServiceBus/namespaces/encryption.keySource",
              "equals": "Microsoft.Keyvault"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawc4639a6d-2ec5-470a-8e8f-0a2c150c48fc.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'c4639a6d-2ec5-470a-8e8f-0a2c150c48fc' {

    Properties @{
        DisplayName = 'Service Bus Namespace - Customer Managed Keys DENY'
        Description = 'This Azure Policy denies the deployment of a Service Bus Namespace when the ''Customer-managed key'' setting is not enabled as this implies that a Microsoft Managed Key is used.'
        Version     = '1.0.0'
        Category    = 'Service Bus'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.ServiceBus/namespaces' {

        When {
            Field sku.tier | Must -Be 'Premium'
        }

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

    Effect (Param Effect)
}

Source: policyDefinitions/Service Bus/service-bus-namespace-customer-managed-keys-deny/azurepolicy.json in Azure/Community-Policy, under the MIT licence.