---
policy: /ce/ca/google/compute-engine/instance-serial-port-connection
logic: /ce/ca/google/compute-engine/instance-serial-port-connection/prod.logic.yaml
executionTime: 2025-04-24T23:46:53.718598733Z
rows:
  - id: a4Z00
    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: a4Z11
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 102
      actual: 102
    conditionText:
      expected: extract('CA10__metadataJson__c').asJson().isInvalid()
      actual: extract('CA10__metadataJson__c').asJson().isInvalid()
    runtimeError:
      expected: "Expected property name or '}' in JSON at position 78 (line 1 column\
        \ 79)"
      actual: "Expected property name or '}' in JSON at position 78 (line 1 column\
        \ 79)"
  - id: a4Z22
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('caJsonFrom__metadataJson__serial_port_enable_value').contains('true')
      actual: extract('caJsonFrom__metadataJson__serial_port_enable_value').contains('true')
    runtimeError: {}
  - id: a4Z33
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/compute-engine/instance-serial-port-connection/policy.yaml
    md5Hash: F120ADF681C82F9710A14B2A77B67126
    content: "---\nnames: \n  full: \"Google GCE Instance Enable Connecting to Serial\
      \ Ports is not disabled\"\n  contextual: \"Instance Enable Connecting to Serial\
      \ Ports is not disabled\"\ndescription: \"Interacting with a serial port is\
      \ often referred to as the serial console, which is similar to \\\n using a\
      \ terminal window, in that input and output is entirely in text mode and there\
      \ is no graphical \\ \n interface or mouse support.\n If you enable the interactive\
      \ serial console on an instance, clients can attempt to connect to that instance\
      \ \\ \n from any IP address. Therefore interactive serial console support should\
      \ be disabled.\"\ntype: COMPLIANCE_POLICY\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - /frameworks/cis-gcp-v3.0.0/04/05\n  - /frameworks/cloudaware/resource-security/secure-access\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/ComputeEngine/disable-interactive-serial-console-support.html\"\
      \n      name: \"Disable Interactive Serial Console Support\"\n"
  - path: /ce/ca/google/compute-engine/instance-serial-port-connection/prod.logic.yaml
    md5Hash: 88A7BB4434ECFFAA9B1A61E5AEFFF8A2
    content: "---\n\ninputType: \"CA10__CaGoogleGceInstance__c\"\ntestData:\n  - file:\
      \ test-data.json\nimportExtracts:\n  - file: /types/CA10__CaGoogleGceInstance__c/object.extracts.yaml\n\
      conditions: \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"Enable\
      \ Connecting to Serial Ports is enabled for the instance.\"\n    remediationMessage:\
      \ \"It is recommended to disable Connecting to Serial Ports.\"\n    check:\n\
      \      CONTAINS:\n        arg:\n          EXTRACT: \"caJsonFrom__metadataJson__serial_port_enable_value\"\
      \n        substring:\n          TEXT: \"true\"\notherwise:\n  status: \"COMPLIANT\"\
      \n  currentStateMessage: \"Enable Connecting to Serial Ports is not enabled\
      \ for the instance.\""
  - path: /ce/ca/google/compute-engine/instance-serial-port-connection/test-data.json
    md5Hash: DCEF1147A07047F6A0DF79D04CE2CB38
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-08T18:22:06Z" },
          "Id": "a4Z00",
          "CA10__disappearanceTime__c": "2024-08-30T14:19:56Z",
          "CA10__metadataJson__c": "{}"
        },
        {
          "expectedResult": {
            "status": "UNDETERMINED",
            "conditionIndex": "102",
            "conditionText": "extract('CA10__metadataJson__c').asJson().isInvalid()",
            "runtimeError": "Expected property name or '}' in JSON at position 78 (line 1 column 79)"
          },
          "context": { "snapshotTime": "2024-09-08T18:22:06Z" },
          "Id": "a4Z11",
          "CA10__disappearanceTime__c": null,
          "CA10__metadataJson__c": "{\"fingerprint\":\"e51rHdmMjJY\\u003d\",\"items\":[{\"key\":\"startup-script\",\"value\": {\\n  curl -s -H \\\"Metadata-Flavor: Google\\\" \\\"http://metadata/computeMetadata/v1/instance/\\\"\\n}\\n\\nfunction get_token()\\n\\n# "
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('caJsonFrom__metadataJson__serial_port_enable_value').contains('true')",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-08T18:22:06Z" },
          "Id": "a4Z22",
          "CA10__disappearanceTime__c": null,
          "CA10__metadataJson__c": "{\"fingerprint\":\"000000\\u003d\",\"items\":[{\"key\":\"boostCpu\",\"value\":\"true\"},{\"key\":\"enable-oslogin\",\"value\":\"TRUE\"},{\"key\":\"serial-port-enable\",\"value\":\"true\"}],\"kind\":\"compute#metadata\"}"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-08T18:22:06Z" },
          "Id": "a4Z33",
          "CA10__disappearanceTime__c": null,
          "CA10__metadataJson__c": "{\"fingerprint\":\"000000\\u003d\",\"items\":[{\"key\":\"boostCpu\",\"value\":\"true\"},{\"key\":\"enable-oslogin\",\"value\":\"TRUE\"},{\"key\":\"serial-port-enable\",\"value\":\"false\"}],\"kind\":\"compute#metadata\"}"
        }
      ]
  - 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" : "a4Z00",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4Z11",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "102",
      "conditionText" : "extract('CA10__metadataJson__c').asJson().isInvalid()",
      "runtimeError" : "Expected property name or '}' in JSON at position 78 (line 1 column 79)"
    }
  }, {
    "Id" : "a4Z22",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('caJsonFrom__metadataJson__serial_port_enable_value').contains('true')",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4Z33",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__metadataJson__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-08T18:22:06Z")
    },
    "Id" : "a4Z00",
    "CA10__disappearanceTime__c" : new Date("2024-08-30T14:19:56Z"),
    "CA10__metadataJson__c" : "{}"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-08T18:22:06Z")
    },
    "Id" : "a4Z11",
    "CA10__metadataJson__c" : "{\"fingerprint\":\"e51rHdmMjJY\\u003d\",\"items\":[{\"key\":\"startup-script\",\"value\": {\\n  curl -s -H \\\"Metadata-Flavor: Google\\\" \\\"http://metadata/computeMetadata/v1/instance/\\\"\\n}\\n\\nfunction get_token()\\n\\n# "
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-08T18:22:06Z")
    },
    "Id" : "a4Z22",
    "CA10__metadataJson__c" : "{\"fingerprint\":\"000000\\u003d\",\"items\":[{\"key\":\"boostCpu\",\"value\":\"true\"},{\"key\":\"enable-oslogin\",\"value\":\"TRUE\"},{\"key\":\"serial-port-enable\",\"value\":\"true\"}],\"kind\":\"compute#metadata\"}"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-08T18:22:06Z")
    },
    "Id" : "a4Z33",
    "CA10__metadataJson__c" : "{\"fingerprint\":\"000000\\u003d\",\"items\":[{\"key\":\"boostCpu\",\"value\":\"true\"},{\"key\":\"enable-oslogin\",\"value\":\"TRUE\"},{\"key\":\"serial-port-enable\",\"value\":\"false\"}],\"kind\":\"compute#metadata\"}"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__metadataJson__c STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  OPTIONS (library=['gs://compliance-platform-public/jmespath.min.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]
      function jsonQueryChecked4() {
          var input = extract6.call(extract6);
          var out;
          try {
              out = jmespath.search(input, 'to_string(items[?key==\'serial-port-enable\'].value)');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "extract('caJsonFrom__metadataJson__c').jsonQueryText('to_string(items[?key==\\'serial-port-enable\\'].value)').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return a text.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:104", {cause: {status: 'UNDETERMINED', conditionIndex: 104, conditionText: "extract('caJsonFrom__metadataJson__c').jsonQueryText('to_string(items[?key==\\'serial-port-enable\\'].value)').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          if (TextLib.isEmpty(out)) {
              throw new Error("UNDETERMINED condition:105", {cause: {status: 'UNDETERMINED', conditionIndex: 105, conditionText: "extract('caJsonFrom__metadataJson__c').jsonQueryText('to_string(items[?key==\\'serial-port-enable\\'].value)').isResultEmpty()", currentStateMessage: "The JSON query did not return a value.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return out;
      }
      function jsonChecked7() {
          var input = extract9.call(extract9);
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "extract('CA10__metadataJson__c').asJson().isEmpty()", currentStateMessage: "Metadata JSON is empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "extract('CA10__metadataJson__c').asJson().isInvalid()", currentStateMessage: "Metadata JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract9() { if (!this.out) { this.out = obj.CA10__metadataJson__c; } return this.out; };
      function extract6() { if (!this.out) { this.out = jsonChecked7(); } return this.out; };
      function extract3() { if (!this.out) { this.out = jsonQueryChecked4(); } return this.out; };
      references1.push('Metadata JSON [obj.CA10__metadataJson__c]: ' + obj.CA10__metadataJson__c);
      try {
          if (TextLib.contains(extract3.call(extract3), 'true')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('caJsonFrom__metadataJson__serial_port_enable_value').contains('true')", currentStateMessage: "Enable Connecting to Serial Ports is enabled for the instance.", currentStateReferences: references1.join('\n'), remediation: "It is recommended to disable Connecting to Serial Ports.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Enable Connecting to Serial Ports is not enabled for 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.CA10__metadataJson__c AS CA10__metadataJson__c,
          process_CA10__CaGoogleGceInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__metadataJson__c AS CA10__metadataJson__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
