Bylaw

Gallery › Storage › Azure Community Policy

Audit storage accounts with unrestricted network access

Converted Policy Audit Deny Disabled Mode All Version 2.0.0

Audit storage accounts with unrestricted network access

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

Azure Policy JSONazurepolicy.json · 53 lines
{
  "name": "b8a4dbe8-609e-4e44-9a30-b8d383b71226",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit storage accounts with unrestricted network access",
    "description": "Audit storage accounts with unrestricted network access",
    "metadata": {
      "category": "Storage",
      "version": "2.0.0"
    },
    "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.defaultAction",
                "exists": "false"
              },
              {
                "field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
                "equals": "Allow"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawb8a4dbe8-609e-4e44-9a30-b8d383b71226.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'b8a4dbe8-609e-4e44-9a30-b8d383b71226' {

    Properties @{
        DisplayName = 'Audit storage accounts with unrestricted network access'
        Description = 'Audit storage accounts with unrestricted network access'
        Category    = 'Storage'
        Version     = '2.0.0'
        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.defaultAction exists' {
            Field networkAcls.defaultAction | Must -Exist
        }

        Require 'networkAcls.defaultAction is not Allow' {
            Field networkAcls.defaultAction | Must -Not -Be 'Allow' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Storage/audit-storage-accounts-with-unrestricted-network-access/azurepolicy.json in Azure/Community-Policy, under the MIT licence.