Bylaw

Gallery › Storage › Azure built-in policies

Storage accounts should have infrastructure encryption

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

Enable infrastructure encryption for higher level of assurance that the data is secure. When infrastructure encryption is enabled, data in a storage account is encrypted twice.

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

Azure Policy JSONStorageAccountInfrastructureEncryptionEnabled_Audit.json · 113 lines
{
  "properties": {
    "displayName": "Storage accounts should have infrastructure encryption",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Enable infrastructure encryption for higher level of assurance that the data is secure. When infrastructure encryption is enabled, data in a storage account is encrypted twice.",
    "metadata": {
      "version": "1.1.0",
      "category": "Storage"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the audit policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "excludedManagedByResourceProviders": {
        "type": "Array",
        "metadata": {
          "displayName": "Managed services to exclude",
          "description": "Select managed services whose storage accounts should be excluded from this policy, or select all managed resource groups. Leave empty to evaluate all storage accounts."
        },
        "allowedValues": [
          "Azure Red Hat OpenShift",
          "Azure Databricks",
          "Microsoft Purview",
          "All managed resource groups"
        ],
        "defaultValue": []
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "anyOf": [
              {
                "value": "[contains(parameters('excludedManagedByResourceProviders'), 'Azure Red Hat OpenShift')]",
                "equals": false
              },
              {
                "value": "[resourcegroup().managedBy]",
                "notContains": "/providers/Microsoft.RedHatOpenShift/"
              }
            ]
          },
          {
            "anyOf": [
              {
                "value": "[contains(parameters('excludedManagedByResourceProviders'), 'Azure Databricks')]",
                "equals": false
              },
              {
                "value": "[resourcegroup().managedBy]",
                "notContains": "/providers/Microsoft.Databricks/"
              }
            ]
          },
          {
            "anyOf": [
              {
                "value": "[contains(parameters('excludedManagedByResourceProviders'), 'Microsoft Purview')]",
                "equals": false
              },
              {
                "value": "[resourcegroup().managedBy]",
                "notContains": "/providers/Microsoft.Purview/"
              }
            ]
          },
          {
            "anyOf": [
              {
                "value": "[contains(parameters('excludedManagedByResourceProviders'), 'All managed resource groups')]",
                "equals": false
              },
              {
                "value": "[empty(resourcegroup().managedBy)]",
                "equals": true
              }
            ]
          },
          {
            "field": "Microsoft.Storage/storageAccounts/encryption.requireInfrastructureEncryption",
            "notEquals": "true"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/4733ea7b-a883-42fe-8cac-97454c2a9e4a",
  "name": "4733ea7b-a883-42fe-8cac-97454c2a9e4a"
}
Bylaw4733ea7b-a883-42fe-8cac-97454c2a9e4a.bylaw.ps1 · 54 lines
# Converted from StorageAccountInfrastructureEncryptionEnabled_Audit.json by ConvertTo-Bylaw.
Policy '4733ea7b-a883-42fe-8cac-97454c2a9e4a' {

    Properties @{
        DisplayName   = 'Storage accounts should have infrastructure encryption'
        Description   = 'Enable infrastructure encryption for higher level of assurance that the data is secure. When infrastructure encryption is enabled, data in a storage account is encrypted twice.'
        Version       = '1.1.0'
        Category      = 'Storage'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the audit policy'
    }
    Parameter ExcludedManagedByResourceProviders @{
        Type          = 'Array'
        AllowedValues = @('Azure Red Hat OpenShift', 'Azure Databricks', 'Microsoft Purview', 'All managed resource groups')
        Default       = @()
        DisplayName   = 'Managed services to exclude'
        Description   = 'Select managed services whose storage accounts should be excluded from this policy, or select all managed resource groups. Leave empty to evaluate all storage accounts.'
    }

    Resource 'Microsoft.Storage/storageAccounts' {

        When {
            AnyOf {
                Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''Azure Red Hat OpenShift'')]' | Must -Be $false
                Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.RedHatOpenShift/'
            }
            AnyOf {
                Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''Azure Databricks'')]' | Must -Be $false
                Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.Databricks/'
            }
            AnyOf {
                Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''Microsoft Purview'')]' | Must -Be $false
                Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.Purview/'
            }
            AnyOf {
                Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''All managed resource groups'')]' | Must -Be $false
                Arm '[empty(resourcegroup().managedBy)]' | Must -Be $true
            }
        }

        Require 'encryption.requireInfrastructureEncryption is true' {
            Field encryption.requireInfrastructureEncryption | Must -Be 'true'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Storage/StorageAccountInfrastructureEncryptionEnabled_Audit.json in Azure/azure-policy, under the MIT licence.