Bylaw

Gallery › Storage › Azure Landing Zones Library

Storage Accounts should restrict CORS rules

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Deny CORS rules for storage account for increased data exfiltration protection and endpoint protection.

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

Azure Policy JSONDeny-Storage-CorsRules.alz_policy_definition.json · 100 lines
{
  "name": "Deny-Storage-CorsRules",
  "properties": {
    "description": "Deny CORS rules for storage account for increased data exfiltration protection and endpoint protection.",
    "displayName": "Storage Accounts should restrict CORS rules",
    "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": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "anyOf": [
          {
            "allOf": [
              {
                "equals": "Microsoft.Storage/storageAccounts/blobServices",
                "field": "type"
              },
              {
                "count": {
                  "field": "Microsoft.Storage/storageAccounts/blobServices/cors.corsRules[*]"
                },
                "greater": 0
              }
            ]
          },
          {
            "allOf": [
              {
                "equals": "Microsoft.Storage/storageAccounts/fileServices",
                "field": "type"
              },
              {
                "count": {
                  "field": "Microsoft.Storage/storageAccounts/fileServices/cors.corsRules[*]"
                },
                "greater": 0
              }
            ]
          },
          {
            "allOf": [
              {
                "equals": "Microsoft.Storage/storageAccounts/tableServices",
                "field": "type"
              },
              {
                "count": {
                  "field": "Microsoft.Storage/storageAccounts/tableServices/cors.corsRules[*]"
                },
                "greater": 0
              }
            ]
          },
          {
            "allOf": [
              {
                "equals": "Microsoft.Storage/storageAccounts/queueServices",
                "field": "type"
              },
              {
                "count": {
                  "field": "Microsoft.Storage/storageAccounts/queueServices/cors.corsRules[*]"
                },
                "greater": 0
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeny-Storage-CorsRules.bylaw.ps1 · 52 lines
# Converted from Deny-Storage-CorsRules.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-Storage-CorsRules' {

    Properties @{
        DisplayName = 'Storage Accounts should restrict CORS rules'
        Description = 'Deny CORS rules for storage account for increased data exfiltration protection and endpoint protection.'
        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   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        Require 'type and cors.corsRules are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Storage/storageAccounts/blobServices' -IfPresent
                Count 'Microsoft.Storage/storageAccounts/blobServices/cors.corsRules[*]' | Must -Be 0
            }
        }

        Require 'type and cors.corsRules are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Storage/storageAccounts/fileServices' -IfPresent
                Count 'Microsoft.Storage/storageAccounts/fileServices/cors.corsRules[*]' | Must -Be 0
            }
        }

        Require 'type and cors.corsRules are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Storage/storageAccounts/tableServices' -IfPresent
                Count 'Microsoft.Storage/storageAccounts/tableServices/cors.corsRules[*]' | Must -Be 0
            }
        }

        Require 'type and cors.corsRules are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Storage/storageAccounts/queueServices' -IfPresent
                Count 'Microsoft.Storage/storageAccounts/queueServices/cors.corsRules[*]' | Must -Be 0
            }
        }
    }

    Effect (Param Effect)
}

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