--- policy: /ce/ca/aws/waf/rule-group-without-rules logic: /ce/ca/aws/waf/rule-group-without-rules/prod.logic.yaml executionTime: 2026-06-06T12:03:29.759111416Z generationMs: 103 executionMs: 1092 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: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: "not(setOfText(['caAwsWafv2RuleGroupGlobal', 'caAwsWafv2RuleGroupRegional']).contains(RecordType.DeveloperName))" actual: "not(setOfText(['caAwsWafv2RuleGroupGlobal', 'caAwsWafv2RuleGroupRegional']).contains(RecordType.DeveloperName))" runtimeError: {} - id: test3 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 299 actual: 299 conditionText: expected: CA10A1__AWS_WAF_Rules__r.hasNo(COMPLIANT) actual: CA10A1__AWS_WAF_Rules__r.hasNo(COMPLIANT) runtimeError: {} - id: test4 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 300 actual: 300 conditionText: expected: otherwise actual: otherwise runtimeError: {} usedFiles: - path: /ce/ca/aws/waf/rule-group-without-rules/policy.yaml md5Hash: 364F618C170A78759A1C3A772DC9E488 content: | --- names: full: "AWS WAF Rule Group has no WAF Rules" contextual: "Rule Group has no WAF Rules" description: "Ensure that AWS WAF Rule Groups contain at least one rule. An empty\ \ rule group provides no traffic filtering and may indicate an incomplete\ \ configuration or an unused resource." type: "COMPLIANCE_POLICY" categories: - "SECURITY" frameworkMappings: - "/frameworks/cloudaware/resource-security/threat-protection" - "/frameworks/aws-fsbp-v1.0.0/waf/03" - "/frameworks/aws-fsbp-v1.0.0/waf/07" - "/frameworks/aws-well-architected/sec/05/03" similarPolicies: awsSecurityHub: - name: "[WAF.3] AWS WAF Classic Regional rule groups should have at least one rule" url: "https://docs.aws.amazon.com/securityhub/latest/userguide/waf-controls.html#waf-3" - name: "[WAF.7] AWS WAF Classic global rule groups should have at least one rule" url: "https://docs.aws.amazon.com/securityhub/latest/userguide/waf-controls.html#waf-7" - path: /ce/ca/aws/waf/rule-group-without-rules/prod.logic.yaml md5Hash: CE00448C865C80292B9F819B911A0771 content: | --- inputType: "CA10A1__CaAwsWafRuleGroup__c" recordTypes: - "caAwsWafv2RuleGroupGlobal" - "caAwsWafv2RuleGroupRegional" testData: - file: "test-data.json" conditions: - status: "INCOMPLIANT" currentStateMessage: "The AWS WAF rule group does not have any rules." remediationMessage: "Add at least one rule to the rule group or deleting it if it is not needed." check: RELATED_LIST_HAS_NO: status: "COMPLIANT" relationshipName: "CA10A1__AWS_WAF_Rules__r" otherwise: status: "COMPLIANT" currentStateMessage: "The AWS WAF rule group has at least one rule." relatedLists: - relationshipName: "CA10A1__AWS_WAF_Rules__r" conditions: [] otherwise: status: "COMPLIANT" currentStateMessage: "This is a rule within the group." - path: /ce/ca/aws/waf/rule-group-without-rules/test-data.json md5Hash: C6413B03EB5163B704CF13D817D57864 content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2025-10-24T05:35:18Z" }, "CA10A1__disappearanceTime__c": "2025-10-24T05:35:18Z", "Id": "test1", "RecordTypeId": "RecordTypeId1", "RecordType": { "DeveloperName": "caAwsWafRuleGroupRegional", "Id": "RecordTypeId1" }, "CA10A1__AWS_WAF_Rules__r": [] }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "not(setOfText(['caAwsWafv2RuleGroupGlobal', 'caAwsWafv2RuleGroupRegional']).contains(RecordType.DeveloperName))", "runtimeError": null }, "context": { "snapshotTime": "2025-10-24T05:35:18Z" }, "CA10A1__disappearanceTime__c": null, "Id": "test2", "RecordTypeId": "RecordTypeId1", "RecordType": { "DeveloperName": "caAwsWafRuleGroupRegional", "Id": "RecordTypeId1" }, "CA10A1__AWS_WAF_Rules__r": [] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "299", "conditionText": "CA10A1__AWS_WAF_Rules__r.hasNo(COMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2025-10-24T05:35:18Z" }, "CA10A1__disappearanceTime__c": null, "Id": "test3", "RecordTypeId": "RecordTypeId2", "RecordType": { "DeveloperName": "caAwsWafv2RuleGroupRegional", "Id": "RecordTypeId2" }, "CA10A1__AWS_WAF_Rules__r": [] }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "300", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2025-10-24T05:35:18Z" }, "CA10A1__disappearanceTime__c": null, "Id": "test4", "RecordTypeId": "RecordTypeId2", "RecordType": { "DeveloperName": "caAwsWafv2RuleGroupRegional", "Id": "RecordTypeId2" }, "CA10A1__AWS_WAF_Rules__r": [ { "CA10__disappearanceTime__c": null, "CA10A1__ruleGroup__c": "test4", "Id": "test4_1", "RecordTypeId": "RecordTypeId2_1", "RecordType": { "Id": "RecordTypeId2_1" } } ] } ] script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "test1", "expectedResult" : { "status" : "DISAPPEARED", "conditionIndex" : "99", "conditionText" : "isDisappeared(CA10A1__disappearanceTime__c)", "runtimeError" : null } }, { "Id" : "test2", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "199", "conditionText" : "not(setOfText(['caAwsWafv2RuleGroupGlobal', 'caAwsWafv2RuleGroupRegional']).contains(RecordType.DeveloperName))", "runtimeError" : null } }, { "Id" : "test3", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "299", "conditionText" : "CA10A1__AWS_WAF_Rules__r.hasNo(COMPLIANT)", "runtimeError" : null } }, { "Id" : "test4", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "300", "conditionText" : "otherwise", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10A1__CaAwsWafRuleGroup__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "CA10A1__disappearanceTime__c" : new Date("2025-10-24T05:35:18Z"), "Id" : "test1", "RecordTypeId" : "RecordTypeId1" }, { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "Id" : "test2", "RecordTypeId" : "RecordTypeId1" }, { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "Id" : "test3", "RecordTypeId" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "Id" : "test4", "RecordTypeId" : "RecordTypeId2" } ]; """; CREATE TEMP FUNCTION mock_RecordType() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "DeveloperName" : "caAwsWafRuleGroupRegional", "Id" : "RecordTypeId1" }, { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "DeveloperName" : "caAwsWafv2RuleGroupRegional", "Id" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "Id" : "RecordTypeId2_1" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsWafRule__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-10-24T05:35:18Z") }, "CA10A1__ruleGroup__c" : "test4", "Id" : "test4_1", "RecordTypeId" : "RecordTypeId2_1" } ]; """; CREATE TEMP FUNCTION process_CA10A1__CaAwsWafRuleGroup__c( obj STRUCT< CA10A1__disappearanceTime__c TIMESTAMP, RecordType STRUCT< DeveloperName STRING, Id STRING >, CA10A1__AWS_WAF_Rules__r ARRAY, result STRUCT >>, Id STRING, RecordTypeId STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var CollectionLib = new function () { this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) { if (arg == null) return []; let parts = arg.split(separator); return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize); }; this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) { if (arr == null) return []; let result = []; let seen = new Set(); arr.forEach(el => { let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el); if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) { if (!skipDuplicates || !seen.has(normalized)) { if (skipDuplicates) seen.add(normalized); result.push(normalized); } } }); if (sort) result.sort(); return result; }; this.equal = function(left, right) { left = left == null ? [] : left; right = right == null ? [] : right; if (left.length !== right.length) return false; for (let i = 0; i < left.length; i++) { if (left[i] !== right[i]) return false; } return true; }; this.notEqual = function(left, right) { return !this.equal(left, right); }; this.size = function(collection) { return collection == null ? 0 : collection.length; }; this.startsWith = function(collection, search, normalize) { if (collection == null || collection.length === 0) return false; let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search); return collection[0] === normalizedSearch; }; this.endsWith = function(collection, search, normalize) { if (collection == null || collection.length === 0) return false; let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search); return collection[collection.length - 1] === normalizedSearch; }; this.contains = function(collection, search, normalize) { if (collection == null || collection.length === 0) return false; return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)); }; this.containsAll = function(collection, searchArray, normalize) { if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false; return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search))); }; this.containsAny = function(collection, searchArray, normalize) { if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false; return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search))); }; }(); 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 [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] references1.push('Record Type Name [obj.RecordType.DeveloperName]: ' + obj.RecordType.DeveloperName); if (!CollectionLib.contains(CollectionLib.fromArray(['caAwsWafv2RuleGroupGlobal', 'caAwsWafv2RuleGroupRegional'], true, true, true, true), obj.RecordType.DeveloperName, true)) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(setOfText(['caAwsWafv2RuleGroupGlobal', 'caAwsWafv2RuleGroupRegional']).contains(RecordType.DeveloperName))", currentStateMessage: "Object record type is not applicable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10A1__AWS_WAF_Rules__r_COMPLIANT3 = 0; if (obj.CA10A1__AWS_WAF_Rules__r != null) { for (var i4 = 0; i4 < obj.CA10A1__AWS_WAF_Rules__r.length; i4++) { if (typeof(obj.CA10A1__AWS_WAF_Rules__r[i4].status) !== 'undefined') { if (obj.CA10A1__AWS_WAF_Rules__r[i4].status == 'COMPLIANT') { count_CA10A1__AWS_WAF_Rules__r_COMPLIANT3 += obj.CA10A1__AWS_WAF_Rules__r[i4].count; } } else { if (obj.CA10A1__AWS_WAF_Rules__r[i4].result.status == 'COMPLIANT') { count_CA10A1__AWS_WAF_Rules__r_COMPLIANT3 += 1; } } } } // condition[2], conditionIndex:[200..299] references1.push('Related list [CA10A1__AWS_WAF_Rules__r] ' + (count_CA10A1__AWS_WAF_Rules__r_COMPLIANT3 == 0 ? 'does not have' : 'has') + ' objects in COMPLIANT status'); if (count_CA10A1__AWS_WAF_Rules__r_COMPLIANT3 == 0) { return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10A1__AWS_WAF_Rules__r.hasNo(COMPLIANT)", currentStateMessage: "The AWS WAF rule group does not have any rules.", currentStateReferences: references1.join('\n'), remediation: "Add at least one rule to the rule group or deleting it if it is not needed.", runtimeError: null}; } return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The AWS WAF rule group has at least one rule.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10A1__AWS_WAF_Rules__r( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10A1__ruleGroup__c STRING, Id STRING, RecordTypeId STRING, RecordType STRUCT< Id STRING > >, snapshotTime TIMESTAMP ) RETURNS STRUCT 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}; } return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "This is a rule within the group.", 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.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c, STRUCT ( `RecordType`.DeveloperName AS DeveloperName, `RecordType`.Id AS Id ) AS RecordType, `CA10A1__AWS_WAF_Rules__r`.arr AS CA10A1__AWS_WAF_Rules__r, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, process_CA10A1__CaAwsWafRuleGroup__c( STRUCT( sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c, STRUCT ( `RecordType`.DeveloperName AS DeveloperName, `RecordType`.Id AS Id ) AS RecordType, `CA10A1__AWS_WAF_Rules__r`.arr AS CA10A1__AWS_WAF_Rules__r, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10A1__CaAwsWafRuleGroup__c()) AS sObject LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType` ON sObject.RecordTypeId = `RecordType`.Id LEFT JOIN ( SELECT sObject.CA10A1__ruleGroup__c, ARRAY_AGG( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10A1__ruleGroup__c AS CA10A1__ruleGroup__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType, process_CA10A1__AWS_WAF_Rules__r( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10A1__ruleGroup__c AS CA10A1__ruleGroup__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaAwsWafRule__c()) AS sObject LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType` ON sObject.RecordTypeId = `RecordType`.Id GROUP BY sObject.CA10A1__ruleGroup__c ) AS `CA10A1__AWS_WAF_Rules__r` ON sObject.Id = `CA10A1__AWS_WAF_Rules__r`.CA10A1__ruleGroup__c ) sObject ON sObject.Id = expectedResult.Id;