---
policy: /ce/ca/aws/rds/instance-encryption
logic: /ce/ca/aws/rds/instance-encryption/prod.logic.yaml
executionTime: 2025-05-10T12:02:19.570006182Z
rows:
  - id: test1
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__storageEncrypted__c') == true
      actual: extract('CA10__storageEncrypted__c') == true
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/instance-encryption/policy.yaml
    md5Hash: 06E5E5A1A1BE233BF8269098B7B5A824
    content: |
      ---
      names:
        full: AWS RDS Instance Encryption is not enabled
        contextual: Instance Encryption is not enabled
      description: "Amazon RDS encrypted DB instances use the industry standard AES-256\
        \ encryption algorithm to encrypt your data on the server that hosts your Amazon\
        \ RDS DB instances. After your data is encrypted, Amazon RDS handles authentication\
        \ of access and decryption of your data transparently with a minimal impact on performance."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/02/02/01"
        - "/frameworks/cloudaware/resource-security/data-encryption"
        - "/frameworks/aws-fsbp-v1.0.0/rds/03"
      similarPolicies:
        internal:
          - dec-x-6ba5ecd2
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/aws/RDS/rds-encryption-enabled.html
            name: RDS Encryption Enabled
  - path: /ce/ca/aws/rds/instance-encryption/prod.logic.yaml
    md5Hash: A897F6C6B89E8CAF7BA5B63ACBDAED95
    content: "---\ninputType: \"CA10__CaAwsDbInstance__c\"\ntestData:\n  - file: test-data.json\n\
      importExtracts:\n  - file: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml\n\
      conditions:\n  - status: \"COMPLIANT\"\n    currentStateMessage: \"RDS Instance\
      \ storage encryption is enabled.\"\n    check:\n      IS_EQUAL:\n        left:\n\
      \          EXTRACT: CA10__storageEncrypted__c\n        right:\n          BOOLEAN:\
      \ true \notherwise:\n  status: \"INCOMPLIANT\"\n  currentStateMessage: \"RDS\
      \ Instance storage encryption is disabled.\"\n  remediationMessage: \"Enable\
      \ RDS Instance storage encryption.\"\n"
  - path: /ce/ca/aws/rds/instance-encryption/test-data.json
    md5Hash: 543955F6C011435E9B1BBA2D53060B55
    content: |
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__storageEncrypted__c') == true",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-04T19:44:50Z" },
          "Id": "test1",
          "CA10__disappearanceTime__c": null,
          "CA10__storageEncrypted__c": true
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-04T19:44:50Z" },
          "Id": "test2",
          "CA10__disappearanceTime__c": null,
          "CA10__storageEncrypted__c": false
        }
      ]
  - path: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml
    md5Hash: FF9B20D94B2A03C8B9A5C755DC5EF3A9
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__engine__c\n    value:\n      FIELD:\n\
      \        path: CA10__engine__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. DB Instance Engine cannot be empty.\"\n# Not Nullable. Can't\
      \ have no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__endpointPort__c\n\
      \    value:\n      FIELD:\n        path: CA10__endpointPort__c\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. DB Endpoint Port cannot be empty.\"\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__publiclyAccessible__c\n    value:\n      FIELD:\n        path:\
      \ CA10__publiclyAccessible__c\n# Checkbox. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__storageEncrypted__c\n    value: \n\
      \      FIELD:\n        path: CA10__storageEncrypted__c\n# Checkbox. Can't have\
      \ no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__autoMinorVersionUpgrade__c\n\
      \    value: \n      FIELD:\n        path: CA10__autoMinorVersionUpgrade__c\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__multiAz__c\n    value: \n      FIELD:\n        path: CA10__multiAz__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" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__storageEncrypted__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__storageEncrypted__c BOOLEAN,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-04T19:44:50Z")
    },
    "Id" : "test1",
    "CA10__storageEncrypted__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-04T19:44:50Z")
    },
    "Id" : "test2",
    "CA10__storageEncrypted__c" : false
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__storageEncrypted__c BOOLEAN
      >,
      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__storageEncrypted__c; } return this.out; };
      references1.push('Storage Encrypted [obj.CA10__storageEncrypted__c]: ' + obj.CA10__storageEncrypted__c);
      if (extract3.call(extract3) == true) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__storageEncrypted__c') == true", currentStateMessage: "RDS Instance storage encryption is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "RDS Instance storage encryption is disabled.", currentStateReferences: references1.join('\n'), remediation: "Enable RDS Instance storage encryption.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__storageEncrypted__c AS CA10__storageEncrypted__c,
          process_CA10__CaAwsDbInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__storageEncrypted__c AS CA10__storageEncrypted__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
