Bylaw

Gallery › Storage › Azure Landing Zones Library

Storage Accounts with custom domains assigned should be denied

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy denies the creation of Storage Accounts with custom domains assigned as communication cannot be encrypted, and always uses HTTP.

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

Azure Policy JSONDeny-StorageAccount-CustomDomain.alz_policy_definition.json · 60 lines
{
  "name": "Deny-StorageAccount-CustomDomain",
  "properties": {
    "description": "This policy denies the creation of Storage Accounts with custom domains assigned as communication cannot be encrypted, and always uses HTTP.",
    "displayName": "Storage Accounts with custom domains assigned should be denied",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "Storage",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Deny",
        "metadata": {
          "description": "The effect determines what happens when the policy rule is evaluated to match",
          "displayName": "Effect"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.Storage/storageAccounts",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "exists": "true",
                "field": "Microsoft.Storage/storageAccounts/customDomain"
              },
              {
                "equals": "true",
                "field": "Microsoft.Storage/storageAccounts/customDomain.useSubDomainName"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeny-StorageAccount-CustomDomain.bylaw.ps1 · 32 lines
# Converted from Deny-StorageAccount-CustomDomain.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-StorageAccount-CustomDomain' {

    Properties @{
        DisplayName = 'Storage Accounts with custom domains assigned should be denied'
        Description = 'This policy denies the creation of Storage Accounts with custom domains assigned as communication cannot be encrypted, and always uses HTTP.'
        Category    = 'Storage'
        Version     = '1.0.0'
        Mode        = 'All'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

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

    Resource 'Microsoft.Storage/storageAccounts' {

        Require 'customDomain does not exist' {
            Field customDomain | Must -Not -Exist
        }

        Require 'customDomain.useSubDomainName is not true' {
            Field customDomain.useSubDomainName | Must -Not -Be 'true' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policy_definitions/Deny-StorageAccount-CustomDomain.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.