-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix: WAF rule logic #900
Merged
Merged
fix: WAF rule logic #900
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Staging: load_balancer✅ Terraform Init: Plan: 0 to add, 1 to change, 0 to destroy Show summary
Show planResource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# aws_wafv2_web_acl.forms_acl will be updated in-place
~ resource "aws_wafv2_web_acl" "forms_acl" {
id = "e8fc1b67-9d4d-4a29-8c94-65b37b30a231"
name = "GCForms"
tags = {}
# (9 unchanged attributes hidden)
- rule {
- name = "AllowOnlyAppUrls" -> null
- priority = 60 -> null
- action {
- block {
}
}
- statement {
- not_statement {
- statement {
- and_statement {
- statement {
- byte_match_statement {
- positional_constraint = "EXACTLY" -> null
- search_string = "forms-staging.cdssandbox.xyz" -> null
- field_to_match {
- single_header {
- name = "host" -> null
}
}
- text_transformation {
- priority = 1 -> null
- type = "LOWERCASE" -> null
}
}
}
- statement {
- regex_pattern_set_reference_statement {
- arn = "arn:aws:wafv2:ca-central-1:687401027353:regional/regexpatternset/valid_app_uri_paths/2020c3bc-eb87-45f3-8ee7-99cd707612e7" -> null
- field_to_match {
- uri_path {}
}
- text_transformation {
- priority = 1 -> null
- type = "COMPRESS_WHITE_SPACE" -> null
}
- text_transformation {
- priority = 2 -> null
- type = "LOWERCASE" -> null
}
}
}
}
}
}
}
- visibility_config {
- cloudwatch_metrics_enabled = true -> null
- metric_name = "AllowOnlyAppUrls" -> null
- sampled_requests_enabled = false -> null
}
}
- rule {
- name = "AWSManagedRulesAmazonIpReputationList" -> null
- priority = 1 -> null
- override_action {
- none {}
}
- statement {
- managed_rule_group_statement {
- name = "AWSManagedRulesAmazonIpReputationList" -> null
- vendor_name = "AWS" -> null
# (1 unchanged attribute hidden)
}
}
- visibility_config {
- cloudwatch_metrics_enabled = true -> null
- metric_name = "AWSManagedRulesAmazonIpReputationList" -> null
- sampled_requests_enabled = true -> null
}
}
- rule {
- name = "AWSManagedRulesKnownBadInputsRuleSet" -> null
- priority = 40 -> null
- override_action {
- none {}
}
- statement {
- managed_rule_group_statement {
- name = "AWSManagedRulesKnownBadInputsRuleSet" -> null
- vendor_name = "AWS" -> null
# (1 unchanged attribute hidden)
}
}
- visibility_config {
- cloudwatch_metrics_enabled = true -> null
- metric_name = "AWSManagedRulesKnownBadInputsRuleSet" -> null
- sampled_requests_enabled = true -> null
}
}
- rule {
- name = "AWSManagedRulesLinuxRuleSet" -> null
- priority = 50 -> null
- override_action {
- none {}
}
- statement {
- managed_rule_group_statement {
- name = "AWSManagedRulesLinuxRuleSet" -> null
- vendor_name = "AWS" -> null
# (1 unchanged attribute hidden)
}
}
- visibility_config {
- cloudwatch_metrics_enabled = true -> null
- metric_name = "AWSManagedRulesLinuxRuleSet" -> null
- sampled_requests_enabled = true -> null
}
}
+ rule {
+ name = "AllowOnlyApiUrls"
+ priority = 65
+ action {
+ block {
}
}
+ statement {
+ and_statement {
+ statement {
+ byte_match_statement {
+ positional_constraint = "EXACTLY"
+ search_string = "api.forms-staging.cdssandbox.xyz"
+ field_to_match {
+ single_header {
+ name = "host"
}
}
+ text_transformation {
+ priority = 1
+ type = "LOWERCASE"
}
}
}
+ statement {
+ not_statement {
+ statement {
+ regex_pattern_set_reference_statement {
+ arn = "arn:aws:wafv2:ca-central-1:687401027353:regional/regexpatternset/valid_api_uri/3d646d8d-b357-4b54-9fe4-0083273f7989"
+ field_to_match {
+ uri_path {}
}
+ text_transformation {
+ priority = 1
+ type = "COMPRESS_WHITE_SPACE"
}
+ text_transformation {
+ priority = 2
+ type = "LOWERCASE"
}
}
}
}
}
}
}
+ visibility_config {
+ cloudwatch_metrics_enabled = true
+ metric_name = "AllowOnlyApiUrls"
+ sampled_requests_enabled = false
}
}
+ rule {
+ name = "AllowOnlyAppUrls"
+ priority = 60
+ action {
+ block {
}
}
+ statement {
+ and_statement {
+ statement {
+ byte_match_statement {
+ positional_constraint = "EXACTLY"
+ search_string = "forms-staging.cdssandbox.xyz"
+ field_to_match {
+ single_header {
+ name = "host"
}
}
+ text_transformation {
+ priority = 1
+ type = "LOWERCASE"
}
}
}
+ statement {
+ not_statement {
+ statement {
+ regex_pattern_set_reference_statement {
+ arn = "arn:aws:wafv2:ca-central-1:687401027353:regional/regexpatternset/valid_app_uri_paths/2020c3bc-eb87-45f3-8ee7-99cd707612e7"
+ field_to_match {
+ uri_path {}
}
+ text_transformation {
+ priority = 1
+ type = "COMPRESS_WHITE_SPACE"
}
+ text_transformation {
+ priority = 2
+ type = "LOWERCASE"
}
}
}
}
}
}
}
+ visibility_config {
+ cloudwatch_metrics_enabled = true
+ metric_name = "AllowOnlyAppUrls"
+ sampled_requests_enabled = false
}
}
+ rule {
+ name = "AWSManagedRulesAmazonIpReputationList"
+ priority = 1
+ override_action {
+ none {}
}
+ statement {
+ managed_rule_group_statement {
+ name = "AWSManagedRulesAmazonIpReputationList"
+ vendor_name = "AWS"
}
}
+ visibility_config {
+ cloudwatch_metrics_enabled = true
+ metric_name = "AWSManagedRulesAmazonIpReputationList"
+ sampled_requests_enabled = true
}
}
+ rule {
+ name = "AWSManagedRulesKnownBadInputsRuleSet"
+ priority = 40
+ override_action {
+ none {}
}
+ statement {
+ managed_rule_group_statement {
+ name = "AWSManagedRulesKnownBadInputsRuleSet"
+ vendor_name = "AWS"
}
}
+ visibility_config {
+ cloudwatch_metrics_enabled = true
+ metric_name = "AWSManagedRulesKnownBadInputsRuleSet"
+ sampled_requests_enabled = true
}
}
+ rule {
+ name = "AWSManagedRulesLinuxRuleSet"
+ priority = 50
+ override_action {
+ none {}
}
+ statement {
+ managed_rule_group_statement {
+ name = "AWSManagedRulesLinuxRuleSet"
+ vendor_name = "AWS"
}
}
+ visibility_config {
+ cloudwatch_metrics_enabled = true
+ metric_name = "AWSManagedRulesLinuxRuleSet"
+ sampled_requests_enabled = true
}
}
# (7 unchanged blocks hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
─────────────────────────────────────────────────────────────────────────────
Saved the plan to: plan.tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "plan.tfplan"
Show Conftest resultsWARN - plan.json - main - Missing Common Tags: ["aws_acm_certificate.form_viewer"]
WARN - plan.json - main - Missing Common Tags: ["aws_acm_certificate.form_viewer_maintenance_mode"]
WARN - plan.json - main - Missing Common Tags: ["aws_acm_certificate.forms_api"]
WARN - plan.json - main - Missing Common Tags: ["aws_alb_listener_rule.forms_api"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudfront_distribution.maintenance_mode"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.firehose_waf_logs"]
WARN - plan.json - main - Missing Common Tags: ["aws_kinesis_firehose_delivery_stream.firehose_waf_logs"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb.form_viewer"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb_listener.form_viewer_http"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb_listener.form_viewer_https"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb_target_group.form_viewer_1"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb_target_group.form_viewer_2"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb_target_group.forms_api"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_bucket.maintenance_mode"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_object.maintenance_static_page_css_files[\"style.css\"]"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_object.maintenance_static_page_html_files[\"index-fr.html\"]"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_object.maintenance_static_page_html_files[\"index.html\"]"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_object.maintenance_static_page_ico_files[\"favicon.ico\"]"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_object.maintenance_static_page_svg_files[\"site-unavailable.svg\"]"]
WARN - plan.json - main - Missing Common Tags: ["aws_shield_protection.alb"]
WARN - plan.json - main - Missing Common Tags: ["aws_shield_protection.route53_hosted_zone[0]"]
WARN - plan.json - main - Missing... |
craigzour
approved these changes
Nov 22, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary | Résumé
The previous logic was such that although an APP or API path was valid it would be blocked by the opposing service rule.
This fixes the logic to be:
service_url && !uri
instead of!(service_url && uri)
app && !uri
app = true && uri = false = block
app = false && uri = true = allow
app = true && uri = true = allow
app = false && uri = false = allow
and
api && !uri
api = true && uri = false = block
api = false && uri = true = allow
api = true && uri = true = allow
api = false && uri = false = allow
Test instructions | Instructions pour tester la modification
Have faith in my logic deduction abilities on a Friday morning running on only 2 cups of coffee.