---
policy: /ce/ca/aws/ec2/ebs-snapshot-encryption
logic: /ce/ca/aws/ec2/ebs-snapshot-encryption/prod.logic.yaml
executionTime: 2025-12-27T12:01:46.740287193Z
generationMs: 59
executionMs: 674
rows:
  - id: '001'
    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: '002'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__state__c') != 'completed'
      actual: extract('CA10__state__c') != 'completed'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__encrypted__c') == false
      actual: extract('CA10__encrypted__c') == false
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__encrypted__c') == true
      actual: extract('CA10__encrypted__c') == true
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/ec2/ebs-snapshot-encryption/policy.yaml
    md5Hash: 20DEDF09EAA2ABF9545345D6BCFBB7BA
    content: "---\nnames:\n  full: \"AWS EBS Snapshot is not encrypted\"\n  contextual:\
      \ \"EBS Snapshot is not encrypted\"\ndescription: >\n  Ensure that Amazon EBS\
      \ snapshots are encrypted to protect data at rest. \n  Encrypted snapshots provide\
      \ an additional layer of security by preventing \n  unauthorized access to the\
      \ snapshot content. The EBS encryption and decryption \n  is handled transparently\
      \ and does not require any additional \n  action from you, your server instance,\
      \ or your application.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\
      \nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/data-encryption\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/ec2/03\"\nsimilarPolicies:\n  cloudConformity:\n\
      \    - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/EBS/snapshot-encrypted.html\n\
      \      name: EBS Snapshot Encrypted\n  awsSecurityHub:\n    - name: \"[EC2.3]\
      \ Attached Amazon EBS volumes should be encrypted at-rest\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/ec2-controls.html#ec2-3\""
  - path: /ce/ca/aws/ec2/ebs-snapshot-encryption/prod.logic.yaml
    md5Hash: 4E29765F6E633D9F2458B0ABD562E748
    content: |
      inputType: "CA10__CaAwsSnapshot__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: /types/CA10__CaAwsSnapshot__c/object.extracts.yaml
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The snapshot is not in a completed state."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__state__c"
              right:
                TEXT: "completed"
        - status: "INCOMPLIANT"
          currentStateMessage: "The EBS snapshot is not encrypted."
          remediationMessage: "Copy the snapshot and enable encryption on the copy to secure the data."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__encrypted__c"
              right:
                BOOLEAN: false
        - status: "COMPLIANT"
          currentStateMessage: "The EBS snapshot is encrypted."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__encrypted__c"
              right:
                BOOLEAN: true
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/ec2/ebs-snapshot-encryption/test-data.json
    md5Hash: C6512EC4464C4F3A11776ABEB3197793
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T01:10:46Z" },
          "CA10__disappearanceTime__c": "2025-12-01T01:01:02Z",
          "CA10__state__c": "completed",
          "CA10__encrypted__c": true,
          "Id": "001"
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__state__c') != 'completed'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T01:10:46Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__state__c": "error",
          "CA10__encrypted__c": true,
          "Id": "002"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__encrypted__c') == false",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T01:10:46Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__state__c": "completed",
          "CA10__encrypted__c": false,
          "Id": "003"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "399",
            "conditionText": "extract('CA10__encrypted__c') == true",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T01:10:46Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__state__c": "completed",
          "CA10__encrypted__c": true,
          "Id": "004"
        }
      ]
  - path: /types/CA10__CaAwsSnapshot__c/object.extracts.yaml
    md5Hash: 44D70F8730901DA3EFD8E736EDA9E616
    content: "# yaml-language-server: $schema=../../schema/Extracts.schema.json\n\
      ---\nextracts:\n# Values: Yea | No. Nullable null is equal to No. \n  - name:\
      \ CA10__publicAccessible__c\n    value:\n      FIELD: \n        path: CA10__publicAccessible__c\n\
      \        # undeterminedIf:\n        #   noAccessDelegate:\n        #     path:\
      \ \"CA10__publicAccessible__c\"\n        #     currentStateMessage: \"Unable\
      \ to determined Public Access. Possible Permissions issues with ec2:DescribeSnapshotAttribute.\"\
      \n# Not Nullable. Can't have no access retrieved via ec2:DescribeSnapshots.\n\
      \  - name: \"CA10__startTime__c\"\n    value:\n      FIELD:\n        path: \"\
      CA10__startTime__c\"\n        undeterminedIf:\n          isEmpty: \"Corrupted\
      \ data. Snapshot Start Time cannot be empty.\"\n# Values: pending | completed\
      \ | error | recoverable | recovering \n# Not Nullable. Can't have no access\
      \ retrieved via ec2:DescribeSnapshots.\n  - name: \"CA10__state__c\"\n    value:\n\
      \      FIELD:\n        path: \"CA10__state__c\"\n        undeterminedIf:\n \
      \         isEmpty: \"Corrupted data. Snapshot Start Time cannot be empty.\"\n\
      # Not Nullable.\n  - name: \"CA10__encrypted__c\"\n    value:\n      FIELD:\n\
      \        path: \"CA10__encrypted__c\"\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. Snapshot `Encrypted` state cannot be empty.\""
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" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__state__c') != 'completed'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__encrypted__c') == false",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__encrypted__c') == true",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsSnapshot__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__state__c STRING,
      CA10__encrypted__c BOOLEAN,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T01:10:46Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-12-01T01:01:02Z"),
    "CA10__state__c" : "completed",
    "CA10__encrypted__c" : true,
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T01:10:46Z")
    },
    "CA10__state__c" : "error",
    "CA10__encrypted__c" : true,
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T01:10:46Z")
    },
    "CA10__state__c" : "completed",
    "CA10__encrypted__c" : false,
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T01:10:46Z")
    },
    "CA10__state__c" : "completed",
    "CA10__encrypted__c" : true,
    "Id" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsSnapshot__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__state__c STRING,
          CA10__encrypted__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 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 IsEmptyLib = new function () {
      this.simpleIsEmpty = function(arg) {
          return arg == null;
      };
      this.simpleIsNotEmpty = function(arg) {
          return arg != null;
      };
  }();
      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__state__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__state__c.isEmpty()", currentStateMessage: "Corrupted data. Snapshot Start Time cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__state__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('State [obj.CA10__state__c]: ' + obj.CA10__state__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'completed')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__state__c') != 'completed'", currentStateMessage: "The snapshot is not in a completed state.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked7() {
          if (IsEmptyLib.simpleIsEmpty(obj.CA10__encrypted__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__encrypted__c.isEmpty()", currentStateMessage: "Corrupted data. Snapshot `Encrypted` state cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__encrypted__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      references1.push('Encrypted [obj.CA10__encrypted__c]: ' + obj.CA10__encrypted__c);
      try {
          if (extract6.call(extract6) == false) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__encrypted__c') == false", currentStateMessage: "The EBS snapshot is not encrypted.", currentStateReferences: references1.join('\n'), remediation: "Copy the snapshot and enable encryption on the copy to secure the data.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[3], conditionIndex:[300..399]
      function fieldChecked10() {
          if (IsEmptyLib.simpleIsEmpty(obj.CA10__encrypted__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__encrypted__c.isEmpty()", currentStateMessage: "Corrupted data. Snapshot `Encrypted` state cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__encrypted__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      try {
          if (extract9.call(extract9) == true) {
              return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__encrypted__c') == true", currentStateMessage: "The EBS snapshot is encrypted.", 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: 400, 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__state__c AS CA10__state__c,
          sObject.CA10__encrypted__c AS CA10__encrypted__c,
          sObject.Id AS Id,
          process_CA10__CaAwsSnapshot__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__state__c AS CA10__state__c,
                  sObject.CA10__encrypted__c AS CA10__encrypted__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsSnapshot__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
