id: azure-public-ip-update-unalerted
info:
  name: Azure Public IP Create/Update Alert Not Configured
  author: princechaddha
  severity: high
  description: |
    Ensure that activity log alerts are used to detect "Create or Update Public IP Address" events within your Microsoft Azure cloud account. An activity log alert gets activated when a new activity log event that matches the condition specified in the alert occurs.
  impact: |
    Without proper alert rules configured for monitoring "Create or Update Public IP Address" events, unauthorized or unwanted changes might go unnoticed, leading to potential security risks.
  remediation: |
    Ensure alert rules are properly configured to monitor and notify on "Create or Update Public IP Address" events by setting the alert condition to "Microsoft.Network/publicIPAddresses/write" 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,public-ip,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"

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

      - type: word
        words:
          - "Microsoft.Network/publicIPAddresses/write"
        negative: true

    extractors:
      - type: dsl
        dsl:
          - 'id + " does not have the correct alert configuration for Create/Update Public IP Address events"'
# digest: 4a0a00473045022100fe5a63546e63ed5b5f65ed6a253017b0a16a5c5f8a57d0b5087d291aa46360a8022047d918e49bec204816e763da7e3eb182d10df6ee97ca3ae7190f333d419cdf5b:922c64590222798bb761d5b6d8e72950