id: azure-storage-account-delete-unalerted
info:
  name: Azure Storage Account Delete Alert Not Configured
  author: princechaddha
  severity: high
  description: |
    Ensure that a Microsoft Azure activity log alert is fired whenever a "Delete Storage Account" event is triggered within your cloud account. An Azure activity log alert fires each time the event that matches the condition specified in the alert configuration is triggered. The alert condition that this conformity rule checks for is "Whenever the Administrative Activity Log 'Delete Storage Account (Microsoft.Storage/storageAccounts)' has 'any' Event level, with 'any' status and event is initiated by 'any'".
  impact: |
    Failure to have alert rules for the deletion of storage accounts can allow malicious or accidental deletions to go unnoticed, potentially leading to data loss and security breaches.
  remediation: |
    Ensure alert rules are configured to fire on "Delete Storage Account" events by setting the alert condition to "Microsoft.Storage/storageAccounts/delete" and ensuring that an action group is attached to manage notifications.
  reference:
    - https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-activity-log
  tags: cloud,devops,azure,microsoft,storage-account,azure-cloud-config

flow: |
  code(1);
  for (let AlertData of iterate(template.alertList)) {
    set("id", AlertData);
    code(2);
  }

self-contained: true
code:
  - engine:
      - sh
      - bash
    source: |
      az monitor activity-log alert list --output json --query '[?(enabled==`true`)].id'

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

  - engine:
      - sh
      - bash
    source: |
      az monitor activity-log alert show --ids "$id" --query 'condition'

    matchers-condition: and
    matchers:
      - type: word
        words:
          - '"field": "operationName"'

      - type: word
        words:
          - "Microsoft.Storage/storageAccounts/delete"
        negative: true

    extractors:
      - type: dsl
        dsl:
          - 'id + " does not have the correct alert configuration for Delete Storage Account events"'
# digest: 490a0046304402204edac876188f737e4e055235f08d97d514d111d88dd3d6204ba4c68196c56f3f022074b54a5ab0b3c8fbf57ecdc96d8863a6bf35f3e35c38393465c863bec482b542:922c64590222798bb761d5b6d8e72950