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

fix: enable blocking of calls to unauthorized endpoints #613

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

gcharest
Copy link
Contributor

@gcharest gcharest commented Aug 6, 2024

Summary | Résumé

Enable blocking calls to unauthorized endpoints

@gcharest gcharest requested a review from a team August 6, 2024 17:11
@gcharest gcharest self-assigned this Aug 6, 2024
Copy link

github-actions bot commented Aug 6, 2024

Production: terraform

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 1 to add, 2 to change, 0 to destroy
Show summary
CHANGE NAME
add aws_wafv2_web_acl_logging_configuration.sre-bot
update aws_iam_role.sre-bot
aws_wafv2_web_acl.sre-bot
Show plan
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place

Terraform will perform the following actions:

  # aws_iam_role.sre-bot will be updated in-place
  ~ resource "aws_iam_role" "sre-bot" {
      ~ assume_role_policy    = jsonencode(
          ~ {
              ~ Statement = [
                  ~ {
                      ~ Principal = {
                          - AWS     = "arn:aws:sts::283582579564:assumed-role/AWSReservedSSO_AWSAdministratorAccess_fdd017a84f0012e7/[email protected]" -> null
                            # (1 unchanged element hidden)
                        }
                        # (2 unchanged elements hidden)
                    },
                ]
                # (1 unchanged element hidden)
            }
        )
        id                    = "sre-bot-ecs-role"
        name                  = "sre-bot-ecs-role"
        tags                  = {
            "CostCentre" = "sre-bot"
        }
        # (8 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # aws_wafv2_web_acl.sre-bot will be updated in-place
  ~ resource "aws_wafv2_web_acl" "sre-bot" {
        id            = "2ea5ee5d-d7d8-46a4-a0a4-f59b67bd4c44"
        name          = "sre-bot"
        tags          = {
            "Name" = "sre-bot"
        }
        # (7 unchanged attributes hidden)

      + rule {
          + name     = "AuthorizedEndpoints"
          + priority = 6

          + action {

              + block {
                }
            }

          + statement {
              + and_statement {
                  + statement {

                      + not_statement {
                          + statement {

                              + byte_match_statement {
                                  + positional_constraint = "STARTS_WITH"
                                  + search_string         = "/login"

                                  + field_to_match {

                                      + uri_path {}
                                    }

                                  + text_transformation {
                                      + priority = 0
                                      + type     = "NORMALIZE_PATH"
                                    }
                                }
                            }
                        }
                    }
                  + statement {

                      + not_statement {
                          + statement {

                              + byte_match_statement {
                                  + positional_constraint = "STARTS_WITH"
                                  + search_string         = "/logout"

                                  + field_to_match {

                                      + uri_path {}
                                    }

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

                      + not_statement {
                          + statement {

                              + byte_match_statement {
                                  + positional_constraint = "STARTS_WITH"
                                  + search_string         = "/auth"

                                  + field_to_match {

                                      + uri_path {}
                                    }

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

                      + not_statement {
                          + statement {

                              + byte_match_statement {
                                  + positional_constraint = "STARTS_WITH"
                                  + search_string         = "/geolocate"

                                  + field_to_match {

                                      + uri_path {}
                                    }

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

                      + not_statement {
                          + statement {

                              + byte_match_statement {
                                  + positional_constraint = "STARTS_WITH"
                                  + search_string         = "/hook"

                                  + field_to_match {

                                      + uri_path {}
                                    }

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

                      + not_statement {
                          + statement {

                              + byte_match_statement {
                                  + positional_constraint = "STARTS_WITH"
                                  + search_string         = "/version"

                                  + field_to_match {

                                      + uri_path {}
                                    }

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

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "AuthorizedEndpoints"
              + sampled_requests_enabled   = true
            }
        }
      - rule {
          - name     = "AuthorizedEndpoints" -> null
          - priority = 6 -> null

          - action {

              - count {
                }
            }

          - statement {
              - and_statement {
                  - statement {

                      - not_statement {
                          - statement {

                              - byte_match_statement {
                                  - positional_constraint = "STARTS_WITH" -> null
                                  - search_string         = "/login" -> null

                                  - field_to_match {

                                      - uri_path {}
                                    }

                                  - text_transformation {
                                      - priority = 0 -> null
                                      - type     = "NORMALIZE_PATH" -> null
                                    }
                                }
                            }
                        }
                    }
                  - statement {

                      - not_statement {
                          - statement {

                              - byte_match_statement {
                                  - positional_constraint = "STARTS_WITH" -> null
                                  - search_string         = "/logout" -> null

                                  - field_to_match {

                                      - uri_path {}
                                    }

                                  - text_transformation {
                                      - priority = 0 -> null
                                      - type     = "NONE" -> null
                                    }
                                }
                            }
                        }
                    }
                  - statement {

                      - not_statement {
                          - statement {

                              - byte_match_statement {
                                  - positional_constraint = "STARTS_WITH" -> null
                                  - search_string         = "/auth" -> null

                                  - field_to_match {

                                      - uri_path {}
                                    }

                                  - text_transformation {
                                      - priority = 0 -> null
                                      - type     = "NONE" -> null
                                    }
                                }
                            }
                        }
                    }
                  - statement {

                      - not_statement {
                          - statement {

                              - byte_match_statement {
                                  - positional_constraint = "STARTS_WITH" -> null
                                  - search_string         = "/geolocate" -> null

                                  - field_to_match {

                                      - uri_path {}
                                    }

                                  - text_transformation {
                                      - priority = 0 -> null
                                      - type     = "NONE" -> null
                                    }
                                }
                            }
                        }
                    }
                  - statement {

                      - not_statement {
                          - statement {

                              - byte_match_statement {
                                  - positional_constraint = "STARTS_WITH" -> null
                                  - search_string         = "/hook" -> null

                                  - field_to_match {

                                      - uri_path {}
                                    }

                                  - text_transformation {
                                      - priority = 0 -> null
                                      - type     = "NONE" -> null
                                    }
                                }
                            }
                        }
                    }
                  - statement {

                      - not_statement {
                          - statement {

                              - byte_match_statement {
                                  - positional_constraint = "STARTS_WITH" -> null
                                  - search_string         = "/version" -> null

                                  - field_to_match {

                                      - uri_path {}
                                    }

                                  - text_transformation {
                                      - priority = 0 -> null
                                      - type     = "NONE" -> null
                                    }
                                }
                            }
                        }
                    }
                }
            }

          - visibility_config {
              - cloudwatch_metrics_enabled = true -> null
              - metric_name                = "AuthorizedEndpoints" -> null
              - sampled_requests_enabled   = true -> null
            }
        }
      - rule {
          - name     = "AWS-AWSManagedRulesAmazonIpReputationList" -> null
          - priority = 4 -> null

          - override_action {

              - none {}
            }

          - statement {

              - managed_rule_group_statement {
                  - name        = "AWSManagedRulesAmazonIpReputationList" -> null
                  - vendor_name = "AWS" -> null
                }
            }

          - visibility_config {
              - cloudwatch_metrics_enabled = true -> null
              - metric_name                = "AWS-AWSManagedRulesAmazonIpReputationList" -> null
              - sampled_requests_enabled   = true -> null
            }
        }
      + rule {
          + name     = "AWS-AWSManagedRulesAmazonIpReputationList"
          + priority = 4

          + override_action {

              + none {}
            }

          + statement {

              + managed_rule_group_statement {
                  + name        = "AWSManagedRulesAmazonIpReputationList"
                  + vendor_name = "AWS"
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "AWS-AWSManagedRulesAmazonIpReputationList"
              + sampled_requests_enabled   = true
            }
        }
      - rule {
          - name     = "AWS-AWSManagedRulesCommonRuleSet" -> null
          - priority = 1 -> null

          - override_action {

              - none {}
            }

          - statement {

              - managed_rule_group_statement {
                  - name        = "AWSManagedRulesCommonRuleSet" -> null
                  - vendor_name = "AWS" -> null
                }
            }

          - visibility_config {
              - cloudwatch_metrics_enabled = true -> null
              - metric_name                = "AWS-AWSManagedRulesCommonRuleSet" -> null
              - sampled_requests_enabled   = true -> null
            }
        }
      + rule {
          + name     = "AWS-AWSManagedRulesCommonRuleSet"
          + priority = 1

          + override_action {

              + none {}
            }

          + statement {

              + managed_rule_group_statement {
                  + name        = "AWSManagedRulesCommonRuleSet"
                  + vendor_name = "AWS"
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "AWS-AWSManagedRulesCommonRuleSet"
              + sampled_requests_enabled   = true
            }
        }
      - rule {
          - name     = "AWS-AWSManagedRulesKnownBadInputsRuleSet" -> null
          - priority = 2 -> null

          - override_action {

              - none {}
            }

          - statement {

              - managed_rule_group_statement {
                  - name        = "AWSManagedRulesKnownBadInputsRuleSet" -> null
                  - vendor_name = "AWS" -> null
                }
            }

          - visibility_config {
              - cloudwatch_metrics_enabled = true -> null
              - metric_name                = "AWS-AWSManagedRulesKnownBadInputsRuleSet" -> null
              - sampled_requests_enabled   = true -> null
            }
        }
      + rule {
          + name     = "AWS-AWSManagedRulesKnownBadInputsRuleSet"
          + priority = 2

          + override_action {

              + none {}
            }

          + statement {

              + managed_rule_group_statement {
                  + name        = "AWSManagedRulesKnownBadInputsRuleSet"
                  + vendor_name = "AWS"
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "AWS-AWSManagedRulesKnownBadInputsRuleSet"
              + sampled_requests_enabled   = true
            }
        }
      - rule {
          - name     = "AWSManagedRulesLinuxRuleSet" -> null
          - priority = 3 -> null

          - override_action {

              - none {}
            }

          - statement {

              - managed_rule_group_statement {
                  - name        = "AWSManagedRulesLinuxRuleSet" -> null
                  - vendor_name = "AWS" -> null
                }
            }

          - visibility_config {
              - cloudwatch_metrics_enabled = true -> null
              - metric_name                = "AWSManagedRulesLinuxRuleSet" -> null
              - sampled_requests_enabled   = true -> null
            }
        }
      + rule {
          + name     = "AWSManagedRulesLinuxRuleSet"
          + priority = 3

          + 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
            }
        }

        # (5 unchanged blocks hidden)
    }

  # aws_wafv2_web_acl_logging_configuration.sre-bot will be created
  + resource "aws_wafv2_web_acl_logging_configuration" "sre-bot" {
      + id                      = (known after apply)
      + log_destination_configs = [
          + "arn:aws:logs:ca-central-1:283582579564:log-group:sre-bot-waf-log-group",
        ]
      + resource_arn            = "arn:aws:wafv2:ca-central-1:283582579564:regional/webacl/sre-bot/2ea5ee5d-d7d8-46a4-a0a4-f59b67bd4c44"
    }

Plan: 1 to add, 2 to change, 0 to destroy.

Warning: Argument is deprecated

  with module.sre_bot_bucket.aws_s3_bucket.this,
  on .terraform/modules/sre_bot_bucket/S3/main.tf line 8, in resource "aws_s3_bucket" "this":
   8: resource "aws_s3_bucket" "this" {

Use the aws_s3_bucket_server_side_encryption_configuration resource instead

(and 6 more similar warnings elsewhere)

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_acm_certificate.sre_bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.sre-bot_group"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.sre_bot_dns"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.sre_bot_waf_log_group"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.sre_bot_error"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.sre_bot_warning"]
WARN - plan.json - main - Missing Common Tags: ["aws_dynamodb_table.aws_access_requests_table"]
WARN - plan.json - main - Missing Common Tags: ["aws_dynamodb_table.sre_bot_data"]
WARN - plan.json - main - Missing Common Tags: ["aws_dynamodb_table.webhooks_table"]
WARN - plan.json - main - Missing Common Tags: ["aws_ecr_repository.sre-bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_ecs_cluster.sre-bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_ecs_service.main"]
WARN - plan.json - main - Missing Common Tags: ["aws_ecs_task_definition.sre-bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.geodb_refresh_policy"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.sre-bot_secrets_manager"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.sre_bot_bucket"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.sre-bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb.sre_bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb_listener.sre_bot_listener"]
WARN - plan.json - main - Missing Common Tags: ["aws_lb_target_group.sre_bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_route53_health_check.sre_bot_healthcheck"]
WARN - plan.json - main - Missing Common Tags: ["aws_route53_resolver_query_log_config.sre_bot"]
WARN - plan.json - main - Missing Common Tags: ["aws_route53_zone.sre_bot"]
WARN - plan.json - main - Missing Common Tags:...

@gcharest gcharest merged commit 77f3668 into main Aug 6, 2024
7 checks passed
@gcharest gcharest deleted the fix/enable_blocking_unknown_endpoints branch August 6, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants