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

add: missing NOT regex_pattern_set_reference_statement dynamic blocks #123

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

viktord
Copy link

@viktord viktord commented Oct 3, 2023

Description

When using and_statement within rate_based_statement we cannot add negated regex_pattern_set_reference_statement cause the corresponding dynamic block is missing.

Example:

  rules = [
    {
      name     = "example_rate_limit"
      priority = "3"

      action = "count"

      visibility_config = {
        cloudwatch_metrics_enabled = true
        metric_name                = "example_rate_limit"
        sampled_requests_enabled   = true
      }

      rate_based_statement = {
        limit              = 3000
        aggregate_key_type = "IP"
        scope_down_statement = {
          and_statement = {
            statements = [
              {
                byte_match_statement = {
                  field_to_match = {
                    single_header = {
                      name = "Host"
                    }
                  }
                  positional_constraint = "STARTS_WITH"
                  search_string         = "example."
                  priority              = 0
                  type                  = "NONE"
                }
              },
              {
                not_statement = {
                  regex_pattern_set_reference_statement = {
                    arn = aws_wafv2_regex_pattern_set.example.arn
                    field_to_match = {
                      uri_path = "{}"
                    }
                    priority = 0
                    type     = "LOWERCASE"
                  }
                }
              }
            ]
          }
        }
      }
    }
  ]

produces:

      + rule {
          + name     = "example_rate_limit"
          + priority = 3

          + action {
              + count {
                }
            }

          + statement {
              + rate_based_statement {
                  + aggregate_key_type = "IP"
                  + limit              = 3000

                  + scope_down_statement {
                      + and_statement {
                          + statement {
                              + byte_match_statement {
                                  + positional_constraint = "STARTS_WITH"
                                  + search_string         = "example."

                                  + field_to_match {
                                    }

                                  + text_transformation {
                                      + priority = 0
                                      + type     = "NONE"
                                    }
                                }
                            }
                          + statement {
                              + not_statement {
                                  + statement {
                                    }
                                }
                            }
                        }
                    }
                }
            }

Also added:

  • custom_key block (was missing)
  • size_constraint_statement block in and_statement

@tmiller
Copy link

tmiller commented Mar 23, 2024

This seems to be working for me.

@viktord
Copy link
Author

viktord commented Mar 26, 2024

@Ohid25 ready for merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants