# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # wafv2_rulegroup_not_empty_check # # Description: # This control checks whether AWS WAF rule groups contain rules. # # Reports on: # AWS::WAFv2::RuleGroup # # Evaluates: # AWS CloudFormation, AWS CloudFormation hook # # Rule Parameters: # None # # Scenarios: # Scenario: 1 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document does not contain any WAF rule group resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an WAF rule group resource # And: 'Rules' has not been provided # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an WAF rule group resource # And: 'Rules' has been provided as an empty list # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an WAF rule group resource # And: 'Rules' has been provided as a non-empty list # Then: PASS # # Constants # let WAFV2_RULE_GROUP_TYPE = "AWS::WAFv2::RuleGroup" let INPUT_DOCUMENT = this # # Assignments # let wafv2_rule_groups = Resources.*[ Type == %WAFV2_RULE_GROUP_TYPE ] # # Primary Rules # rule wafv2_rulegroup_not_empty_check when is_cfn_template(%INPUT_DOCUMENT) %wafv2_rule_groups not empty { check(%wafv2_rule_groups.Properties) << [CT.WAFV2.PR.2]: Require an AWS WAF rule group to be non-empty [FIX]: Provide one or more AWS WAF rules within the 'Rules' property. >> } rule wafv2_rulegroup_not_empty_check when is_cfn_hook(%INPUT_DOCUMENT, %WAFV2_RULE_GROUP_TYPE) { check(%INPUT_DOCUMENT.%WAFV2_RULE_GROUP_TYPE.resourceProperties) << [CT.WAFV2.PR.2]: Require an AWS WAF rule group to be non-empty [FIX]: Provide one or more AWS WAF rules within the 'Rules' property. >> } # # Parameterized Rules # rule check(wafv2_rule_group) { %wafv2_rule_group { # Scenario 2, 3 and 4 Rules exists Rules is_list Rules not empty } } # # Utility Rules # rule is_cfn_template(doc) { %doc { AWSTemplateFormatVersion exists or Resources exists } } rule is_cfn_hook(doc, RESOURCE_TYPE) { %doc.%RESOURCE_TYPE.resourceProperties exists }