---
policy: /ce/ca/aws/guardduty/detector-eks-audit-logs
logic: /ce/ca/aws/guardduty/detector-eks-audit-logs/prod.logic.yaml
executionTime: 2025-10-08T17:39:18.239567343Z
generationMs: 64
executionMs: 876
rows:
  - id: test1
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status')
        == 'DISABLED'
      actual: extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status')
        == 'DISABLED'
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status')
        == 'ENABLED'
      actual: extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status')
        == 'ENABLED'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/guardduty/detector-eks-audit-logs/policy.yaml
    md5Hash: B94A14AF34340B35815344DE61B096F8
    content: "---\nnames:\n  full: \"AWS GuardDuty Detector EKS Audit Log Monitoring\
      \ is not enabled\"\n  contextual: \"Detector EKS Audit Log Monitoring is not\
      \ enabled\"\ndescription: >\n  Ensure that AWS GuardDuty EKS Audit Log Monitoring\
      \ is enabled to monitor Kubernetes \n  audit logs for potential threats and\
      \ suspicious activities within your EKS clusters.\ntype: \"COMPLIANCE_POLICY\"\
      \ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/guardduty/05\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[GuardDuty.5] GuardDuty EKS Audit Log Monitoring should be enabled\"\
      \n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/guardduty-controls.html#guardduty-5\""
  - path: /ce/ca/aws/guardduty/detector-eks-audit-logs/prod.logic.yaml
    md5Hash: 90ECAF7A74C6B8105F50B790244D29CE
    content: "---\ninputType: \"CA10__CaAwsGuardDutyDetector__c\"\ntestData:\n  -\
      \ file: \"test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10__CaAwsGuardDutyDetector__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"GuardDuty\
      \ EKS Audit Log Monitoring is disabled.\"\n    remediationMessage: \"Enable\
      \ EKS Audit Log Monitoring in the GuardDuty data sources settings.\"\n    check:\n\
      \      IS_EQUAL:\n        left:\n          JSON_QUERY_TEXT:\n            expression:\
      \ \"kubernetes.auditLogs.status\" \n            arg:\n              EXTRACT:\
      \ \"caJsonFrom__dataSourcesJson__c\"\n            undeterminedIf:\n        \
      \      evaluationError: \"Json query text has failed.\"\n              resultTypeMismatch:\
      \ \"Json query text did not return text type.\"\n        right:\n          TEXT:\
      \ \"DISABLED\"\n  - status: \"COMPLIANT\"\n    currentStateMessage: \"GuardDuty\
      \ EKS Audit Log Monitoring is enabled.\"\n    check:\n      IS_EQUAL:\n    \
      \    left:\n          JSON_QUERY_TEXT:\n            expression: \"kubernetes.auditLogs.status\"\
      \ \n            arg:\n              EXTRACT: \"caJsonFrom__dataSourcesJson__c\"\
      \n            undeterminedIf:\n              evaluationError: \"Json query text\
      \ has failed.\"\n              resultTypeMismatch: \"Json query text did not\
      \ return text type.\"\n        right:\n          TEXT: \"ENABLED\"\notherwise:\n\
      \  status: \"UNDETERMINED\"\n  currentStateMessage: \"Unexpected values in the\
      \ field.\""
  - path: /ce/ca/aws/guardduty/detector-eks-audit-logs/test-data.json
    md5Hash: 669FB5BB76D9AD1AA6B04E50ED675DB5
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status') == 'DISABLED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__dataSourcesJson__c": "{\"cloudTrail\":{\"status\":\"ENABLED\"},\"dnsLogs\":{\"status\":\"ENABLED\"},\"flowLogs\":{\"status\":\"ENABLED\"},\"s3Logs\":{\"status\":\"DISABLED\"},\"kubernetes\":{\"auditLogs\":{\"status\":\"DISABLED\"}},\"malwareProtection\":{\"scanEc2InstanceWithFindings\":{\"ebsVolumes\":{\"status\":\"DISABLED\",\"reason\":null}},\"serviceRole\":null}}",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status') == 'ENABLED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__dataSourcesJson__c": "{\"cloudTrail\":{\"status\":\"ENABLED\"},\"dnsLogs\":{\"status\":\"ENABLED\"},\"flowLogs\":{\"status\":\"ENABLED\"},\"s3Logs\":{\"status\":\"DISABLED\"},\"kubernetes\":{\"auditLogs\":{\"status\":\"ENABLED\"}},\"malwareProtection\":{\"scanEc2InstanceWithFindings\":{\"ebsVolumes\":{\"status\":\"DISABLED\",\"reason\":null}},\"serviceRole\":null}}",
              "Id": "test2"
          }
      ]
  - path: /types/CA10__CaAwsGuardDutyDetector__c/object.extracts.yaml
    md5Hash: B1458F9B9038182B01C83196ED7E48C8
    content: |-
      ---
      extracts:
      # Values: ENABLED | DISABLED. Not Nullable.
        - name: "CA10__status__c"
          value:
            FIELD:
              path: "CA10__status__c"
              undeterminedIf:
                noAccessDelegate:
                  path: "CA10__status__c"
                  currentStateMessage: "The status cannot be empty. Possible permission issue with guardduty:GetDetector."
        - name: "CA10__dataSourcesJson__c"
          value:
            FIELD:
              path: "CA10__dataSourcesJson__c"
              undeterminedIf:
                noAccessDelegate:
                  path: "CA10__dataSourcesJson__c"
                  currentStateMessage: "The Data Sources cannot be empty. Possible permission issue with guardduty:GetDetector."
        - name: "caJsonFrom__dataSourcesJson__c"
          value:
            JSON_FROM:
              arg:
                EXTRACT: "CA10__dataSourcesJson__c"
              undeterminedIf:
                isInvalid: "The Data Sources JSON is invalid."
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" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status') == 'DISABLED'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status') == 'ENABLED'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsGuardDutyDetector__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__dataSourcesJson__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__dataSourcesJson__c" : "{\"cloudTrail\":{\"status\":\"ENABLED\"},\"dnsLogs\":{\"status\":\"ENABLED\"},\"flowLogs\":{\"status\":\"ENABLED\"},\"s3Logs\":{\"status\":\"DISABLED\"},\"kubernetes\":{\"auditLogs\":{\"status\":\"DISABLED\"}},\"malwareProtection\":{\"scanEc2InstanceWithFindings\":{\"ebsVolumes\":{\"status\":\"DISABLED\",\"reason\":null}},\"serviceRole\":null}}",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__dataSourcesJson__c" : "{\"cloudTrail\":{\"status\":\"ENABLED\"},\"dnsLogs\":{\"status\":\"ENABLED\"},\"flowLogs\":{\"status\":\"ENABLED\"},\"s3Logs\":{\"status\":\"DISABLED\"},\"kubernetes\":{\"auditLogs\":{\"status\":\"ENABLED\"}},\"malwareProtection\":{\"scanEc2InstanceWithFindings\":{\"ebsVolumes\":{\"status\":\"DISABLED\",\"reason\":null}},\"serviceRole\":null}}",
    "Id" : "test2"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsGuardDutyDetector__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__dataSourcesJson__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  OPTIONS (library=['gs://compliance-platform-public/jmespath.min.js'])
  AS r"""
  var BytesLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg;
      };
      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 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 jsonQueryChecked2() {
          var input = extract4.call(extract4);
          var out;
          try {
              out = jmespath.search(input, 'kubernetes.auditLogs.status');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status').isResultTypeMismatch()", currentStateMessage: "Json query text did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:104", {cause: {status: 'UNDETERMINED', conditionIndex: 104, conditionText: "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status').isEvaluationFailed()", currentStateMessage: "Json query text has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked5() {
          var input = extract7.call(extract7);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "extract('CA10__dataSourcesJson__c').asJson().isInvalid()", currentStateMessage: "The Data Sources JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked8() {
          if (BytesLib.isEmpty(obj.CA10__dataSourcesJson__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__dataSourcesJson__c.delegatedTo(CA10__dataSourcesJson__c).isEmpty()", currentStateMessage: "The Data Sources cannot be empty. Possible permission issue with guardduty:GetDetector.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__dataSourcesJson__c;
      }
      function extract7() { if (!this.out) { this.out = fieldChecked8(); } return this.out; };
      function extract4() { if (!this.out) { this.out = jsonChecked5(); } return this.out; };
      references1.push('Data Sources JSON [obj.CA10__dataSourcesJson__c]: ' + obj.CA10__dataSourcesJson__c);
      try {
          if (TextLib.equal(jsonQueryChecked2(), 'DISABLED')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status') == 'DISABLED'", currentStateMessage: "GuardDuty EKS Audit Log Monitoring is disabled.", currentStateReferences: references1.join('\n'), remediation: "Enable EKS Audit Log Monitoring in the GuardDuty data sources settings.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function jsonQueryChecked9() {
          var input = extract11.call(extract11);
          var out;
          try {
              out = jmespath.search(input, 'kubernetes.auditLogs.status');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status').isResultTypeMismatch()", currentStateMessage: "Json query text did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status').isEvaluationFailed()", currentStateMessage: "Json query text has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked12() {
          var input = extract14.call(extract14);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "extract('CA10__dataSourcesJson__c').asJson().isInvalid()", currentStateMessage: "The Data Sources JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked15() {
          if (BytesLib.isEmpty(obj.CA10__dataSourcesJson__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__dataSourcesJson__c.delegatedTo(CA10__dataSourcesJson__c).isEmpty()", currentStateMessage: "The Data Sources cannot be empty. Possible permission issue with guardduty:GetDetector.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__dataSourcesJson__c;
      }
      function extract14() { if (!this.out) { this.out = fieldChecked15(); } return this.out; };
      function extract11() { if (!this.out) { this.out = jsonChecked12(); } return this.out; };
      try {
          if (TextLib.equal(jsonQueryChecked9(), 'ENABLED')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('caJsonFrom__dataSourcesJson__c').jsonQueryText('kubernetes.auditLogs.status') == 'ENABLED'", currentStateMessage: "GuardDuty EKS Audit Log Monitoring is enabled.", 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: 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__dataSourcesJson__c AS CA10__dataSourcesJson__c,
          sObject.Id AS Id,
          process_CA10__CaAwsGuardDutyDetector__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__dataSourcesJson__c AS CA10__dataSourcesJson__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsGuardDutyDetector__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
