Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

feat: redirect /login to /home #762

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

Conversation

patheard
Copy link
Member

Summary

Add a custom WAF ACL rule that redirects requests
to the login page to the home page.

Add a custom WAF ACL rule that redirecs requests
to the login page to the home page.
@patheard patheard self-assigned this Jun 17, 2022
@patheard patheard requested a review from a team as a code owner June 17, 2022 18:26
Copy link

@mohdnr mohdnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 ✅ super convenient

@github-actions
Copy link

Plan changes

✅   Terraform Format: success
✅   Terraform Plan: success

Plan: 0 to add, 1 to change, 0 to destroy
Show plan
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_wafv2_web_acl.qrcode_acl will be updated in-place
  ~ resource "aws_wafv2_web_acl" "qrcode_acl" {
        arn        = "arn:aws:wafv2:ca-central-1:595701125956:regional/webacl/qrcode/90ed9118-ca41-437c-862b-a8d6cb10a584"
        capacity   = 1140
        id         = "90ed9118-ca41-437c-862b-a8d6cb10a584"
        lock_token = "24f3ca30-69ba-4f1f-9f0a-ca472def0b2f"
        name       = "qrcode"
        scope      = "REGIONAL"
        tags       = {
            "CostCentre" = "CovidPortal_Staging"
        }
        tags_all   = {
            "CostCentre" = "CovidPortal_Staging"
        }

        default_action {
            allow {
            }
        }

      + rule {
          + name     = "RedirectLoginToHome"
          + priority = 110

          + action {

              + block {
                  + custom_response {
                      + response_code = 301

                      + response_header {
                          + name  = "Location"
                          + value = "https://staging.covid-hcportal.cdssandbox.xyz"
                        }
                    }
                }
            }

          + statement {

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

                  + field_to_match {

                      + uri_path {}
                    }

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

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "RedirectLoginToHome"
              + sampled_requests_enabled   = true
            }
        }
      - rule {
          - name     = "CanadaOnlyGeoRestriction" -> null
          - priority = 5 -> null

          - action {

              - block {
                  - custom_response {
                      - response_code = 403 -> null

                      - response_header {
                          - name  = "waf-block" -> null
                          - value = "CanadaOnlyGeoRestriction" -> null
                        }
                    }
                }
            }

          - statement {

              - not_statement {
                  - statement {

                      - geo_match_statement {
                          - country_codes = [
                              - "CA",
                            ] -> null
                        }
                    }
                }
            }

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

          + action {

              + block {
                  + custom_response {
                      + response_code = 403

                      + response_header {
                          + name  = "waf-block"
                          + value = "CanadaOnlyGeoRestriction"
                        }
                    }
                }
            }

          + statement {

              + not_statement {
                  + statement {

                      + geo_match_statement {
                          + country_codes = [
                              + "CA",
                            ]
                        }
                    }
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "CanadaOnlyGeoRestriction"
              + sampled_requests_enabled   = true
            }
        }
        rule {
            name     = "PostRequestLimit"
            priority = 102

            action {

                block {
                }
            }

            statement {

                rate_based_statement {
                    aggregate_key_type = "IP"
                    limit              = 100

                    scope_down_statement {

                        byte_match_statement {
                            positional_constraint = "EXACTLY"
                            search_string         = "post"

                            field_to_match {

                                method {}
                            }

                            text_transformation {
                                priority = 1
                                type     = "LOWERCASE"
                            }
                        }
                    }
                }
            }

            visibility_config {
                cloudwatch_metrics_enabled = true
                metric_name                = "PostRequestRateLimit"
                sampled_requests_enabled   = true
            }
        }
        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     = "AWSManagedRulesCommonRuleSet"
            priority = 2

            override_action {

                none {}
            }

            statement {

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

            visibility_config {
                cloudwatch_metrics_enabled = true
                metric_name                = "AWSManagedRulesCommonRuleSet"
                sampled_requests_enabled   = true
            }
        }
        rule {
            name     = "AWSManagedRulesKnownBadInputsRuleSet"
            priority = 3

            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 = 4

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

        visibility_config {
            cloudwatch_metrics_enabled = true
            metric_name                = "covid_portal_global_rule"
            sampled_requests_enabled   = false
        }
    }

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

Changes to Outputs:
    ecs_cluster                  = {
        arn                                = "arn:aws:ecs:ca-central-1:595701125956:cluster/covid-portal_staging"
        capacity_providers                 = [
            "FARGATE",
        ]
        configuration                      = []
        default_capacity_provider_strategy = [
            {
                base              = 2
                capacity_provider = "FARGATE"
                weight            = 1
            },
        ]
        id                                 = "arn:aws:ecs:ca-central-1:595701125956:cluster/covid-portal_staging"
        name                               = "covid-portal_staging"
        setting                            = [
            {
                name  = "containerInsights"
                value = "enabled"
            },
        ]
        tags                               = {
            "CostCentre" = "CovidPortal_Staging"
        }
        tags_all                           = {
            "CostCentre" = "CovidPortal_Staging"
        }
    }
    security_group_egress        = {
        arn                    = "arn:aws:ec2:ca-central-1:595701125956:security-group/sg-006789af77a3fbdcb"
        description            = "Egress - CovidShield External Services"
        egress                 = [
            {
                cidr_blocks      = [
                    "0.0.0.0/0",
                ]
                description      = "Security group rule for Portal New Relic egress"
                from_port        = 443
                ipv6_cidr_blocks = []
                prefix_list_ids  = []
                protocol         = "tcp"
                security_groups  = []
                self             = false
                to_port          = 443
            },
            {
                cidr_blocks      = [
                    "0.0.0.0/0",
                ]
                description      = "Security group rule for Portal email egress"
                from_port        = 587
                ipv6_cidr_blocks = []
                prefix_list_ids  = []
                protocol         = "tcp"
                security_groups  = []
                self             = false
                to_port          = 587
            },
        ]
        id                     = "sg-006789af77a3fbdcb"
        ingress                = []
        name                   = "egress-anywhere"
        name_prefix            = ""
        owner_id               = "595701125956"
        revoke_rules_on_delete = false
        tags                   = {
            "CostCentre" = "CovidPortal_Staging"
        }
        tags_all               = {
            "CostCentre" = "CovidPortal_Staging"
        }
        timeouts               = null
        vpc_id                 = "vpc-0e71ff594dff0ef9d"
    }
    security_group_load_balancer = {
        arn                    = "arn:aws:ec2:ca-central-1:595701125956:security-group/sg-0ddadcce9ea825a8e"
        description            = "Ingress - covidportal Load Balancer"
        egress                 = [
            {
                cidr_blocks      = [
                    "172.16.0.0/16",
                ]
                description      = ""
                from_port        = 8000
                ipv6_cidr_blocks = []
                prefix_list_ids  = []
                protocol         = "tcp"
                security_groups  = []
                self             = false
                to_port          = 8000
            },
        ]
        id                     = "sg-0ddadcce9ea825a8e"
        ingress                = [
            {
                cidr_blocks      = [
                    "0.0.0.0/0",
                ]
                description      = ""
                from_port        = 443
                ipv6_cidr_blocks = []
                prefix_list_ids  = []
                protocol         = "tcp"
                security_groups  = []
                self             = false
                to_port          = 443
            },
            {
                cidr_blocks      = [
                    "0.0.0.0/0",
                ]
                description      = ""
                from_port        = 80
                ipv6_cidr_blocks = []
                prefix_list_ids  = []
                protocol         = "tcp"
                security_groups  = []
                self             = false
                to_port          = 80
            },
        ]
        name                   = "covidportal-load-balancer"
        name_prefix            = ""
        owner_id               = "595701125956"
        revoke_rules_on_delete = false
        tags                   = {
            "CostCentre" = "CovidPortal_Staging"
        }
        tags_all               = {
            "CostCentre" = "CovidPortal_Staging"
        }
        timeouts               = null
        vpc_id                 = "vpc-0e71ff594dff0ef9d"
    }

Warning: Argument is deprecated

  on s3.tf line 4, in resource "aws_s3_bucket" "firehose_waf_logs":
   4: resource "aws_s3_bucket" "firehose_waf_logs" {

Use the aws_s3_bucket_server_side_encryption_configuration resource instead

(and 8 more similar warnings elsewhere)


------------------------------------------------------------------------

This plan was saved to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"

Releasing state lock. This may take a few moments...

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

Successfully merging this pull request may close these issues.

3 participants