id: azure-storage-blob-public-access
info:
  name: Azure Storage Blob Public Access Not 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 public access is not disabled, blob containers can be accessed by anyone, potentially exposing sensitive data to unauthorized users.
  remediation: |
    Disable public access to all storage accounts containing blob containers to prevent unauthorized data access.
  reference:
    - https://docs.microsoft.com/en-us/azure/storage/common/storage-disallow-access
  tags: cloud,devops,azure,microsoft,storage,azure-cloud-config

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

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

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

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

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

    extractors:
      - type: dsl
        dsl:
          - 'ids + " has public access enabled"'
# digest: 4b0a00483046022100f755c16fc63db658362f5f67dfe2c2033a4272b416639726c548fc8895f49c1d022100e57e148fcab6a467515f5983dfe1ddf7f1ba8c73d72f9835c13befe146fffb85:922c64590222798bb761d5b6d8e72950