Bylaw

Gallery › Communication › Azure Community Policy

Enforce allowed domains on ECS

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Denies creation of Email Communication Service domains unless the domain is explicitly approved.

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

Azure Policy JSONazurepolicy.json · 55 lines
{
  "name": "2fc0f268-7ac0-4975-b33f-cd967a773e7b",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Enforce allowed domains on ECS",
    "mode": "All",
    "description": "Denies creation of Email Communication Service domains unless the domain is explicitly approved.",
    "metadata": {
      "version": "1.0.0",
      "category": "Communication"
    },
    "parameters": {
      "allowedDomains": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed domains",
          "description": "List of approved domain resource names, for example contoso.com"
        },
        "defaultValue": [
          "defensie.nl"
        ]
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Specifies whether non-approved Email Communication Service domains are denied, audited, or ignored."
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Deny"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Communication/emailServices/domains"
          },
          {
            "value": "[last(split(field('name'), '/'))]",
            "notIn": "[parameters('allowedDomains')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw2fc0f268-7ac0-4975-b33f-cd967a773e7b.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '2fc0f268-7ac0-4975-b33f-cd967a773e7b' {

    Properties @{
        DisplayName = 'Enforce allowed domains on ECS'
        Description = 'Denies creation of Email Communication Service domains unless the domain is explicitly approved.'
        Version     = '1.0.0'
        Category    = 'Communication'
        Mode        = 'All'
    }

    Parameter AllowedDomains @{
        Type        = 'Array'
        Default     = @('defensie.nl')
        DisplayName = 'Allowed domains'
        Description = 'List of approved domain resource names, for example contoso.com'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Specifies whether non-approved Email Communication Service domains are denied, audited, or ignored.'
    }

    Resource 'Microsoft.Communication/emailServices/domains' {

        Require 'name is as required' {
            Arm '[last(split(field(''name''), ''/''))]' | Must -BeIn (Param AllowedDomains)
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Communication Services/enforce-ecs-allowed-domains/azurepolicy.json in Azure/Community-Policy, under the MIT licence.