id: azure-openai-public-access-disabled
info:
  name: Azure OpenAI Public Network Access Not Disabled
  author: princechaddha
  severity: high
  description: |
    Ensure that public network access (i.e. all network access) to Microsoft Azure OpenAI service instances is disabled in order to enhance security by preventing unauthorized access.
  impact: |
    Enabling public network access to Azure OpenAI service instances can lead to unauthorized access, compromising the security and integrity of the instances.
  remediation: |
    Configure the Azure OpenAI service instances to disable public network access to secure them against unauthorized external access.
  reference:
    - https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account-cli?tabs=windows
  tags: cloud,devops,azure,microsoft,openai,azure-cloud-config,ai

flow: |
  code(1);
  for (let ServiceData of iterate(template.serviceList)) {
    ServiceData = JSON.parse(ServiceData);
    set("name", ServiceData.name);
    set("resourceGroup", ServiceData.resourceGroup);
    code(2);
  }

self-contained: true
code:
  - engine:
      - sh
      - bash
    source: |
      az cognitiveservices account list --output json --query '[?(kind==`OpenAI`)].{"name":name,"resourceGroup":resourceGroup}'

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

  - engine:
      - sh
      - bash
    source: |
      az cognitiveservices account show --name "$name" --resource-group "$resourceGroup" --query '{networkAcls:properties.networkAcls.defaultAction,publicNetworkAccess:properties.publicNetworkAccess}'

    matchers-condition: and
    matchers:
      - type: word
        words:
          - '"networkAcls": "Allow"'
          - '"networkAcls": "null"'

      - type: word
        words:
          - '"publicNetworkAccess": "Enabled"'

    extractors:
      - type: dsl
        dsl:
          - '"$name in $resourceGroup has public network access enabled"'
# digest: 4b0a00483046022100e7b40c386f3b996967bba58bdfcdd5364875f896a5b894e960b2a9d9041b5228022100b894c1d029450025de524a5dbaab8ead72723d06402973a454fe7ba8da39a1b9:922c64590222798bb761d5b6d8e72950