---
policy: /ce/ca/aws/msk/cluster-client-broker-encryption
logic: /ce/ca/aws/msk/cluster-client-broker-encryption/prod.logic.yaml
executionTime: 2026-01-17T12:02:54.711414714Z
generationMs: 81
executionMs: 882
rows:
  - id: test1
    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: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__encryptionClientBroker__c') == 'PLAINTEXT' || extract('CA10__encryptionClientBroker__c')
        == 'TLS_PLAINTEXT'
      actual: extract('CA10__encryptionClientBroker__c') == 'PLAINTEXT' || extract('CA10__encryptionClientBroker__c')
        == 'TLS_PLAINTEXT'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__encryptionClientBroker__c') == 'TLS'
      actual: extract('CA10__encryptionClientBroker__c') == 'TLS'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/msk/cluster-client-broker-encryption/policy.yaml
    md5Hash: FE89491550CC66EC8EC44089D7FB2FC0
    content: "---\nnames:\n  full: \"AWS MSK Cluster Client-Broker Encryption is not\
      \ enabled\"\n  contextual: \"Cluster Client-Broker Encryption is not enabled\"\
      \ndescription: >\n  Ensure that Amazon MSK clusters are configured to enforce\
      \ TLS encryption for \n  data in transit between clients and brokers. This prevents\
      \ plaintext traffic \n  and protects data from eavesdropping.\ntype: \"COMPLIANCE_POLICY\"\
      \ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/data-encryption\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/msk/01\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[MSK.1] MSK clusters should be encrypted in transit among broker\
      \ nodes\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/msk-controls.html#msk-1\""
  - path: /ce/ca/aws/msk/cluster-client-broker-encryption/prod.logic.yaml
    md5Hash: 5C02FE10E013E7836A626F5198F393A1
    content: "---\ninputType: \"CA10__CaAwsMskCluster__c\"\nimportExtracts:\n  - file:\
      \ \"/types/CA10__CaAwsMskCluster__c/object.extracts.yaml\"\ntestData:\n  - file:\
      \ \"test-data.json\"\nconditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"The MSK cluster allows unencrypted communication (PLAINTEXT or TLS_PLAINTEXT).\"\
      \n    remediationMessage: \"Update the cluster configuration to require TLS\
      \ for client-broker communication.\"\n    check:\n      OR:\n        args:\n\
      \          - IS_EQUAL:\n              left:\n                EXTRACT: \"CA10__encryptionClientBroker__c\"\
      \n              right:\n                TEXT: \"PLAINTEXT\"\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"CA10__encryptionClientBroker__c\"\
      \n              right:\n                TEXT: \"TLS_PLAINTEXT\"\n  - status:\
      \ \"COMPLIANT\"\n    currentStateMessage: \"The MSK cluster enforces TLS encryption\
      \ for all client-broker connections.\" \n    check:\n      IS_EQUAL:\n     \
      \   left:\n          EXTRACT: \"CA10__encryptionClientBroker__c\"\n        right:\n\
      \          TEXT: \"TLS\"\notherwise:\n  status: \"UNDETERMINED\"\n  currentStateMessage:\
      \ \"Unexpected values in the field.\""
  - path: /ce/ca/aws/msk/cluster-client-broker-encryption/test-data.json
    md5Hash: 7BD415FDE242088E7D1DEBCD6435B957
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-13T23:28:46Z"
              },
              "CA10__disappearanceTime__c": "2026-01-13T20:52:48Z",
              "CA10__encryptionClientBroker__c": "TLS",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__encryptionClientBroker__c') == 'PLAINTEXT' || extract('CA10__encryptionClientBroker__c') == 'TLS_PLAINTEXT'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-13T23:28:46Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__encryptionClientBroker__c": "PLAINTEXT",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__encryptionClientBroker__c') == 'TLS'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-13T23:28:46Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__encryptionClientBroker__c": "TLS",
              "Id": "test3"
          }
      ]
  - path: /types/CA10__CaAwsMskCluster__c/object.extracts.yaml
    md5Hash: 8EFC219AB649690607ABB91220221090
    content: "---\nextracts:\n# Values: TLS, PLAINTEXT, TLS_PLAINTEXT. Not nullable.\
      \ Can't have no access, retrieved via kafka:ListClusters\n  - name: \"CA10__encryptionClientBroker__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__encryptionClientBroker__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Cluster Client Broker Encryption\
      \ cannot be empty.\"\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" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__encryptionClientBroker__c') == 'PLAINTEXT' || extract('CA10__encryptionClientBroker__c') == 'TLS_PLAINTEXT'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__encryptionClientBroker__c') == 'TLS'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsMskCluster__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__encryptionClientBroker__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-13T23:28:46Z")
    },
    "CA10__disappearanceTime__c" : new Date("2026-01-13T20:52:48Z"),
    "CA10__encryptionClientBroker__c" : "TLS",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-13T23:28:46Z")
    },
    "CA10__encryptionClientBroker__c" : "PLAINTEXT",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-13T23:28:46Z")
    },
    "CA10__encryptionClientBroker__c" : "TLS",
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsMskCluster__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__encryptionClientBroker__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 AWS [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__encryptionClientBroker__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__encryptionClientBroker__c.isEmpty()", currentStateMessage: "Cluster Client Broker Encryption cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__encryptionClientBroker__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Encryption: Client Broker [obj.CA10__encryptionClientBroker__c]: ' + obj.CA10__encryptionClientBroker__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'PLAINTEXT') || TextLib.equal(extract3.call(extract3), 'TLS_PLAINTEXT')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__encryptionClientBroker__c') == 'PLAINTEXT' || extract('CA10__encryptionClientBroker__c') == 'TLS_PLAINTEXT'", currentStateMessage: "The MSK cluster allows unencrypted communication (PLAINTEXT or TLS_PLAINTEXT).", currentStateReferences: references1.join('\n'), remediation: "Update the cluster configuration to require TLS for client-broker communication.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked8() {
          if (TextLib.isEmpty(obj.CA10__encryptionClientBroker__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__encryptionClientBroker__c.isEmpty()", currentStateMessage: "Cluster Client Broker Encryption cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__encryptionClientBroker__c;
      }
      function extract7() { if (!this.out) { this.out = fieldChecked8(); } return this.out; };
      try {
          if (TextLib.equal(extract7.call(extract7), 'TLS')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__encryptionClientBroker__c') == 'TLS'", currentStateMessage: "The MSK cluster enforces TLS encryption for all client-broker connections.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Unexpected values in the field.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__encryptionClientBroker__c AS CA10__encryptionClientBroker__c,
          sObject.Id AS Id,
          process_CA10__CaAwsMskCluster__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__encryptionClientBroker__c AS CA10__encryptionClientBroker__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsMskCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
