waf.tf 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # trussworks/wafv2/aws has a basic WAF with the AWS Managed Ruleset
  2. # See https://registry.terraform.io/modules/trussworks/wafv2/aws/latest
  3. #
  4. # Attempted to add some sane defaults so we can customize as needed
  5. resource "aws_wafv2_ip_set" "ipset" {
  6. name = "blocked_ips"
  7. scope = "REGIONAL"
  8. ip_address_version = "IPV4"
  9. addresses = [
  10. ]
  11. }
  12. module "wafv2" {
  13. source = "trussworks/wafv2/aws"
  14. version = "~> 2.0"
  15. name = local.alb_name
  16. scope = "REGIONAL"
  17. alb_arn = aws_lb.searchhead-alb.arn
  18. associate_alb = true
  19. ip_sets_rule = [
  20. {
  21. name = "blocked_ips"
  22. action = "block"
  23. priority = 1
  24. ip_set_arn = aws_wafv2_ip_set.ipset.arn
  25. }
  26. ]
  27. # A rate-based rule tracks the rate of requests for each originating IP address, and triggers the rule action when the rate exceeds a limit that you specify on the number of requests in any 5-minute time span
  28. ip_rate_based_rule = {
  29. name = "Rate_Limit"
  30. priority = 5
  31. limit = 900 # 900 requests per 5 minutes= 3 requests/second (sustained for 5 minutes)
  32. action = "block"
  33. }
  34. tags = merge(var.standard_tags, var.tags)
  35. }
  36. resource "aws_wafv2_web_acl_logging_configuration" "waf_logs" {
  37. log_destination_configs = [ "arn:${var.aws_partition}:firehose:${var.aws_region}:${var.aws_account_id}:deliverystream/aws-waf-logs-splunk" ]
  38. resource_arn = module.wafv2.web_acl_id
  39. # logging_filter {
  40. # default_behavior = "KEEP"
  41. #
  42. # filter {
  43. # behavior = "DROP"
  44. #
  45. # condition {
  46. # action_condition {
  47. # action = "COUNT"
  48. # }
  49. # }
  50. #
  51. # condition {
  52. # label_name_condition {
  53. # label_name = "awswaf:111122223333:rulegroup:testRules:LabelNameZ"
  54. # }
  55. # }
  56. #
  57. # requirement = "MEETS_ALL"
  58. # }
  59. #
  60. # filter {
  61. # behavior = "KEEP"
  62. #
  63. # condition {
  64. # action_condition {
  65. # action = "ALLOW"
  66. # }
  67. # }
  68. #
  69. # requirement = "MEETS_ANY"
  70. # }
  71. # }
  72. }