---
policy: /ce/ca/aws/opensearch/domain-encryption
logic: /ce/ca/aws/opensearch/domain-encryption/prod.logic.yaml
executionTime: 2025-11-17T14:33:40.834037701Z
generationMs: 77
executionMs: 659
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__encryptionAtRestEnabled__c'))
      actual: not(extract('CA10__encryptionAtRestEnabled__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-encryption/policy.yaml
    md5Hash: ED7E42ADC58AD3C7B3646020CBE240D0
    content: "---\nnames:\n  full: \"AWS OpenSearch Domain is not encrypted at rest\"\
      \n  contextual: \"Domain is not encrypted at rest\"\ndescription: >\n  Ensure\
      \ that Amazon OpenSearch domains have encryption at rest enabled to protect\
      \ \n  sensitive data from unauthorized access to the underlying storage.\ntype:\
      \ \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-security/data-encryption\"\n  - \"/frameworks/aws-fsbp-v1.0.0/es/01\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/opensearch/01\"\n  - \"/frameworks/aws-well-architected/sec/08/02\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[Opensearch.1] OpenSearch\
      \ domains should have encryption at rest enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/opensearch-controls.html#opensearch-1\"\
      \n    - name: \"[ES.1] Elasticsearch domains should have encryption at-rest\
      \ enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/es-controls.html#es-1\"\
      \n"
  - path: /ce/ca/aws/opensearch/domain-encryption/prod.logic.yaml
    md5Hash: 04522120A988D5CCEBCF342D79645B58
    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: \"The OpenSearch\
      \ domain is not encrypted at rest.\"\n    remediationMessage: \"Encryption at\
      \ rest cannot be enabled on an existing domain.\\\n      \\ A new domain must\
      \ be created with encryption enabled.\"\n    check:\n      NOT:\n        arg:\n\
      \          EXTRACT: \"CA10__encryptionAtRestEnabled__c\"    \notherwise:\n \
      \ status: \"COMPLIANT\"\n  currentStateMessage: \"The OpenSearch domain is encrypted\
      \ at rest.\""
  - path: /ce/ca/aws/opensearch/domain-encryption/test-data.json
    md5Hash: F7E2D9411867832EEF5D6FB7DEDA14BE
    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__encryptionAtRestEnabled__c": true,
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "not(extract('CA10__encryptionAtRestEnabled__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-05T23:51:16Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__encryptionAtRestEnabled__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__encryptionAtRestEnabled__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__encryptionAtRestEnabled__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__encryptionAtRestEnabled__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__encryptionAtRestEnabled__c" : true,
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-05T23:51:16Z")
    },
    "CA10__encryptionAtRestEnabled__c" : false,
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-05T23:51:16Z")
    },
    "CA10__encryptionAtRestEnabled__c" : true,
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsElasticsearchDomain__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__encryptionAtRestEnabled__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__encryptionAtRestEnabled__c; } return this.out; };
      references1.push('Encryption At Rest Enabled [obj.CA10__encryptionAtRestEnabled__c]: ' + obj.CA10__encryptionAtRestEnabled__c);
      if (!extract3.call(extract3)) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "not(extract('CA10__encryptionAtRestEnabled__c'))", currentStateMessage: "The OpenSearch domain is not encrypted at rest.", currentStateReferences: references1.join('\n'), remediation: "Encryption at rest cannot be enabled on an existing domain. A new domain must be created with encryption enabled.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The OpenSearch domain is encrypted at rest.", 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__encryptionAtRestEnabled__c AS CA10__encryptionAtRestEnabled__c,
          sObject.Id AS Id,
          process_CA10__CaAwsElasticsearchDomain__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__encryptionAtRestEnabled__c AS CA10__encryptionAtRestEnabled__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsElasticsearchDomain__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
