---
inputType: "CA10__CaAzureNetworkSecurityGroup__c"
testData:
  - file: "test-data.json"
conditions:
  - status: "INCOMPLIANT"
    currentStateMessage: "Network Security Group has a rule that allows UDP access from the Internet."
    remediationMessage: "Consider restricting internet-level access to your Azure resources."
    check:
      RELATED_LIST_HAS:
        relationshipName: "CA10__Azure_Network_Security_Group_Rules__r"
        status: "INCOMPLIANT"
otherwise:
  status: "COMPLIANT"
  currentStateMessage: "Network Security Group does not allow unrestricted UDP access from the internet."
relatedLists:
  - relationshipName: "CA10__Azure_Network_Security_Group_Rules__r"
    importExtracts:
      - file: "/types/CA10__CaAzureNetworkSecurityGroupRule__c/object.extracts.yaml"
    conditions:
      - status: "INAPPLICABLE"
        currentStateMessage: "NSG Deny Rule."
        check:
          NOT_EQUAL:
            left:
              EXTRACT: "CA10__access__c"
            right:
              TEXT: "Allow"
      - status: "INAPPLICABLE"
        currentStateMessage: "NSG Outbound Rule."
        check:
          NOT_EQUAL:
            left:
              EXTRACT: "CA10__direction__c"
            right:
              TEXT: "Inbound"
      - status: "INAPPLICABLE"
        currentStateMessage: "NSG Rule with the port other than UDP."
        check:
          NOT_EQUAL:
            left:
              EXTRACT: "CA10__protocol__c"
            right:
              TEXT: "UDP"
      - status: "INCOMPLIANT"
        currentStateMessage: "NSG Rule with UDP access from the Internet."
        remediationMessage: "Consider restricting internet-level access to your Azure resources."
        check:
          OR:
            args:
              - IS_EQUAL:
                  left:
                    EXTRACT: "CA10__sourceAddressPrefix__c"
                  right:
                    TEXT: "Internet"
              - IS_EQUAL:
                  left:
                    EXTRACT: "CA10__sourceAddressPrefix__c"
                  right:
                    TEXT: "*"
              - IS_EQUAL:
                  left:
                    EXTRACT: "CA10__sourceAddressPrefix__c"
                  right:
                    TEXT: "0.0.0.0"
              - CONTAINS:
                  arg:
                    EXTRACT: "CA10__sourceAddressPrefix__c"
                  substring:
                    TEXT: "/0"
              - IS_EQUAL:
                  left:
                    EXTRACT: "CA10__sourceAddressPrefix__c"
                  right:
                    TEXT: "Any"
    otherwise: 
      status: "INAPPLICABLE"
      currentStateMessage: "Unrelated rule."
