---
policy: /ce/ca/aws/cloudtrail/log-file-validation
logic: /ce/ca/aws/cloudtrail/log-file-validation/prod.logic.yaml
executionTime: 2025-04-24T23:44:27.216821607Z
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: extract('CA10__logFileValidationEnabled__c') == false
      actual: extract('CA10__logFileValidationEnabled__c') == false
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__logFileValidationEnabled__c') == true
      actual: extract('CA10__logFileValidationEnabled__c') == true
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/cloudtrail/log-file-validation/policy.yaml
    md5Hash: A4C083B180A1E0C6310A9A21E7B9177E
    content: |
      ---
      names:
        full: AWS CloudTrail Log File Validation is not enabled
        contextual: Log File Validation is not enabled
      description: "CloudTrail log file validation creates a digitally signed digest file\
        \ containing a hash of each log that CloudTrail writes to S3. These digest files\
        \ can be used to determine whether a log file was changed, deleted, or unchanged\
        \ after CloudTrail delivered the log. It is recommended that file validation be\
        \ enabled on all CloudTrails."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
        - RELIABILITY
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/03/02"
        - "/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration"
        - "/frameworks/aws-fsbp-v1.0.0/cloudtrail/04"
      similarPolicies:
        internal:
          - dec-x-b1e1a494
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/CloudTrail/cloudtrail-log-file-integrity-validation.html
            name: CloudTrail Log File Integrity Validation
  - path: /ce/ca/aws/cloudtrail/log-file-validation/prod.logic.yaml
    md5Hash: 6DF8075634F775F9F6C90E08B96F54A6
    content: |-
      ---
      inputType: "CA10__CaAwsCloudTrailTrail__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsCloudTrailTrail__c/object.extracts.yaml"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "CloudTrail Log File Validation is disabled."
          remediationMessage: "Consider enabling CloudTrail Log File Validation."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__logFileValidationEnabled__c"
              right:
                BOOLEAN: false
        - status: "COMPLIANT"
          currentStateMessage: "CloudTrail Log File Validation is enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__logFileValidationEnabled__c"
              right:
                BOOLEAN: true
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/cloudtrail/log-file-validation/test-data.json
    md5Hash: 37B4E56A1FF545D51AF96BD8991E3EC6
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-28T17:35:50Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-05-28T17:35:50Z",
              "CA10__logFileValidationEnabled__c": true
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__logFileValidationEnabled__c') == false",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-28T17:35:50Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__logFileValidationEnabled__c": false
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__logFileValidationEnabled__c') == true",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-28T17:35:50Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__logFileValidationEnabled__c": true
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-28T17:35:50Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__logFileValidationEnabled__c": null
          }
      ]
  - path: /types/CA10__CaAwsCloudTrailTrail__c/object.extracts.yaml
    md5Hash: 3DD3C63AB8EE3DD1379ED26A102A68C4
    content: "---\nextracts:\n# Checkbox. Can't have no access, retrieved via cloudtrail:DescribeTrails\n\
      \  - name: \"CA10__multiRegionTrail__c\"\n    value: \n      FIELD:\n      \
      \  path: \"CA10__multiRegionTrail__c\"\n# Checkbox. \n  - name: \"CA10__isLogging__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__isLogging__c\"\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10__isLogging__c\"\n   \
      \         currentStateMessage: \"Unable to determine Logging status. Possible\
      \ permission issue with cloudtrail:GetTrailStatus.\"\n# Checkbox. Can't have\
      \ no access, retrieved via cloudtrail:DescribeTrails\n  - name: \"CA10__logFileValidationEnabled__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__logFileValidationEnabled__c\"\
      \n# Nullable\n  - name: \"CA10__eventSelectorsJson__c\"\n    value: \n     \
      \ FIELD:\n        path: \"CA10__eventSelectorsJson__c\"\n        returnType:\
      \ BYTES\n        undeterminedIf:\n          noAccessDelegate:\n            path:\
      \ \"CA10__eventSelectorsJson__c\"\n            currentStateMessage: \"Unable\
      \ to determine Logging status. Possible permission issue with cloudtrail:GetEventSelectors.\"\
      \n  - name: \"caJsonFrom__eventSelectorsJson__c\"\n    value: \n      JSON_FROM:\n\
      \        arg:\n          EXTRACT: \"CA10__eventSelectorsJson__c\"\n        undeterminedIf:\n\
      \          isInvalid: \"Provided CloudTrail Event Selector has invalid JSON.\"\
      \n# Returns TEXT. Values: All, WriteOnly, ReadOnly\n  - name: \"caJsonText__eventSelectorsJson_readWriteType__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__eventSelectorsJson__c\"\n        expression: \"[*].readWriteType\
      \ | [0]\"\n        undeterminedIf:\n          evaluationError: \"The JSON text\
      \ query has failed.\"\n          resultTypeMismatch: \"The JSON query did not\
      \ return a text type.\"\n# Returns BOOLEAN true or false\n  - name: \"caJsonBoolean__eventSelectorsJson_includeManagementEvents__c\"\
      \n    value: \n      JSON_QUERY_BOOLEAN:\n        arg: \n          EXTRACT:\
      \ \"caJsonFrom__eventSelectorsJson__c\"\n        expression: \"[*].includeManagementEvents\
      \ | [0]\"\n        undeterminedIf:\n          evaluationError: \"The JSON boolean\
      \ query has failed.\"\n          resultTypeMismatch: \"The JSON query did not\
      \ return a boolean type.\"\n# Nullable. Can't have no access, retrieved via\
      \ cloudtrail:DescribeTrails\n  - name: \"CA10__kmsKey__c\"\n    value: \n  \
      \    FIELD:\n        path: \"CA10__kmsKey__c\"\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" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__logFileValidationEnabled__c') == false",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__logFileValidationEnabled__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsCloudTrailTrail__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__logFileValidationEnabled__c BOOLEAN,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-05-28T17:35:50Z"),
    "CA10__logFileValidationEnabled__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test2",
    "CA10__logFileValidationEnabled__c" : false
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test3",
    "CA10__logFileValidationEnabled__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test4",
    "CA10__logFileValidationEnabled__c" : null
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsCloudTrailTrail__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__logFileValidationEnabled__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__logFileValidationEnabled__c; } return this.out; };
      references1.push('Log File Validation Enabled [obj.CA10__logFileValidationEnabled__c]: ' + obj.CA10__logFileValidationEnabled__c);
      if (extract3.call(extract3) == false) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__logFileValidationEnabled__c') == false", currentStateMessage: "CloudTrail Log File Validation is disabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling CloudTrail Log File Validation.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__logFileValidationEnabled__c; } return this.out; };
      if (extract6.call(extract6) == true) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__logFileValidationEnabled__c') == true", currentStateMessage: "CloudTrail Log File Validation is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, 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.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__logFileValidationEnabled__c AS CA10__logFileValidationEnabled__c,
          process_CA10__CaAwsCloudTrailTrail__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__logFileValidationEnabled__c AS CA10__logFileValidationEnabled__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsCloudTrailTrail__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
