Bylaw

Gallery › Storage › Azure built-in policies

Storage accounts should prevent shared key access (excluding storage accounts created by Databricks)

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Audit requirement of Azure Active Directory (Azure AD) to authorize requests for your storage account. By default, requests can be authorized with either Azure Active Directory credentials, or by using the account access key for Shared Key authorization. Of these two types of authorization, Azure AD provides superior security and ease of use over Shared Key, and is recommended by Microsoft.

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

Azure Policy JSONStorageAccountAllowSharedKeyAccessWithDatabricksExcluded_Audit.json · 70 lines
{
  "properties": {
    "displayName": "Storage accounts should prevent shared key access (excluding storage accounts created by Databricks)",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Audit requirement of Azure Active Directory (Azure AD) to authorize requests for your storage account. By default, requests can be authorized with either Azure Active Directory credentials, or by using the account access key for Shared Key authorization. Of these two types of authorization, Azure AD provides superior security and ease of use over Shared Key, and is recommended by Microsoft.",
    "metadata": {
      "version": "1.0.0",
      "category": "Storage"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "value": "[resourcegroup().managedBy]",
            "notContains": "/providers/Microsoft.Databricks/"
          },
          {
            "anyOf": [
              {
                "anyOf": [
                  {
                    "field": "Microsoft.Storage/storageAccounts/allowSharedKeyAccess",
                    "exists": "false"
                  },
                  {
                    "field": "Microsoft.Storage/storageAccounts/allowSharedKeyAccess",
                    "equals": ""
                  }
                ]
              },
              {
                "field": "Microsoft.Storage/storageAccounts/allowSharedKeyAccess",
                "equals": "true"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/fd9903f1-38c2-4d36-8e44-5c1c20c561e8",
  "name": "fd9903f1-38c2-4d36-8e44-5c1c20c561e8"
}
Bylawfd9903f1-38c2-4d36-8e44-5c1c20c561e8.bylaw.ps1 · 37 lines
# Converted from StorageAccountAllowSharedKeyAccessWithDatabricksExcluded_Audit.json by ConvertTo-Bylaw.
Policy 'fd9903f1-38c2-4d36-8e44-5c1c20c561e8' {

    Properties @{
        DisplayName   = 'Storage accounts should prevent shared key access (excluding storage accounts created by Databricks)'
        Description   = 'Audit requirement of Azure Active Directory (Azure AD) to authorize requests for your storage account. By default, requests can be authorized with either Azure Active Directory credentials, or by using the account access key for Shared Key authorization. Of these two types of authorization, Azure AD provides superior security and ease of use over Shared Key, and is recommended by Microsoft.'
        Version       = '1.0.0'
        Category      = 'Storage'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match'
    }

    Resource 'Microsoft.Storage/storageAccounts' {

        When {
            Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.Databricks/'
        }

        Require 'allowSharedKeyAccess is not' {
            Field allowSharedKeyAccess | Must -Not -Be ''
        }

        Require 'allowSharedKeyAccess is not true' {
            Field allowSharedKeyAccess | Must -Not -Be 'true' -IfPresent
        }
    }

    Effect (Param Effect)
}

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