---
policy: /ce/ca/google/compute-engine/disable-instance-ip-forwarding
logic: /ce/ca/google/compute-engine/disable-instance-ip-forwarding/prod.logic.yaml
executionTime: 2025-04-24T23:46:49.488016737Z
rows:
  - id: a4Z1
    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: a4Z2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('Name').startsWith('gke-')
      actual: extract('Name').startsWith('gke-')
    runtimeError: {}
  - id: a4Z3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__ipForwarding__c') == true
      actual: extract('CA10__ipForwarding__c') == true
    runtimeError: {}
  - id: a44
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/compute-engine/disable-instance-ip-forwarding/policy.yaml
    md5Hash: 0E772F543A90FCAAFF9CC47D66567ABB
    content: "---\nnames: \n  full: \"Google GCE Instance IP Forwarding is not disabled.\"\
      \n  contextual: \"Instance IP Forwarding is not disabled.\"\ndescription: \"\
      Compute Engine instance cannot forward a packet unless the source IP address\
      \ of the \\ \n packet matches the IP address of the instance. Similarly, GCP\
      \ won't deliver a packet whose \\ \n destination IP address is different than\
      \ the IP address of the instance receiving the packet. \\ \n However, both capabilities\
      \ are required if you want to use instances to help route packets. \\\n Forwarding\
      \ of data packets should be disabled to prevent data loss or information disclosure.\"\
      \ntype: COMPLIANCE_POLICY\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - /frameworks/cis-gcp-v3.0.0/04/06\n  - /frameworks/cloudaware/resource-security/secure-access\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/ComputeEngine/disable-ip-forwarding.html\"\
      \n      name: \"Disable IP Forwarding for Virtual Machine Instances\"\n"
  - path: /ce/ca/google/compute-engine/disable-instance-ip-forwarding/prod.logic.yaml
    md5Hash: DA179E7CE6AF6E584E9CF0F8FFF52E7E
    content: |-
      ---
      inputType: "CA10__CaGoogleGceInstance__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleGceInstance__c/object.extracts.yaml
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The instance is created by GKE."
          check:
            STARTS_WITH:
              arg:
                EXTRACT: "Name"
              prefix:
                TEXT: 'gke-'
        - status: "INCOMPLIANT"
          currentStateMessage: "IP forwarding is enabled on the instance."
          remediationMessage: "Disable IP forwarding on the instance."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__ipForwarding__c"
              right:
                BOOLEAN: true
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "IP forwarding is not enabled on the instance."
  - path: /ce/ca/google/compute-engine/disable-instance-ip-forwarding/test-data.json
    md5Hash: 58CECB775EB0283D9646DB7092A3827A
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-02T17:45:22Z" },
          "Id": "a4Z1",
          "CA10__disappearanceTime__c": "2024-08-25T08:14:56Z",
          "Name": "d-amazon",
          "CA10__labels__c": "",
          "CA10__ipForwarding__c": false
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('Name').startsWith('gke-')",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-02T17:45:22Z" },
          "Id": "a4Z2",
          "CA10__disappearanceTime__c": null,
          "Name": "gke-camel-default",
          "CA10__labels__c": "goog-gke-node:",
          "CA10__ipForwarding__c": false
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__ipForwarding__c') == true",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-02T17:45:22Z" },
          "Id": "a4Z3",
          "CA10__disappearanceTime__c": null,
          "Name": "gateway-2019",
          "CA10__labels__c": "",
          "CA10__ipForwarding__c": true
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-02T17:45:22Z" },
          "Id": "a44",
          "CA10__disappearanceTime__c": null,
          "Name": "image",
          "CA10__labels__c": "instance-name: image",
          "CA10__ipForwarding__c": false
        }
      ]
  - path: /types/CA10__CaGoogleGceInstance__c/object.extracts.yaml
    md5Hash: 95F28CC49887E4035F2848BC20DC25D1
    content: "---\nextracts:\n  - name: \"Name\"\n    value: \n      FIELD:\n    \
      \    path: \"Name\"\n        undeterminedIf:\n          isEmpty:  \"Name should\
      \ not be empty\"\n  - name: \"CA10__labels__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__labels__c\"\n        undeterminedIf:\n          isEmpty:\
      \  \"Labels should not be empty\"\n  - name: \"CA10__ipForwarding__c\"\n   \
      \ value: \n      FIELD:\n        path: \"CA10__ipForwarding__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"IP forwarding can't be empty\"\n  - name: \"CA10__shieldedIntegrityMonitoringState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__shieldedIntegrityMonitoringState__c\"\
      \n  - name: \"CA10__shieldedVtpmState__c\"\n    value: \n      FIELD:\n    \
      \    path: \"CA10__shieldedVtpmState__c\"\n  - name: \"CA10__confidentialComputeStatus__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__confidentialComputeStatus__c\"\
      \n  - name: \"CA10__machineTypeName__c\"\n    value: \n      FIELD:\n      \
      \  path: \"CA10__machineTypeName__c\"\n  - name: \"CA10__metadataJson__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__metadataJson__c\"\n      \
      \  returnType: BYTES\n  - name: \"caJsonFrom__metadataJson__c\"\n    value:\
      \ \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__metadataJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Metadata JSON is invalid.\"\
      \n          isEmpty: \"Metadata JSON is empty.\"\n  - name: \"caJsonFrom__metadataJson__block_project_ssh_keys_value\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__metadataJson__c\"\
      \n        expression: \"to_string(items[?key=='block-project-ssh-keys'].value)\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return a text.\"\n\
      \          resultIsEmpty: \"The JSON query did not return a value.\"\n  - name:\
      \ \"caJsonFrom__metadataJson__enable_oslogin_value\"\n    value: \n      JSON_QUERY_TEXT:\n\
      \        arg:\n          EXTRACT: \"caJsonFrom__metadataJson__c\"\n        expression:\
      \ \"to_string(items[?key=='enable-oslogin'].value)\"\n        undeterminedIf:\n\
      \          evaluationError: \"The JSON query has failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a text.\"\n          resultIsEmpty: \"The\
      \ JSON query did not return a value.\"\n  - name: \"caJsonFrom__metadataJson__serial_port_enable_value\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__metadataJson__c\"\
      \n        expression: \"to_string(items[?key=='serial-port-enable'].value)\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return a text.\"\n\
      \          resultIsEmpty: \"The JSON query did not return a value.\"\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" : "a4Z1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4Z2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('Name').startsWith('gke-')",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4Z3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__ipForwarding__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "a44",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      Name STRING,
      CA10__ipForwarding__c BOOLEAN,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-02T17:45:22Z")
    },
    "Id" : "a4Z1",
    "CA10__disappearanceTime__c" : new Date("2024-08-25T08:14:56Z"),
    "Name" : "d-amazon",
    "CA10__ipForwarding__c" : false
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-02T17:45:22Z")
    },
    "Id" : "a4Z2",
    "Name" : "gke-camel-default",
    "CA10__ipForwarding__c" : false
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-02T17:45:22Z")
    },
    "Id" : "a4Z3",
    "Name" : "gateway-2019",
    "CA10__ipForwarding__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-02T17:45:22Z")
    },
    "Id" : "a44",
    "Name" : "image",
    "CA10__ipForwarding__c" : false
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          Name STRING,
          CA10__ipForwarding__c BOOLEAN
      >,
      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 IsEmptyLib = new function () {
          this.simpleIsEmpty = function(arg) {
              return arg == null;
          };
          this.simpleIsNotEmpty = function(arg) {
              return arg != null;
          };
      }();
      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.Name)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "Name.isEmpty()", currentStateMessage: "Name should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.Name;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Name [obj.Name]: ' + obj.Name);
      try {
          if (TextLib.startsWith(extract3.call(extract3), 'gke-')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('Name').startsWith('gke-')", currentStateMessage: "The instance is created by GKE.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked7() {
          if (IsEmptyLib.simpleIsEmpty(obj.CA10__ipForwarding__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__ipForwarding__c.isEmpty()", currentStateMessage: "IP forwarding can't be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__ipForwarding__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      references1.push('IP Forwarding [obj.CA10__ipForwarding__c]: ' + obj.CA10__ipForwarding__c);
      try {
          if (extract6.call(extract6) == true) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__ipForwarding__c') == true", currentStateMessage: "IP forwarding is enabled on the instance.", currentStateReferences: references1.join('\n'), remediation: "Disable IP forwarding on the instance.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "IP forwarding is not enabled on the instance.", 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.Name AS Name,
          sObject.CA10__ipForwarding__c AS CA10__ipForwarding__c,
          process_CA10__CaGoogleGceInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.Name AS Name,
                  sObject.CA10__ipForwarding__c AS CA10__ipForwarding__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
