---
policy: /ce/ca/google/dataproc/cluster-encryption
logic: /ce/ca/google/dataproc/cluster-encryption/prod.logic.yaml
executionTime: 2025-04-24T23:46:56.703075878Z
rows:
  - id: 111
    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: 112
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__encryptionConfigKmsKeyName__c').isEmpty()
      actual: extract('CA10__encryptionConfigKmsKeyName__c').isEmpty()
    runtimeError: {}
  - id: 113
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/dataproc/cluster-encryption/policy.yaml
    md5Hash: CB125BBCFE6876051855EC266BC3794D
    content: "---\nnames: \n  full: \"Google Dataproc Cluster is not encrypted using\
      \ Customer-Managed Encryption Key\"\n  contextual: \"Cluster is not encrypted\
      \ using Customer-Managed Encryption Key\"\ndescription: \"When you use Dataproc,\
      \ cluster and job data is stored on Persistent Disks (PDs) \\\n associated with\
      \ the Compute Engine VMs in your cluster and in a Cloud Storage staging bucket.\
      \ \\ \n This PD and bucket data is encrypted using a Google-generated data encryption\
      \ key (DEK) and \\ \n key encryption key (KEK). The CMEK feature allows you\
      \ to create, use, and revoke the key \\ \n encryption key (KEK). Google still\
      \ controls the data encryption key (DEK).\"\ntype: COMPLIANCE_POLICY\ncategories:\n\
      \  - \"SECURITY\"\nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/08/01\n\
      \  - /frameworks/cloudaware/resource-security/secure-access\nsimilarPolicies:\n\
      \  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/gcp/Dataproc/enable-encryption-with-cmks-for-dataproc-clusters.html\"\
      \n      name: \"Enable Dataproc Cluster Encryption with Customer-Managed Keys\"\
      \n"
  - path: /ce/ca/google/dataproc/cluster-encryption/prod.logic.yaml
    md5Hash: FCA624397F8D49C150E0A4ECB7B3EDE9
    content: |
      ---

      inputType: "CA10__CaGoogleDataprocCluster__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleDataprocCluster__c/object.extracts.yaml
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The Dataproc Cluster is not encrypted with Customer-Managed Encryption Key."
          remediationMessage: "Use Customer-Managed Encryption Key for Dataproc Cluster"
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10__encryptionConfigKmsKeyName__c"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The Dataproc Cluster is encrypted with Customer-Managed Encryption Key."
  - path: /ce/ca/google/dataproc/cluster-encryption/test-data.json
    md5Hash: F1C378B80465FAAB255AB40A5E31E3C6
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "111",
          "CA10__disappearanceTime__c": "2025-01-08T15:37:41Z",
          "CA10__encryptionConfigKmsKeyName__c": ""
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__encryptionConfigKmsKeyName__c').isEmpty()",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "112",
          "CA10__disappearanceTime__c": null,
          "CA10__encryptionConfigKmsKeyName__c": ""
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "113",
          "CA10__disappearanceTime__c": null,
          "CA10__encryptionConfigKmsKeyName__c": "name3"
        }
      ]
  - path: /types/CA10__CaGoogleDataprocCluster__c/object.extracts.yaml
    md5Hash: 262A8BDF8A1F9D109A47EF253BDFC767
    content: "---\nextracts:\n  - name: \"CA10__encryptionConfigKmsKeyName__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__encryptionConfigKmsKeyName__c\""
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" : "111",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "112",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__encryptionConfigKmsKeyName__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "113",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleDataprocCluster__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__encryptionConfigKmsKeyName__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "111",
    "CA10__disappearanceTime__c" : new Date("2025-01-08T15:37:41Z"),
    "CA10__encryptionConfigKmsKeyName__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "112",
    "CA10__encryptionConfigKmsKeyName__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "113",
    "CA10__encryptionConfigKmsKeyName__c" : "name3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleDataprocCluster__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__encryptionConfigKmsKeyName__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]
      function extract3() { if (!this.out) { this.out = obj.CA10__encryptionConfigKmsKeyName__c; } return this.out; };
      references1.push('Encryption Config KMS Key Name [obj.CA10__encryptionConfigKmsKeyName__c]: ' + obj.CA10__encryptionConfigKmsKeyName__c);
      if (TextLib.isEmpty(extract3.call(extract3))) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__encryptionConfigKmsKeyName__c').isEmpty()", currentStateMessage: "The Dataproc Cluster is not encrypted with Customer-Managed Encryption Key.", currentStateReferences: references1.join('\n'), remediation: "Use Customer-Managed Encryption Key for Dataproc Cluster", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The Dataproc Cluster is encrypted with Customer-Managed Encryption Key.", 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__encryptionConfigKmsKeyName__c AS CA10__encryptionConfigKmsKeyName__c,
          process_CA10__CaGoogleDataprocCluster__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__encryptionConfigKmsKeyName__c AS CA10__encryptionConfigKmsKeyName__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleDataprocCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
