---
policy: /ce/ca/google/gke/node-pool-service-account
logic: /ce/ca/google/gke/node-pool-service-account/prod.logic.yaml
executionTime: 2025-10-25T12:02:45.907493392Z
generationMs: 62
executionMs: 614
rows:
  - id: '001'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10G1__nodeConfigServiceAccount__c') == 'default'
      actual: extract('CA10G1__nodeConfigServiceAccount__c') == 'default'
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/gke/node-pool-service-account/policy.yaml
    md5Hash: 7EA59B2CD5290C28C61855ECE840493F
    content: "---\nnames: \n  full: \"Google GKE Cluster Node Pool uses default Service\
      \ account\"\n  contextual: \"Cluster Node Pool uses default Service account\"\
      \ndescription: \"Create and use minimally privileged Service accounts to run\
      \ GKE cluster nodes \\\n \\ instead of using the Compute Engine default Service\
      \ account. Unnecessary permissions could \\\n \\ be abused in the case of a\
      \ node compromise.\"\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\
      \nframeworkMappings:\n  - \"/frameworks/cis-gke-v1.8.0/05/02/01\"\n  - \"/frameworks/pci-dss-v3.2.1/02/01\"\
      \n  - \"/frameworks/pci-dss-v3.2.1/07/01/02\"\n  - \"/frameworks/nist-sp-800-53-r4/ac/06\"\
      \n  - \"/frameworks/nist-sp-800-53-r4/sc/07\"\n  - \"/frameworks/iso-iec-27001-2013/09/02/03\"\
      \n  - \"/frameworks/cloudaware/resource-security/secure-access\""
  - path: /ce/ca/google/gke/node-pool-service-account/prod.logic.yaml
    md5Hash: E6442BA900DF30332CEFA9DE243FA573
    content: "---\n\ninputType: \"CA10G1__CaGoogleGkeClusterNodePool__c\"\ntestData:\n\
      \  - file: test-data.json\nimportExtracts:\n  - file: /types/CA10G1__CaGoogleGkeClusterNodePool__c/object.extracts.yaml\n\
      conditions:\n  - status: \"UNDETERMINED\"\n    currentStateMessage: \"Node Pool\
      \ Service account config is empty.\"\n    check:\n      IS_EMPTY:\n        arg:\n\
      \          EXTRACT: \"CA10G1__nodeConfigServiceAccount__c\"\n  - status: \"\
      INCOMPLIANT\"\n    currentStateMessage: \"Node Pool use default Service account.\"\
      \n    remediationMessage: \"Create a minimally privileged Service account.\"\
      \    \n    check:\n      IS_EQUAL:\n        left:\n          EXTRACT: \"CA10G1__nodeConfigServiceAccount__c\"\
      \n        right:\n          TEXT: \"default\"\notherwise:\n  status: \"COMPLIANT\"\
      \n  currentStateMessage: \"Node Pool don't use default Service account.\"\n\
      \  "
  - path: /ce/ca/google/gke/node-pool-service-account/test-data.json
    md5Hash: FCF583F78005A182C9010F5318211A92
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10G1__nodeConfigServiceAccount__c') == 'default'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-11T18:29:55Z" },
          "Id": "001",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__nodeConfigServiceAccount__c": "default"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-11T18:29:55Z" },
          "Id": "002",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__nodeConfigServiceAccount__c": "tt-gke-11kc@my.iam.gserviceaccount.com"
        }
      ]
  - path: /types/CA10G1__CaGoogleGkeClusterNodePool__c/object.extracts.yaml
    md5Hash: 0A652ABADAA95854B5E133EB8B5BBD45
    content: "---\nextracts:\n  - name: \"CA10G1__nodeManagementAutoRepair__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10G1__nodeManagementAutoRepair__c\"\
      \n  - name: \"CA10G1__nodeManagementAutoUpgrade__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10G1__nodeManagementAutoUpgrade__c\"\n  - name: \"CA10G1__nodeConfigImageType__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10G1__nodeConfigImageType__c\"\
      \n  - name: \"CA10G1__nodeConfigServiceAccount__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10G1__nodeConfigServiceAccount__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" : "001",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10G1__nodeConfigServiceAccount__c') == 'default'",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10G1__CaGoogleGkeClusterNodePool__c()
  RETURNS ARRAY<STRUCT<
      CA10G1__disappearanceTime__c TIMESTAMP,
      CA10G1__nodeConfigServiceAccount__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-11T18:29:55Z")
    },
    "CA10G1__nodeConfigServiceAccount__c" : "default",
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-11T18:29:55Z")
    },
    "CA10G1__nodeConfigServiceAccount__c" : "tt-gke-11kc@my.iam.gserviceaccount.com",
    "Id" : "002"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10G1__CaGoogleGkeClusterNodePool__c(
      obj STRUCT<
          CA10G1__disappearanceTime__c TIMESTAMP,
          CA10G1__nodeConfigServiceAccount__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 [CA10G1__disappearanceTime__c]: ' + obj.CA10G1__disappearanceTime__c);
      if (obj.CA10G1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10G1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10G1__nodeConfigServiceAccount__c; } return this.out; };
      references1.push('Node Config: Service Account [obj.CA10G1__nodeConfigServiceAccount__c]: ' + obj.CA10G1__nodeConfigServiceAccount__c);
      if (TextLib.isEmpty(extract3.call(extract3))) {
          return {status: 'UNDETERMINED', conditionIndex: 199, conditionText: "extract('CA10G1__nodeConfigServiceAccount__c').isEmpty()", currentStateMessage: "Node Pool Service account config is empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10G1__nodeConfigServiceAccount__c; } return this.out; };
      if (TextLib.equal(extract6.call(extract6), 'default')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10G1__nodeConfigServiceAccount__c') == 'default'", currentStateMessage: "Node Pool use default Service account.", currentStateReferences: references1.join('\n'), remediation: "Create a minimally privileged Service account.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Node Pool don't use default Service account.", 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.CA10G1__disappearanceTime__c AS CA10G1__disappearanceTime__c,
          sObject.CA10G1__nodeConfigServiceAccount__c AS CA10G1__nodeConfigServiceAccount__c,
          sObject.Id AS Id,
          process_CA10G1__CaGoogleGkeClusterNodePool__c(
              STRUCT(
                  sObject.CA10G1__disappearanceTime__c AS CA10G1__disappearanceTime__c,
                  sObject.CA10G1__nodeConfigServiceAccount__c AS CA10G1__nodeConfigServiceAccount__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10G1__CaGoogleGkeClusterNodePool__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
