---
policy: /ce/ca/aws/rds/snapshot-encryption
logic: /ce/ca/aws/rds/snapshot-encryption/prod.logic.yaml
executionTime: 2025-11-17T14:33:43.88539483Z
generationMs: 72
executionMs: 671
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: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: not(extract('CA10__encrypted__c'))
      actual: not(extract('CA10__encrypted__c'))
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'available'
      actual: extract('CA10__status__c') != 'available'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/snapshot-encryption/policy.yaml
    md5Hash: C77C26A4DB713E828A54FE1E8B3683F1
    content: "---\nnames:\n  full: \"AWS RDS Snapshot is not encrypted\"\n  contextual:\
      \ \"Snapshot is not encrypted\"\ndescription: >\n  Ensure that AWS RDS database\
      \ and cluster snapshots are encrypted to protect data \n  at rest. Encrypting\
      \ snapshots adds a critical layer of security by rendering \n  the backup data\
      \ unreadable to unauthorized users, even if the snapshot is compromised.\ntype:\
      \ \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-security/data-encryption\"\n  - \"/frameworks/aws-fsbp-v1.0.0/rds/04\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/neptune/06\"\n  - \"/frameworks/aws-well-architected/sec/08/02\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[RDS.4] RDS cluster snapshots\
      \ and database snapshots should be encrypted at rest\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/rds-controls.html#rds-4\"\
      \n    - name: \"[Neptune.6] Neptune DB cluster snapshots should be encrypted\
      \ at rest\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/neptune-controls.html#neptune-6\"\
      \n"
  - path: /ce/ca/aws/rds/snapshot-encryption/prod.logic.yaml
    md5Hash: C7D7E0BA364BD67A32E488FBA2488991
    content: |-
      ---
      inputType: "CA10__CaAwsDbSnapshot__c"
      importExtracts:
        - file: "/types/CA10__CaAwsDbSnapshot__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The Snapshot is not in available status."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "available"
        - status: "INAPPLICABLE"
          currentStateMessage: "The RDS Snapshot is not encrypted."
          remediationMessage: "Consider encrypting the snapshot by creating an encrypted copy and deleting the original."
          check:
            NOT:
              arg:
                EXTRACT: "CA10__encrypted__c"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The Snapshot is not encrypted."
  - path: /ce/ca/aws/rds/snapshot-encryption/test-data.json
    md5Hash: B2BF9AB8C44BA8E9B1580284CC74FFCB
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": "2025-08-13T05:28:00Z",
              "CA10__status__c": "available",
              "CA10__encrypted__c": true,
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "299",
                  "conditionText": "not(extract('CA10__encrypted__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__encrypted__c": false,
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__encrypted__c": true,
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__status__c') != 'available'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "creating",
              "CA10__encrypted__c": true,
              "Id": "test4"
          }
      ]
  - path: /types/CA10__CaAwsDbSnapshot__c/object.extracts.yaml
    md5Hash: 76C7D71A88222DC213DE94D7293929A3
    content: "---\nextracts:\n# Checkbox\n  - name: \"CA10__encrypted__c\"\n    value:\n\
      \      FIELD:\n        path: CA10__encrypted__c\n# Values: automated, manual,\
      \ shared, public, awsbackup. Not nullable. Can't have no access retrieved via\
      \ rds:DescribeDBSnapshots\n  - name: \"CA10__snapshotType__c\"\n    value:\n\
      \      FIELD:\n        path: \"CA10__snapshotType__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Snapshot Type cannot be empty.\"\n#  Not\
      \ Nullable.\n  - name: \"CA10__attributesJson__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__attributesJson__c\"\n        returnType: BYTES\n    \
      \    undeterminedIf:\n          noAccessDelegate:\n            path: \"CA10__attributesJson__c\"\
      \n            currentStateMessage: \"Unable to determine Snapshot Attributes.\
      \ Possible permission issue with rds:DescribeDBSnapshotAttributes.\"\n     \
      \     isEmpty: \"Snapshot Attributes are not populated yet.\"\n  - name: \"\
      caJsonFrom__attributesJson__c\"\n    value: \n      JSON_FROM:\n        arg:\n\
      \          EXTRACT: \"CA10__attributesJson__c\"\n        undeterminedIf:\n \
      \         isInvalid: \"Snapshot attributes JSON is invalid\"\n# Not Nullable.\n\
      \  - name: \"CA10__snapshotCreateTime__c\"\n    value:\n      FIELD:\n     \
      \   path: \"CA10__snapshotCreateTime__c\"\n        undeterminedIf:\n       \
      \   isEmpty: \"Corrupted data. Snapshot Create Time cannot be empty.\"\n# Not\
      \ nullable. Can't have no access retrieved via rds:DescribeDBSnapshots\n  -\
      \ name: \"CA10__status__c\"\n    value:\n      FIELD:\n        path: \"CA10__status__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Corrupted data. Snapshot Status\
      \ 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" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "not(extract('CA10__encrypted__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'available'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbSnapshot__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__encrypted__c BOOLEAN,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-08-13T05:28:00Z"),
    "CA10__status__c" : "available",
    "CA10__encrypted__c" : true,
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__status__c" : "available",
    "CA10__encrypted__c" : false,
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__status__c" : "available",
    "CA10__encrypted__c" : true,
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__status__c" : "creating",
    "CA10__encrypted__c" : true,
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbSnapshot__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__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 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__status__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__status__c.isEmpty()", currentStateMessage: "Corrupted data. Snapshot Status cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__status__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'available')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'available'", currentStateMessage: "The Snapshot is not in available status.", 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 extract6() { if (!this.out) { this.out = obj.CA10__encrypted__c; } return this.out; };
      references1.push('Encrypted [obj.CA10__encrypted__c]: ' + obj.CA10__encrypted__c);
      if (!extract6.call(extract6)) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "not(extract('CA10__encrypted__c'))", currentStateMessage: "The RDS Snapshot is not encrypted.", currentStateReferences: references1.join('\n'), remediation: "Consider encrypting the snapshot by creating an encrypted copy and deleting the original.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The Snapshot is not encrypted.", 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__status__c AS CA10__status__c,
          sObject.CA10__encrypted__c AS CA10__encrypted__c,
          sObject.Id AS Id,
          process_CA10__CaAwsDbSnapshot__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__encrypted__c AS CA10__encrypted__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbSnapshot__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
