---
policy: /ce/ca/google/vpc/network-dns-policy-logging
logic: /ce/ca/google/vpc/network-dns-policy-logging/prod.logic.yaml
executionTime: 2025-04-24T23:47:39.373936578Z
rows:
  - id: a4bDo0
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: a4b4P01
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: isEmptyLookup('CA10__dnsPolicy__r')
      actual: isEmptyLookup('CA10__dnsPolicy__r')
    runtimeError: {}
  - id: a4bDo33
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__dnsPolicy__r.CA10__loggingStatus__c') != 'Enable'
      actual: extract('CA10__dnsPolicy__r.CA10__loggingStatus__c') != 'Enable'
    runtimeError: {}
  - id: a4b4P044
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/vpc/network-dns-policy-logging/policy.yaml
    md5Hash: 36C1D986E32AFAB98A526D324C093264
    content: "---\nnames: \n  full: \"Google GCE Network DNS Policy Logging is not\
      \ enabled\"\n  contextual: \"GCE Network DNS Policy Logging is not enabled\"\
      \ndescription: \"Cloud DNS logging records the queries from the name servers\
      \ within your VPC to Stackdriver. \\\n  Logged queries can come from Compute\
      \ Engine VMs, GKE containers, or other GCP resources provisioned \\ \n  within\
      \ the VPC. \"\ntype: COMPLIANCE_POLICY\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - /frameworks/cis-gcp-v3.0.0/02/12\n  - /frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/gcp/CloudVPC/dns-logging-for-vpcs.html\"\
      \n      name: \"Enable Cloud DNS Logging for VPC Networks\"\n"
  - path: /ce/ca/google/vpc/network-dns-policy-logging/prod.logic.yaml
    md5Hash: 39EB161AF1830FE9F5424510CA5E09FE
    content: "---\n\ninputType: \"CA10__CaGoogleGceNetwork__c\"\ntestData:\n  - file:\
      \ test-data.json\nimportExtracts:\n  - file: /types/CA10__CaGoogleGceNetwork__c/object.extracts.yaml\n\
      \  - file: /types/CA10__CaGoogleCloudDnsPolicy__c/object.extracts.yaml\nconditions:\
      \ \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"There is no DNS\
      \ policy associated with the network.\"\n    remediationMessage: \"Associate\
      \ the policy to the network.\"\n    check:\n      IS_EMPTY_LOOKUP: \"CA10__dnsPolicy__r\"\
      \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"Logging for existing\
      \ DNS Policy not enabled.\"\n    remediationMessage: \"Enable Logging for existing\
      \ DNS Policy.\"\n    check:\n      NOT_EQUAL:\n        left:\n          EXTRACT:\
      \ \"CA10__dnsPolicy__r.CA10__loggingStatus__c\"\n        right:\n          TEXT:\
      \ \"Enable\"\notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"\
      Cloud DNS Logging is enabled for all VPC Networks.\""
  - path: /ce/ca/google/vpc/network-dns-policy-logging/test-data.json
    md5Hash: A1BEAC97E9CC8EDFD3A6A0D7265341FF
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T20:26:32Z" },
          "Id": "a4bDo0",
          "CA10__disappearanceTime__c": "2023-12-22T12:09:30Z",
          "CA10__dnsPolicy__c": "",
          "CA10__dnsPolicyName__c": "",
          "CA10__dnsPolicy__r": {
            "Id": null,
            "CA10__disappearanceTime__c": null,
            "CA10__loggingStatus__c": null
          }
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "isEmptyLookup('CA10__dnsPolicy__r')",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T20:26:32Z" },
          "Id": "a4b4P01",
          "CA10__disappearanceTime__c": null,
          "CA10__dnsPolicy__c": "",
          "CA10__dnsPolicyName__c": "",
          "CA10__dnsPolicy__r": {
            "Id": null,
            "CA10__disappearanceTime__c": null,
            "CA10__loggingStatus__c": null
          }
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__dnsPolicy__r.CA10__loggingStatus__c') != 'Enable'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T20:26:32Z" },
          "Id": "a4bDo33",
          "CA10__disappearanceTime__c": null,
          "CA10__dnsPolicy__c": "aNODo011",
          "CA10__dnsPolicyName__c": "hellowworld",
          "CA10__dnsPolicy__r": {
            "Id": "aNODo011",
            "CA10__disappearanceTime__c": null,
            "CA10__loggingStatus__c": "Disable"
          }
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T20:26:32Z" },
          "Id": "a4b4P044",
          "CA10__disappearanceTime__c": null,
          "CA10__dnsPolicy__c": "aNO4P022",
          "CA10__dnsPolicyName__c": "dns-policy",
          "CA10__dnsPolicy__r": {
            "Id": "aNO4P022",
            "CA10__disappearanceTime__c": null,
            "CA10__loggingStatus__c": "Enable"
          }
        }
      ]
  - path: /types/CA10__CaGoogleGceNetwork__c/object.extracts.yaml
    md5Hash: 8F9138803D14A08C803D065164BFC0CC
    content: "---\nextracts:\n  - name: \"networkName\"\n    value: \n      FIELD:\n\
      \        path: \"Name\"\n        undeterminedIf:\n          isEmpty:  \"Name\
      \ should not be empty\"\n  - name: \"CA10__autoCreationSubnetworksMode__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__autoCreationSubnetworksMode__c\"\
      \n        undeterminedIf:\n          isEmpty:  \"Auto creation subnetworks mode\
      \ should not be empty\""
  - path: /types/CA10__CaGoogleCloudDnsPolicy__c/object.extracts.yaml
    md5Hash: CE8BEE5BA0362FB893E9DE846C2B2392
    content: "---\nextracts:\n  - name: \"CA10__loggingStatus__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__loggingStatus__c\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "a4bDo0",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4b4P01",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "isEmptyLookup('CA10__dnsPolicy__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4bDo33",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__dnsPolicy__r.CA10__loggingStatus__c') != 'Enable'",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4b4P044",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceNetwork__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__dnsPolicy__c STRING,
      CA10__dnsPolicyName__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T20:26:32Z")
    },
    "Id" : "a4bDo0",
    "CA10__disappearanceTime__c" : new Date("2023-12-22T12:09:30Z"),
    "CA10__dnsPolicy__c" : "",
    "CA10__dnsPolicyName__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T20:26:32Z")
    },
    "Id" : "a4b4P01",
    "CA10__dnsPolicy__c" : "",
    "CA10__dnsPolicyName__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T20:26:32Z")
    },
    "Id" : "a4bDo33",
    "CA10__dnsPolicy__c" : "aNODo011",
    "CA10__dnsPolicyName__c" : "hellowworld"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T20:26:32Z")
    },
    "Id" : "a4b4P044",
    "CA10__dnsPolicy__c" : "aNO4P022",
    "CA10__dnsPolicyName__c" : "dns-policy"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleCloudDnsPolicy__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__loggingStatus__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T20:26:32Z")
    },
    "Id" : null,
    "CA10__loggingStatus__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T20:26:32Z")
    },
    "Id" : "aNODo011",
    "CA10__loggingStatus__c" : "Disable"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T20:26:32Z")
    },
    "Id" : "aNO4P022",
    "CA10__loggingStatus__c" : "Enable"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceNetwork__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__dnsPolicy__c STRING,
          CA10__dnsPolicyName__c STRING,
          CA10__dnsPolicy__r STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__loggingStatus__c STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var TextLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
          };
          this.isEmpty = function(arg) {
              return this.normalize(arg) == '';
          };
          this.isNotEmpty = function(arg) {
              return this.normalize(arg) != '';
          };
          this.equal = function(left, right) {
              return this.normalize(left) == this.normalize(right);
          };
          this.notEqual = function(left, right) {
              return this.normalize(left) != this.normalize(right);
          };
          this.startsWith = function(arg, substring) {
              return this.normalize(arg).startsWith(this.normalize(substring));
          };
          this.endsWith = function(arg, substring) {
              return this.normalize(arg).endsWith(this.normalize(substring));
          };
          this.contains = function(arg, substring) {
              return this.normalize(arg).includes(this.normalize(substring));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      if (TextLib.isEmpty(obj.CA10__dnsPolicyName__c) || TextLib.isEmpty(obj.CA10__dnsPolicy__c) || obj.CA10__dnsPolicy__r.CA10__disappearanceTime__c != null) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "isEmptyLookup('CA10__dnsPolicy__r')", currentStateMessage: "There is no DNS policy associated with the network.", currentStateReferences: references1.join('\n'), remediation: "Associate the policy to the network.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extractChecked2() {
          if (TextLib.isEmpty(obj.CA10__dnsPolicyName__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "extractCheck(obj.CA10__dnsPolicyName__c)", currentStateMessage: "Related object via CA10__dnsPolicyName__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__dnsPolicy__c)) {
              throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "extractCheck(obj.CA10__dnsPolicy__c)", currentStateMessage: "Related object via CA10__dnsPolicy__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10__dnsPolicy__r.CA10__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extractCheck(obj.CA10__dnsPolicy__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__dnsPolicy__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract3.call(extract3);
      }
      function extract3() { if (!this.out) { this.out = obj.CA10__dnsPolicy__r.CA10__loggingStatus__c; } return this.out; };
      references1.push('Logging Status [obj.CA10__dnsPolicy__r.CA10__loggingStatus__c]: ' + obj.CA10__dnsPolicy__r.CA10__loggingStatus__c);
      try {
          if (TextLib.notEqual(extractChecked2(), 'Enable')) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__dnsPolicy__r.CA10__loggingStatus__c') != 'Enable'", currentStateMessage: "Logging for existing DNS Policy not enabled.", currentStateReferences: references1.join('\n'), remediation: "Enable Logging for existing DNS Policy.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Cloud DNS Logging is enabled for all VPC Networks.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__dnsPolicy__c AS CA10__dnsPolicy__c,
          sObject.CA10__dnsPolicyName__c AS CA10__dnsPolicyName__c,
          STRUCT (
              `CA10__dnsPolicy__r`.Id AS Id,
              `CA10__dnsPolicy__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
              `CA10__dnsPolicy__r`.CA10__loggingStatus__c AS CA10__loggingStatus__c
          ) AS CA10__dnsPolicy__r,
          process_CA10__CaGoogleGceNetwork__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__dnsPolicy__c AS CA10__dnsPolicy__c,
                  sObject.CA10__dnsPolicyName__c AS CA10__dnsPolicyName__c,
                  STRUCT (
                      `CA10__dnsPolicy__r`.Id AS Id,
                      `CA10__dnsPolicy__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      `CA10__dnsPolicy__r`.CA10__loggingStatus__c AS CA10__loggingStatus__c
                  ) AS CA10__dnsPolicy__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceNetwork__c()) AS sObject
      LEFT JOIN UNNEST(mock_CA10__CaGoogleCloudDnsPolicy__c()) AS `CA10__dnsPolicy__r`
          ON sObject.CA10__dnsPolicy__c = `CA10__dnsPolicy__r`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
