---
policy: /ce/ca/aws/backup/vault-contains-unencrypted-recovery-points
logic: /ce/ca/aws/backup/vault-contains-unencrypted-recovery-points/prod.logic.yaml
executionTime: 2025-06-25T13:41:09.554641803Z
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10A1__disappearanceTime__c)
      actual: isDisappeared(CA10A1__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10A1__AWS_Backup_Recovery_Points__r.has(INCOMPLIANT)
      actual: CA10A1__AWS_Backup_Recovery_Points__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/backup/vault-contains-unencrypted-recovery-points/policy.yaml
    md5Hash: 0DDB007D223F95A82002339BC3D6A010
    content: "---\nnames:\n  full: AWS Backup Vault contains unencrypted Recovery\
      \ Points\n  contextual: Vault contains unencrypted Recovery Points\ndescription:\
      \ >\n  Ensure that all Recovery Points within an AWS Backup Vault are encrypted.\
      \ \n  Unencrypted recovery points can expose sensitive backup data to unauthorized\
      \ access.\ncategories:\n  - \"SECURITY\"\ntype: \"COMPLIANCE_POLICY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-security/data-encryption\"\n  - \"/frameworks/aws-fsbp-v1.0.0/backup/01\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[Backup.1] AWS Backup recovery\
      \ points should be encrypted at rest\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/backup-controls.html#backup-1\"\
      \n"
  - path: /ce/ca/aws/backup/vault-contains-unencrypted-recovery-points/prod.logic.yaml
    md5Hash: 492CAB216CF5CF41D36C1EDF3D9AED27
    content: "---\ninputType: \"CA10A1__CaAwsBackupBackupVault__c\"\ntestData:\n \
      \ - file: \"test-data.json\"  \nconditions:\n  - status: \"INCOMPLIANT\"\n \
      \   currentStateMessage: \"The Backup Vault contains one or more unencrypted\
      \ Recovery Points.\"\n    remediationMessage: \"Ensure all Recovery Points are\
      \ encrypted. This might require configuring the source resource's encryption\
      \ settings.\"\n    check:\n      RELATED_LIST_HAS:\n        status: \"INCOMPLIANT\"\
      \n        relationshipName: \"CA10A1__AWS_Backup_Recovery_Points__r\"\notherwise:\n\
      \  status: \"COMPLIANT\"\n  currentStateMessage: \"All Recovery Points in this\
      \ Backup Vault are encrypted.\"\nrelatedLists:\n  - relationshipName: \"CA10A1__AWS_Backup_Recovery_Points__r\"\
      \n    importExtracts:\n      - file: \"/types/CA10A1__CaAwsBackupRecoveryPoint__c/object.extracts.yaml\"\
      \n    conditions:\n      - status: \"INCOMPLIANT\"\n        currentStateMessage:\
      \ \"The Recovery Point is not encrypted with a KMS key.\"\n        remediationMessage:\
      \ \"Consider encrypting this Recovery Point.\"\n        check:\n          IS_EMPTY:\n\
      \            arg:\n              EXTRACT: \"CA10A1__kmsMasterKeyId__c\"\n  \
      \  otherwise:\n      status: \"COMPLIANT\"\n      currentStateMessage: \"The\
      \ Recovery Point is encrypted with a KMS.\" "
  - path: /types/CA10A1__CaAwsBackupRecoveryPoint__c/object.extracts.yaml
    md5Hash: C4B6C10EA9486A6080860FBE1C6E1BD8
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ backup:ListRecoveryPointsByBackupVault\n  - name: CA10A1__kmsMasterKeyId__c\n\
      \    value: \n      FIELD:\n        path: CA10A1__kmsMasterKeyId__c"
  - path: /ce/ca/aws/backup/vault-contains-unencrypted-recovery-points/test-data.json
    md5Hash: 6E39716EE48F994F12AEA7F4AC5B9B22
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-10T18:55:17Z"
              },
              "Id": "test1",
              "CA10A1__disappearanceTime__c": "2025-05-10T18:55:17Z",
              "CA10A1__AWS_Backup_Recovery_Points__r": [
                  {
                      "Id": "test1_1",
                      "CA10A1__disappearanceTime__c": "2025-05-06T06:38:15Z",
                      "CA10A1__kmsMasterKeyId__c": "",
                      "CA10A1__backupVault__c": "test1"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-10T18:55:17Z"
              },
              "Id": "test2",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__AWS_Backup_Recovery_Points__r": [
                  {
                      "Id": "test2_1",
                      "CA10A1__disappearanceTime__c": "2025-05-06T06:38:15Z",
                      "CA10A1__kmsMasterKeyId__c": "",
                      "CA10A1__backupVault__c": "test2"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10A1__AWS_Backup_Recovery_Points__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-10T18:55:17Z"
              },
              "Id": "test3",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__AWS_Backup_Recovery_Points__r": [
                  {
                      "Id": "test3_1",
                      "CA10A1__disappearanceTime__c": null,
                      "CA10A1__kmsMasterKeyId__c": "",
                      "CA10A1__backupVault__c": "test3"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-10T18:55:17Z"
              },
              "Id": "test4",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__AWS_Backup_Recovery_Points__r": []
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-10T18:55:17Z"
              },
              "Id": "test5",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__AWS_Backup_Recovery_Points__r": [
                  {
                      "Id": "test5_1",
                      "CA10A1__disappearanceTime__c": null,
                      "CA10A1__kmsMasterKeyId__c": "kmsMasterKeyId5",
                      "CA10A1__backupVault__c": "test5"
                  }
              ]
          }
      ]
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(CA10A1__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10A1__AWS_Backup_Recovery_Points__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsBackupBackupVault__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test1",
    "CA10A1__disappearanceTime__c" : new Date("2025-05-10T18:55:17Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsBackupRecoveryPoint__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__kmsMasterKeyId__c STRING,
      CA10A1__backupVault__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test1_1",
    "CA10A1__disappearanceTime__c" : new Date("2025-05-06T06:38:15Z"),
    "CA10A1__kmsMasterKeyId__c" : "",
    "CA10A1__backupVault__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test2_1",
    "CA10A1__disappearanceTime__c" : new Date("2025-05-06T06:38:15Z"),
    "CA10A1__kmsMasterKeyId__c" : "",
    "CA10A1__backupVault__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test3_1",
    "CA10A1__kmsMasterKeyId__c" : "",
    "CA10A1__backupVault__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-10T18:55:17Z")
    },
    "Id" : "test5_1",
    "CA10A1__kmsMasterKeyId__c" : "kmsMasterKeyId5",
    "CA10A1__backupVault__c" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsBackupBackupVault__c(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__AWS_Backup_Recovery_Points__r ARRAY<STRUCT<
              Id STRING,
              CA10A1__disappearanceTime__c TIMESTAMP,
              CA10A1__kmsMasterKeyId__c STRING,
              CA10A1__backupVault__c STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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 [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10A1__AWS_Backup_Recovery_Points__r_INCOMPLIANT2 = 0;
      if (obj.CA10A1__AWS_Backup_Recovery_Points__r != null) {
          for (var i3 = 0; i3 < obj.CA10A1__AWS_Backup_Recovery_Points__r.length; i3++) {
              if (obj.CA10A1__AWS_Backup_Recovery_Points__r[i3].result.status == 'INCOMPLIANT') {
                  count_CA10A1__AWS_Backup_Recovery_Points__r_INCOMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10A1__AWS_Backup_Recovery_Points__r] ' + (count_CA10A1__AWS_Backup_Recovery_Points__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10A1__AWS_Backup_Recovery_Points__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10A1__AWS_Backup_Recovery_Points__r.has(INCOMPLIANT)", currentStateMessage: "The Backup Vault contains one or more unencrypted Recovery Points.", currentStateReferences: references1.join('\n'), remediation: "Ensure all Recovery Points are encrypted. This might require configuring the source resource's encryption settings.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "All Recovery Points in this Backup Vault are encrypted.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10A1__AWS_Backup_Recovery_Points__r(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__kmsMasterKeyId__c STRING,
          CA10A1__backupVault__c 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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__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.CA10A1__kmsMasterKeyId__c; } return this.out; };
      references1.push('KMS Master Key ID [obj.CA10A1__kmsMasterKeyId__c]: ' + obj.CA10A1__kmsMasterKeyId__c);
      if (TextLib.isEmpty(extract3.call(extract3))) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10A1__kmsMasterKeyId__c').isEmpty()", currentStateMessage: "The Recovery Point is not encrypted with a KMS key.", currentStateReferences: references1.join('\n'), remediation: "Consider encrypting this Recovery Point.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The Recovery Point is encrypted with a KMS.", 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.Id AS Id,
          sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
          `CA10A1__AWS_Backup_Recovery_Points__r`.arr AS CA10A1__AWS_Backup_Recovery_Points__r,
          process_CA10A1__CaAwsBackupBackupVault__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  `CA10A1__AWS_Backup_Recovery_Points__r`.arr AS CA10A1__AWS_Backup_Recovery_Points__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsBackupBackupVault__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10A1__backupVault__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                      sObject.CA10A1__kmsMasterKeyId__c AS CA10A1__kmsMasterKeyId__c,
                      sObject.CA10A1__backupVault__c AS CA10A1__backupVault__c,
                      process_CA10A1__AWS_Backup_Recovery_Points__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                              sObject.CA10A1__kmsMasterKeyId__c AS CA10A1__kmsMasterKeyId__c,
                              sObject.CA10A1__backupVault__c AS CA10A1__backupVault__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10A1__CaAwsBackupRecoveryPoint__c()) AS sObject
          GROUP BY sObject.CA10A1__backupVault__c
      ) AS `CA10A1__AWS_Backup_Recovery_Points__r`
          ON sObject.Id = `CA10A1__AWS_Backup_Recovery_Points__r`.CA10A1__backupVault__c
  ) sObject ON sObject.Id = expectedResult.Id;
