Bylaw

Gallery › Storage › Azure Community Policy

Storage Account - Read Access Logs and Metrics DENY

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This Azure Policy denies the deployment of an Azure Storage Account when the 'Allow read access to storage logging from any network' and 'Allow read access to storage metrics from any network' settings are 'Enabled'.

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

Azure Policy JSONazurepolicy.json · 53 lines
{
  "name": "4aba4c7a-7bd7-4728-92a8-b24aa3f252c0",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Storage Account - Read Access Logs and Metrics DENY",
    "description": "This Azure Policy denies the deployment of an Azure Storage Account when the 'Allow read access to storage logging from any network' and 'Allow read access to storage metrics from any network' settings are 'Enabled'.",
    "metadata": {
      "version": "1.0.0",
      "category": "Storage"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Storage/storageAccounts/networkAcls.bypass",
                "contains": "Logging"
              },
              {
                "field": "Microsoft.Storage/storageAccounts/networkAcls.bypass",
                "contains": "Metrics"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw4aba4c7a-7bd7-4728-92a8-b24aa3f252c0.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '4aba4c7a-7bd7-4728-92a8-b24aa3f252c0' {

    Properties @{
        DisplayName = 'Storage Account - Read Access Logs and Metrics DENY'
        Description = 'This Azure Policy denies the deployment of an Azure Storage Account when the ''Allow read access to storage logging from any network'' and ''Allow read access to storage metrics from any network'' settings are ''Enabled''.'
        Version     = '1.0.0'
        Category    = 'Storage'
        Mode        = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Storage/storageAccounts' {

        Require 'networkAcls.bypass does not contain Logging' {
            Field networkAcls.bypass | Must -Not -ContainText 'Logging' -IfPresent
        }

        Require 'networkAcls.bypass does not contain Metrics' {
            Field networkAcls.bypass | Must -Not -ContainText 'Metrics' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Storage/storage-account-read-access-logs-and-metrics-deny/azurepolicy.json in Azure/Community-Policy, under the MIT licence.