--- policy: /ce/ca/aws/guardduty/detector-not-enabled-in-all-regions logic: /ce/ca/aws/guardduty/detector-not-enabled-in-all-regions/prod.logic.yaml executionTime: 2026-06-06T12:02:58.283786051Z generationMs: 58 executionMs: 1190 rows: - id: test1 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 199 actual: 199 conditionText: expected: CA10__AWS_GuardDuty_Detectors__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT) actual: CA10__AWS_GuardDuty_Detectors__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT) 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/guardduty/detector-not-enabled-in-all-regions/policy.yaml md5Hash: 2AC5953FDAE40B12D5B5F5F3A2DC611E content: "---\nnames:\n full: \"AWS GuardDuty is not enabled in all regions\"\ \n contextual: \"GuardDuty is not enabled in all regions\"\ndescription: >\n\ \ Amazon GuardDuty is a threat detection service that continuously monitors\ \ for \n malicious activity and unauthorized behavior to protect your AWS accounts\ \ and \n workloads. It is recommended that GuardDuty be enabled in all supported\ \ AWS regions \n to ensure comprehensive threat coverage.\ntype: \"COMPLIANCE_POLICY\"\ \ncategories:\n - \"SECURITY\"\nframeworkMappings:\n - \"/frameworks/cloudaware/resource-security/threat-protection\"\ \n - \"/frameworks/aws-well-architected/sec/04/03\"\n - \"/frameworks/aws-well-architected/sec/04/04\"\ \n - \"/frameworks/aws-well-architected/sec/05/03\"\n - \"/frameworks/aws-well-architected/sec/05/04\"\ \n - \"/frameworks/aws-fsbp-v1.0.0/guardduty/01\"\nsimilarPolicies:\n awsSecurityHub:\n\ \ - name: \"[GuardDuty.1] GuardDuty should be enabled\"\n url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/guardduty-controls.html#guardduty-1\"" - path: /ce/ca/aws/guardduty/detector-not-enabled-in-all-regions/prod.logic.yaml md5Hash: 0ECC75C5C45128375D2C54CD404A13D4 content: | --- inputType: "CA10__CaAwsAccount__c" testData: - file: "test-data.json" conditions: - status: "COMPLIANT" currentStateMessage: "GuardDuty is enabled for all active regions." check: IS_EQUAL: left: RELATED_LIST_COUNT: status: "COMPLIANT" relationshipName: "CA10__AWS_GuardDuty_Detectors__r" right: RELATED_LIST_COUNT: status: "COMPLIANT" relationshipName: "CA10__AWS_Account_Regions__r" otherwise: status: "INCOMPLIANT" currentStateMessage: "GuardDuty is not enabled for all active regions." remediationMessage: "Enable GuardDuty in each active region to ensure full threat detection coverage." relatedLists: - relationshipName: "CA10__AWS_GuardDuty_Detectors__r" importExtracts: - file: /types/CA10__CaAwsGuardDutyDetector__c/object.extracts.yaml conditions: - status: "COMPLIANT" currentStateMessage: "Active AWS GuardDuty detector." check: IS_EQUAL: left: EXTRACT: "CA10__status__c" right: TEXT: "ENABLED" otherwise: status: "INAPPLICABLE" currentStateMessage: "This GuardDuty detector is not active." - relationshipName: "CA10__AWS_Account_Regions__r" importExtracts: - file: /types/CA10__CaAwsAccountRegion__c/object.extracts.yaml conditions: - status: "COMPLIANT" currentStateMessage: "Active AWS account region." check: NOT_EQUAL: left: EXTRACT: "CA10__status__c" right: TEXT: "not-opted-in" otherwise: status: "INAPPLICABLE" currentStateMessage: "This AWS account region is not active." - path: /ce/ca/aws/guardduty/detector-not-enabled-in-all-regions/test-data.json md5Hash: 5D71D7D67F6EBA69009EBC0864D0E188 content: |- [ { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "199", "conditionText": "CA10__AWS_GuardDuty_Detectors__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2025-10-08T06:14:51Z" }, "Id": "test1", "CA10__AWS_GuardDuty_Detectors__r": [ { "CA10__disappearanceTime__c": null, "CA10__status__c": "ENABLED", "CA10__account__c": "test1", "Id": "test1_1" }, { "CA10__disappearanceTime__c": null, "CA10__status__c": "ENABLED", "CA10__account__c": "test1", "Id": "test1_2" } ], "CA10__AWS_Account_Regions__r": [ { "CA10__status__c": "opt-in", "CA10__account__c": "test1", "Id": "test1_3" }, { "CA10__status__c": "opt-in", "CA10__account__c": "test1", "Id": "test1_4" } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "200", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2025-10-08T06:14:51Z" }, "Id": "test2", "CA10__AWS_GuardDuty_Detectors__r": [ { "CA10__disappearanceTime__c": null, "CA10__status__c": "ENABLED", "CA10__account__c": "test2", "Id": "test2_1" } ], "CA10__AWS_Account_Regions__r": [ { "CA10__status__c": "opted-in", "CA10__account__c": "test2", "Id": "test2_2" }, { "CA10__status__c": "opted-in", "CA10__account__c": "test2", "Id": "test2_3" } ] } ] - path: /types/CA10__CaAwsAccountRegion__c/object.extracts.yaml md5Hash: B5D54D4844B8E77238E14E730ABEE3C4 content: "---\nextracts:\n - name: CA10__status__c\n value: \n FIELD:\n\ \ path: CA10__status__c\n undeterminedIf:\n isEmpty:\ \ \"Account Region status must be specified \"\n - name: CA10__ebsStorageEncryption__c\n\ \ value: \n FIELD:\n path: CA10__ebsStorageEncryption__c\n \ \ undeterminedIf:\n isEmpty: \"EBS Storage Encryption can not\ \ be empty. Possibly corrupted data.\"" - path: /types/CA10__CaAwsGuardDutyDetector__c/object.extracts.yaml md5Hash: 8B76173EB0902B7F969958A52EDB9AD5 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." - name: "CA10__featuresJson__c" value: FIELD: path: "CA10__featuresJson__c" undeterminedIf: noAccessDelegate: path: "CA10__featuresJson__c" currentStateMessage: "The Features cannot be empty. Possible permission issue with guardduty:GetDetector." - name: "caJsonFrom__featuresJson__c" value: JSON_FROM: arg: EXTRACT: "CA10__featuresJson__c" undeterminedIf: isInvalid: "The Data Sources JSON is invalid." script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "test1", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "199", "conditionText" : "CA10__AWS_GuardDuty_Detectors__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)", "runtimeError" : null } }, { "Id" : "test2", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "200", "conditionText" : "otherwise", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsGuardDutyDetector__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "CA10__status__c" : "ENABLED", "CA10__account__c" : "test1", "Id" : "test1_1" }, { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "CA10__status__c" : "ENABLED", "CA10__account__c" : "test1", "Id" : "test1_2" }, { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "CA10__status__c" : "ENABLED", "CA10__account__c" : "test2", "Id" : "test2_1" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsAccountRegion__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "CA10__status__c" : "opt-in", "CA10__account__c" : "test1", "Id" : "test1_3" }, { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "CA10__status__c" : "opt-in", "CA10__account__c" : "test1", "Id" : "test1_4" }, { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "CA10__status__c" : "opted-in", "CA10__account__c" : "test2", "Id" : "test2_2" }, { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "CA10__status__c" : "opted-in", "CA10__account__c" : "test2", "Id" : "test2_3" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsAccount__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "Id" : "test1" }, { "context" : { "snapshotTime" : new Date("2025-10-08T06:14:51Z") }, "Id" : "test2" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsAccount__c( obj STRUCT< CA10__AWS_GuardDuty_Detectors__r ARRAY >>, CA10__AWS_Account_Regions__r ARRAY >>, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var references1 = []; // condition[0], conditionIndex:[0..99] if (false) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10__AWS_GuardDuty_Detectors__r_COMPLIANT2 = 0; if (obj.CA10__AWS_GuardDuty_Detectors__r != null) { for (var i4 = 0; i4 < obj.CA10__AWS_GuardDuty_Detectors__r.length; i4++) { if (typeof(obj.CA10__AWS_GuardDuty_Detectors__r[i4].status) !== 'undefined') { if (obj.CA10__AWS_GuardDuty_Detectors__r[i4].status == 'COMPLIANT') { count_CA10__AWS_GuardDuty_Detectors__r_COMPLIANT2 += obj.CA10__AWS_GuardDuty_Detectors__r[i4].count; } } else { if (obj.CA10__AWS_GuardDuty_Detectors__r[i4].result.status == 'COMPLIANT') { count_CA10__AWS_GuardDuty_Detectors__r_COMPLIANT2 += 1; } } } } var count_CA10__AWS_Account_Regions__r_COMPLIANT3 = 0; if (obj.CA10__AWS_Account_Regions__r != null) { for (var i5 = 0; i5 < obj.CA10__AWS_Account_Regions__r.length; i5++) { if (typeof(obj.CA10__AWS_Account_Regions__r[i5].status) !== 'undefined') { if (obj.CA10__AWS_Account_Regions__r[i5].status == 'COMPLIANT') { count_CA10__AWS_Account_Regions__r_COMPLIANT3 += obj.CA10__AWS_Account_Regions__r[i5].count; } } else { if (obj.CA10__AWS_Account_Regions__r[i5].result.status == 'COMPLIANT') { count_CA10__AWS_Account_Regions__r_COMPLIANT3 += 1; } } } } // condition[1], conditionIndex:[100..199] references1.push('Related list [CA10__AWS_GuardDuty_Detectors__r] has ' + count_CA10__AWS_GuardDuty_Detectors__r_COMPLIANT2 + ' objects in COMPLIANT status'); references1.push('Related list [CA10__AWS_Account_Regions__r] has ' + count_CA10__AWS_Account_Regions__r_COMPLIANT3 + ' objects in COMPLIANT status'); if (count_CA10__AWS_GuardDuty_Detectors__r_COMPLIANT2 == count_CA10__AWS_Account_Regions__r_COMPLIANT3) { return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_GuardDuty_Detectors__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)", currentStateMessage: "GuardDuty is enabled for all active regions.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "GuardDuty is not enabled for all active regions.", currentStateReferences: references1.join('\n'), remediation: "Enable GuardDuty in each active region to ensure full threat detection coverage.", runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10__AWS_GuardDuty_Detectors__r( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__status__c STRING, CA10__account__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT 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.delegatedTo(CA10__status__c).isEmpty()", currentStateMessage: "The status cannot be empty. Possible permission issue with guardduty:GetDetector.", 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.equal(extract3.call(extract3), 'ENABLED')) { return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__status__c') == 'ENABLED'", currentStateMessage: "Active AWS GuardDuty detector.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'INAPPLICABLE', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This GuardDuty detector is not active.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10__AWS_Account_Regions__r( obj STRUCT< CA10__status__c STRING, CA10__account__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT 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] if (false) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", 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.delegatedTo(CA10__status__c).isEmpty()", currentStateMessage: "The status cannot be empty. Possible permission issue with guardduty:GetDetector.", 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), 'not-opted-in')) { return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'not-opted-in'", currentStateMessage: "Active AWS account region.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'INAPPLICABLE', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This AWS account region is not active.", 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 `CA10__AWS_GuardDuty_Detectors__r`.arr AS CA10__AWS_GuardDuty_Detectors__r, `CA10__AWS_Account_Regions__r`.arr AS CA10__AWS_Account_Regions__r, sObject.Id AS Id, process_CA10__CaAwsAccount__c( STRUCT( `CA10__AWS_GuardDuty_Detectors__r`.arr AS CA10__AWS_GuardDuty_Detectors__r, `CA10__AWS_Account_Regions__r`.arr AS CA10__AWS_Account_Regions__r, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsAccount__c()) AS sObject LEFT JOIN ( SELECT sObject.CA10__account__c, ARRAY_AGG( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__status__c AS CA10__status__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id, process_CA10__AWS_GuardDuty_Detectors__r( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__status__c AS CA10__status__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaAwsGuardDutyDetector__c()) AS sObject GROUP BY sObject.CA10__account__c ) AS `CA10__AWS_GuardDuty_Detectors__r` ON sObject.Id = `CA10__AWS_GuardDuty_Detectors__r`.CA10__account__c LEFT JOIN ( SELECT sObject.CA10__account__c, ARRAY_AGG( STRUCT( sObject.CA10__status__c AS CA10__status__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id, process_CA10__AWS_Account_Regions__r( STRUCT( sObject.CA10__status__c AS CA10__status__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaAwsAccountRegion__c()) AS sObject GROUP BY sObject.CA10__account__c ) AS `CA10__AWS_Account_Regions__r` ON sObject.Id = `CA10__AWS_Account_Regions__r`.CA10__account__c ) sObject ON sObject.Id = expectedResult.Id;