Bylaw

Gallery › Monitoring › Azure built-in policies

Storage account containing the container with activity logs must be encrypted with BYOK

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

This policy audits if the Storage account containing the container with activity logs is encrypted with BYOK. The policy works only if the storage account lies on the same subscription as activity logs by design. More information on Azure Storage encryption at rest can be found here https://aka.ms/azurestoragebyok.

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

Azure Policy JSONActivityLog_StorageAccountBYOK_Audit.json · 69 lines
{
  "properties": {
    "displayName": "Storage account containing the container with activity logs must be encrypted with BYOK",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "This policy audits if the Storage account containing the container with activity logs is encrypted with BYOK. The policy works only if the storage account lies on the same subscription as activity logs by design. More information on Azure Storage encryption at rest can be found here https://aka.ms/azurestoragebyok. ",
    "metadata": {
      "version": "1.0.0",
      "category": "Monitoring"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Insights/logProfiles"
          },
          {
            "field": "Microsoft.Insights/logProfiles/storageAccountId",
            "exists": "true"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Storage/storageAccounts",
          "existenceScope": "subscription",
          "existenceCondition": {
            "allOf": [
              {
                "value": "[contains(field('Microsoft.Insights/logProfiles/storageAccountId'), subscription().Id)]",
                "equals": "true"
              },
              {
                "field": "name",
                "equals": "[last(split(field('Microsoft.Insights/logProfiles/storageAccountId'),'/'))]"
              },
              {
                "field": "Microsoft.Storage/storageAccounts/encryption.keySource",
                "equals": "Microsoft.Keyvault"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/fbb99e8e-e444-4da0-9ff1-75c92f5a85b2",
  "name": "fbb99e8e-e444-4da0-9ff1-75c92f5a85b2"
}
Bylawfbb99e8e-e444-4da0-9ff1-75c92f5a85b2.bylaw.ps1 · 35 lines
# Converted from ActivityLog_StorageAccountBYOK_Audit.json by ConvertTo-Bylaw.
Policy 'fbb99e8e-e444-4da0-9ff1-75c92f5a85b2' {

    Properties @{
        DisplayName   = 'Storage account containing the container with activity logs must be encrypted with BYOK'
        Description   = 'This policy audits if the Storage account containing the container with activity logs is encrypted with BYOK. The policy works only if the storage account lies on the same subscription as activity logs by design. More information on Azure Storage encryption at rest can be found here https://aka.ms/azurestoragebyok. '
        Version       = '1.0.0'
        Category      = 'Monitoring'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Insights/logProfiles' {

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

    AuditIfNotExists 'Microsoft.Storage/storageAccounts' -ExistenceScope Subscription -Effect (Param Effect) {
        Require 'name, encryption.keySource and storageAccountId are as required' {
            Arm '[contains(field(''Microsoft.Insights/logProfiles/storageAccountId''), subscription().Id)]' | Must -Be 'true'
            Field name | Must -Be (Arm '[last(split(field(''Microsoft.Insights/logProfiles/storageAccountId''),''/''))]')
            Field encryption.keySource | Must -Be 'Microsoft.Keyvault'
        }
    }
}

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