---
policy: /ce/ca/aws/opensearch/domain-node-to-node-encryption
logic: /ce/ca/aws/opensearch/domain-node-to-node-encryption/prod.logic.yaml
executionTime: 2025-11-17T14:33:41.356418589Z
generationMs: 70
executionMs: 1074
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: not(extract('CA10__nodeToNodeEncryptionEnabled__c'))
      actual: not(extract('CA10__nodeToNodeEncryptionEnabled__c'))
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/opensearch/domain-node-to-node-encryption/policy.yaml
    md5Hash: 834F5D5B4D4060A4A598B6FFC716641B
    content: "---\nnames:\n  full: \"AWS OpenSearch Domain Node To Node Encryption\
      \ is not enabled\"\n  contextual: \"Domain Node To Node Encryption is not enabled\"\
      \ndescription: >\n  Ensure that node-to-node encryption is enabled for AWS OpenSearch\
      \ Domains to \n  protect data in transit within a cluster. Node-to-node encryption\
      \ uses TLS to \n  encrypt all communications between nodes.\ntype: \"COMPLIANCE_POLICY\"\
      \ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/data-encryption\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/es/03\"\n  - \"/frameworks/aws-fsbp-v1.0.0/opensearch/03\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[Opensearch.3] OpenSearch\
      \ domains should encrypt data sent between nodes\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/opensearch-controls.html#opensearch-3\"\
      \n    - name: \"[ES.3] Elasticsearch domains should encrypt data sent between\
      \ nodes\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/es-controls.html#es-3\"\
      \n"
  - path: /ce/ca/aws/opensearch/domain-node-to-node-encryption/prod.logic.yaml
    md5Hash: C615878585F0420C4A72A50409368B1E
    content: "---\ninputType: \"CA10__CaAwsElasticsearchDomain__c\"\ntestData:\n \
      \ - file: \"test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10__CaAwsElasticsearchDomain__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"Node-to-node\
      \ encryption is not enabled for the OpenSearch Domain.\"\n    remediationMessage:\
      \ \"Consider enabling node-to-node encryption.\"\n    check:\n      NOT:\n \
      \       arg:\n          EXTRACT: \"CA10__nodeToNodeEncryptionEnabled__c\"  \
      \  \notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"Node-to-node\
      \ encryption is enabled for the OpenSearch Domain.\""
  - path: /ce/ca/aws/opensearch/domain-node-to-node-encryption/test-data.json
    md5Hash: BE0BE83DB1D68B3A1175E846474B8C4C
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-05T23:51:16Z"
              },
              "CA10__disappearanceTime__c": "2025-08-17T07:38:43Z",
              "CA10__nodeToNodeEncryptionEnabled__c": false,
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "not(extract('CA10__nodeToNodeEncryptionEnabled__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-05T23:51:16Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__nodeToNodeEncryptionEnabled__c": false,
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-05T23:51:16Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__nodeToNodeEncryptionEnabled__c": true,
              "Id": "test3"
          }
      ]
  - path: /types/CA10__CaAwsElasticsearchDomain__c/object.extracts.yaml
    md5Hash: C072626C7FFF5273DA4B104B530A027E
    content: |
      ---
      extracts:
      # Values: true | false (TEXT). Not nullable. Can't have no access retrieved via es:DescribeDomains
        - name: "CA10__serviceSoftwareUpdateAvailable__c"
          value:
            FIELD:
              path: "CA10__serviceSoftwareUpdateAvailable__c"
      # Checkbox
        - name: "CA10__encryptionAtRestEnabled__c"
          value:
            FIELD:
              path: "CA10__encryptionAtRestEnabled__c"
      # Nullable. Can't have no access retrieved via es:DescribeDomains
        - name: "CA10__endpoint__c"
          value:
            FIELD:
              path: "CA10__endpoint__c"
      # Nullable. Can't have no access retrieved via es:DescribeDomains
        - name: "CA10__vpcEndpoints__c"
          value:
            FIELD:
              path: "CA10__vpcEndpoints__c"
      # Checkbox
        - name: "CA10__nodeToNodeEncryptionEnabled__c"
          value:
            FIELD:
              path: "CA10__nodeToNodeEncryptionEnabled__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" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "not(extract('CA10__nodeToNodeEncryptionEnabled__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsElasticsearchDomain__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__nodeToNodeEncryptionEnabled__c BOOLEAN,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-05T23:51:16Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-08-17T07:38:43Z"),
    "CA10__nodeToNodeEncryptionEnabled__c" : false,
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-05T23:51:16Z")
    },
    "CA10__nodeToNodeEncryptionEnabled__c" : false,
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-05T23:51:16Z")
    },
    "CA10__nodeToNodeEncryptionEnabled__c" : true,
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsElasticsearchDomain__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__nodeToNodeEncryptionEnabled__c BOOLEAN,
          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 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 extract3() { if (!this.out) { this.out = obj.CA10__nodeToNodeEncryptionEnabled__c; } return this.out; };
      references1.push('Node To Node Encryption Enabled [obj.CA10__nodeToNodeEncryptionEnabled__c]: ' + obj.CA10__nodeToNodeEncryptionEnabled__c);
      if (!extract3.call(extract3)) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "not(extract('CA10__nodeToNodeEncryptionEnabled__c'))", currentStateMessage: "Node-to-node encryption is not enabled for the OpenSearch Domain.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling node-to-node encryption.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Node-to-node encryption is enabled for the OpenSearch Domain.", 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__nodeToNodeEncryptionEnabled__c AS CA10__nodeToNodeEncryptionEnabled__c,
          sObject.Id AS Id,
          process_CA10__CaAwsElasticsearchDomain__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__nodeToNodeEncryptionEnabled__c AS CA10__nodeToNodeEncryptionEnabled__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsElasticsearchDomain__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
