Azure Policy for BlobServices

Serhii Polhorodnyk 20 Reputation points
2024-03-15T12:26:44.2733333+00:00

Hi, community!

I'm using this policy in order to audit blob versioning:

{
  "properties": {
    "displayName": "Custom: Configure your Storage account to enable blob versioning",
    "policyType": "Custom",
    "mode": "Indexed",
    "description": "You can enable Blob storage versioning to automatically maintain previous versions of an object. When blob versioning is enabled, you can access earlier versions of a blob to recover your data if it's modified or deleted.",
    "metadata": {
      "version": "1.0.0",
      "category": "Storage"
    },
    "version": "1.0.0",
    "parameters": {},
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts/blobServices"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "value": "[requestContext().apiVersion]",
                    "less": "2019-10-10"
                  },
                  {
                    "field": "Microsoft.Storage/storageAccounts/blobServices/isVersioningEnabled",
                    "exists": "true"
                  }
                ]
              },
              {
                "field": "Microsoft.Storage/storageAccounts/blobServices/isVersioningEnabled",
                "equals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "${effect}"
      }
    }
  },
  "versions": [
    "1.0.0"
  ]
}

But in Azure Portal Policy Compliance I do not see any compliant/non-compliant resources.
I tried to use Microsoft.Storage/storageAccounts type - throws error about type mismatch.

Other policies that are related to Microsoft.Storage/storageAccounts type - showing all storage accounts and compliant/non-compliant ones, but Microsoft.Storage/storageAccounts/blobServices - not. Is it a feature or a bug? And how I can see whicg storage accounts have VersioningEnabled?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,428 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
793 questions
0 comments No comments
{count} votes

Accepted answer
  1. Stanislav Zhelyazkov 21,181 Reputation points MVP
    2024-03-15T13:40:48.6866667+00:00

    Try changing mode to All instead of Indexed. Also increase the API version. This one is not found on the docs.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful