id: azure-blob-anonymous-access-disabled
info:
  name: Azure Blob Anonymous Access Disabled
  author: princechaddha
  severity: medium
  description: |
    Ensure that public (anonymous) access is disabled for all the blob containers available within your Microsoft Azure storage accounts in order to protect your data against unauthorized access. Disabling public access at the storage account level overrides the public access setting configured for the individual blob containers in that storage account.
  impact: |
    If the storage account show command output returns true, the container and blob data can be read by anonymous users, therefore, the public access to the blob containers in the selected Azure storage account is not disabled.
  remediation: |
    Disable public (anonymous) access to all blob containers in Azure storage accounts to protect your data against unauthorized access.
  reference:
    - https://docs.microsoft.com/en-us/azure/storage/blobs/anonymous-read-access-prevent
  tags: cloud,devops,azure,microsoft,azure-storage,azure-cloud-config

flow: |
  code(1);
  for (let StorageAccount of iterate(template.storageAccountIds)) {
    set("ids", StorageAccount);
    code(2);
  }

self-contained: true
code:
  - engine:
      - sh
      - bash
    source: |
      az storage account list --query '[*].id'

    extractors:
      - type: json
        name: storageAccountIds
        internal: true
        json:
          - '.[]'

  - engine:
      - sh
      - bash
    source: |
      az storage account show --ids "$ids" --query allowBlobPublicAccess

    matchers-condition: and
    matchers:
      - type: word
        words:
          - 'true'

    extractors:
      - type: dsl
        dsl:
          - 'ids + " is not disabling anonymous blob access"'
# digest: 4a0a004730450220568a8b05de8baf2554dd90fd84e356675359e794782f456e6f58ad4b5801af02022100a2f52ca38bc9f1a0cca7c7f5ca1cebfa18b63a5123d15eed4d5c19f75597b561:922c64590222798bb761d5b6d8e72950