---
policy: /ce/ca/google/vpc/firewall-rule-logging
logic: /ce/ca/google/vpc/firewall-rule-logging/prod.logic.yaml
executionTime: 2025-10-25T12:02:55.977530061Z
generationMs: 54
executionMs: 529
rows:
  - id: '001'
    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: '002'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__logState__c') == 'Enabled'
      actual: extract('CA10__logState__c') == 'Enabled'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/vpc/firewall-rule-logging/policy.yaml
    md5Hash: 2E04062332445D25B19FD775E8AA96AA
    content: "---\nnames: \n  full: \"Google GCE Firewall Rule logging is disabled\"\
      \n  contextual: \"GCE Firewall Rule logging is disabled\"\ndescription: \"Ensure\
      \ that Firewall Rules Logging is enabled for all GCE firewall\\\n  \\ rules.\
      \ This feature records network connections that match a firewall rule,\\\n \
      \ \\ providing crucial data for security auditing, incident response, and network\
      \ troubleshooting.\"\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\
      \nframeworkMappings:\n  - \"/frameworks/nist-sp-800-53-r4/si/04\"\n  - \"/frameworks/pci-dss-v3.2.1/10/01\"\
      \n  - \"/frameworks/pci-dss-v3.2.1/10/02\"\n  - \"/frameworks/iso-iec-27001-2013/13/01/01\"\
      \n  - \"/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\"\
      \n"
  - path: /ce/ca/google/vpc/firewall-rule-logging/prod.logic.yaml
    md5Hash: D7ECCB9B0B3E54A2A38E1E8CA0627F44
    content: |
      ---

      inputType: "CA10__CaGoogleGceFirewallRule__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaGoogleGceFirewallRule__c/object.extracts.yaml"
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "Firewall Rule logging is enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__logState__c"
              right:
                TEXT: "Enabled"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "Firewall Rule logging is disabled."
        remediationMessage: "Enable logging for the Firewall Rule."
  - path: /ce/ca/google/vpc/firewall-rule-logging/test-data.json
    md5Hash: FC83FA6AB305088D208A3F796BB798DC
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-15T00:50:50Z" },
          "Id": "001",
          "CA10__disappearanceTime__c": "2025-06-12T11:30:05Z",
          "CA10__logState__c": "Disabled"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__logState__c') == 'Enabled'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-15T00:50:50Z" },
          "Id": "002",
          "CA10__disappearanceTime__c": null,
          "CA10__logState__c": "Enabled"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-15T00:50:50Z" },
          "Id": "003",
          "CA10__disappearanceTime__c": null,
          "CA10__logState__c": "Disabled"
        }
      ]
  - path: /types/CA10__CaGoogleGceFirewallRule__c/object.extracts.yaml
    md5Hash: AE08F20196B487A130FB166DA77692D3
    content: "---\nextracts:\n  - name: \"CA10__direction__c\"\n    value: \n    \
      \  FIELD:\n        path: \"CA10__direction__c\"\n        undeterminedIf:\n \
      \        isEmpty: \"Direction is not populated yet.\"\n  - name: \"CA10__sourceRanges__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__sourceRanges__c\"\n     \
      \   undeterminedIf:\n          isEmpty: \"Source ranges are not populated yet.\"\
      \n  - name: \"CA10__allowedProtocolsPorts__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__allowedProtocolsPorts__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Allowed protocol ports are not populated yet.\"\n# 22\
      \ port variants: tcp: 22 / tcp: 22, 80 / tcp: 1-65535\n  - name: \"caJsonFrom__allowedProtocolsPortsJson__c\"\
      \n    value:\n      JSON_FROM:\n        arg:\n          FIELD: \n          \
      \  path: \"CA10__allowedProtocolsPortsJson__c\"\n            returnType: BYTES\n\
      \        undeterminedIf:\n          isInvalid: \"Allowed protocol ports JSON\
      \ is invalid.\"\n          isEmpty: \"Allowed protocol ports JSON is empty.\"\
      \n  - name: \"caJsonFrom__deniedProtocolsPortsJson__c\"\n    value:\n      JSON_FROM:\n\
      \        arg:\n          FIELD: \n            path: \"CA10__deniedProtocolsPortsJson__c\"\
      \n            returnType: BYTES\n        undeterminedIf:\n          isInvalid:\
      \ \"Denied protocol ports JSON is invalid.\"\n          isEmpty: \"Denied protocol\
      \ ports JSON is empty.\"\n  - name: \"CA10__destinationRanges__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__destinationRanges__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Destination ranges are not populated yet.\"\n  - name:\
      \ \"CA10__logState__c\"\n    value: \n      FIELD:\n        path: \"CA10__logState__c\"\
      \n        undeterminedIf:\n         isEmpty: \"Logging status undetermined.\"\
      \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" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__logState__c') == 'Enabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceFirewallRule__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__logState__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-15T00:50:50Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-06-12T11:30:05Z"),
    "CA10__logState__c" : "Disabled",
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-15T00:50:50Z")
    },
    "CA10__logState__c" : "Enabled",
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-15T00:50:50Z")
    },
    "CA10__logState__c" : "Disabled",
    "Id" : "003"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceFirewallRule__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__logState__c STRING,
          Id 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));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      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]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__logState__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__logState__c.isEmpty()", currentStateMessage: "Logging status undetermined.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__logState__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Log State [obj.CA10__logState__c]: ' + obj.CA10__logState__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'Enabled')) {
              return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__logState__c') == 'Enabled'", currentStateMessage: "Firewall Rule logging is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Firewall Rule logging is disabled.", currentStateReferences: references1.join('\n'), remediation: "Enable logging for the Firewall Rule.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__logState__c AS CA10__logState__c,
          sObject.Id AS Id,
          process_CA10__CaGoogleGceFirewallRule__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__logState__c AS CA10__logState__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceFirewallRule__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
