Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKV_AWS_192: fails to recognize AWSManagedRulesKnownBadInputRuleSet as properly configured when using a dynamic configuration #6886

Open
avazula opened this issue Dec 2, 2024 · 1 comment
Labels
checks Check additions or changes

Comments

@avazula
Copy link

avazula commented Dec 2, 2024

Opening this issue which apparently stems from the same problem as described in this issue which got closed due to inactivity.

Describe the issue

Related to Terraform:
checkov fails to recognize that the rule set AWSManagedRulesKnownBadInputRuleSet is configured in a WAF web ACL if the rules configuration is set using dynamic blocks.

The other issue mentioned in the one linked above mentions input cast. Please note that I encounter the issue both when priority is set as a string or as a number (I even tried explicit cast using number()).

It also mentions that the problem could be caused by the fact that the configuration is coming from locals. I tried passing it a variable and encountered the same problem.

Examples

// other config of resource "aws_wafv2_web_acl" ...
dynamic "rule" {
    for_each = var.waf_acl_rules == null ? local.waf_acl_default_rules : var.waf_acl_rules
    content {
      name     = rule.value.name
      priority = rule.value.priority
      dynamic "override_action" {
        for_each = lookup(rule.value, "override_action", null) == null ? [] : [lookup(rule.value, "override_action")]
        content {
          dynamic "count" {
            for_each = override_action.value == "count" ? ["1"] : []
            content {}
          }
          dynamic "none" {
            for_each = override_action.value == "none" ? ["1"] : []
            content {}
          }
        }
      }
      statement {
        managed_rule_group_statement {
          name        = rule.value.managed_rule_group_statement_name
          vendor_name = rule.value.managed_rule_group_statement_vendor_name
        }
      }
      visibility_config {
        cloudwatch_metrics_enabled = rule.value.cloudwatch_metrics_enabled
        metric_name                = rule.value.cloudwatch_metric_name
        sampled_requests_enabled   = rule.value.sampled_requests_enabled
      }
    }
  }

With the rules config defined as such:

locals {
  waf_acl_default_rules = [ # also fails if passed as a variable instead of a local value
    // other rules ...
    {
      name                                     = "AWSManagedRulesKnownBadInputsRuleSet"
      priority                                 = 2 # also fails when equal to "2"
      override_action                          = "none"
      managed_rule_group_statement_name        = "AWSManagedRulesKnownBadInputsRuleSet"
      managed_rule_group_statement_vendor_name = "AWS"
      cloudwatch_metrics_enabled               = true
      cloudwatch_metric_name                   = "AWSManagedRulesKnownBadInputsRuleSet"
      sampled_requests_enabled                 = true
    }
  ]
}

Looking at the code I'm not sure what could be causing it.

Version (please complete the following information):

  • Checkov Version [e.g. 22]
    3.2.293

Additional context

Terraform version: 1.9.2
AWS provider version: 5.77.0

@avazula avazula added the checks Check additions or changes label Dec 2, 2024
@avazula
Copy link
Author

avazula commented Dec 2, 2024

FYI, I am encountering the same issue for CKV2_AWS_47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checks Check additions or changes
Projects
None yet
Development

No branches or pull requests

1 participant