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

[Issue 965] Configure RDS to pass Security Hub checks #1048

Merged
merged 6 commits into from
Jan 23, 2024

Conversation

jamesbursa
Copy link
Collaborator

@jamesbursa jamesbursa commented Jan 19, 2024

Summary

Fixes #965

Time to review: 10 mins

Changes proposed

  • Increase backup retention period from default (1 day) to maximum (35 days).
  • Change the RDS superuser from a fixed username postgres to a randomized username of the form rootd475cc8eefda848e49bff38b509233ff.
  • Add variables to set the number of database instances in each environment, and increase the number of instances in prod to 2 (one writer, one reader).
  • Enable performance insights with a 3 month retention period.

Context for reviewers

This addresses the issues found by Security Hub.

The requirement "RDS DB clusters should be configured for multiple Availability Zones" has a cost implication as Aurora Serverless reader instances run continuously at the minimum configured scale. Therefore we only set 2 instances in the prod environment (1 writer and 2 reader), and leave the other environments with only 1 instance (a writer).

Warning

Since this changes the database superuser username, it forces a replacement of the RDS clusters. All data would be lost. After the clusters have been recreated, we will need to re-run the role manager lambda to create other users, so that the API can connect.

Partial terraform plan:

  # module.database.aws_rds_cluster.db must be replaced
-/+ resource "aws_rds_cluster" "db" {
      ~ allocated_storage                   = 1 -> (known after apply)
      + apply_immediately                   = (known after apply)
      ~ arn                                 = "arn:aws:rds:us-east-1:...:cluster:api-dev" -> (known after apply)
      ~ availability_zones                  = [
          - "us-east-1a",
          - "us-east-1c",
          - "us-east-1d",
        ] -> (known after apply)
      - backtrack_window                    = 0 -> null
      ~ backup_retention_period             = 1 -> 35
      + cluster_identifier_prefix           = (known after apply)
      ~ cluster_members                     = [
          - "api-dev-primary",
        ] -> (known after apply)
      ~ cluster_resource_id                 = "cluster-XNKIT..." -> (known after apply)
      ~ db_cluster_parameter_group_name     = "default.aurora-postgresql14" -> (known after apply)
      ~ db_subnet_group_name                = "default" -> (known after apply)
      ~ endpoint                            = "api-dev.cluster-....us-east-1.rds.amazonaws.com" -> (known after apply)
      ~ engine_version                      = "14.6" -> (known after apply)
      ~ engine_version_actual               = "14.6" -> (known after apply)
      ~ hosted_zone_id                      = "Z2R2IT..." -> (known after apply)
      ~ iam_roles                           = [] -> (known after apply)
      ~ id                                  = "api-dev" -> (known after apply)
      - iops                                = 0 -> null
      ~ master_user_secret                  = [
          - {
              - kms_key_id    = "arn:aws:kms:us-east-1:..."
              - secret_arn    = "arn:aws:secretsmanager:us-east-1:..."
              - secret_status = "active"
            },
        ] -> (known after apply)
      + master_user_secret_kms_key_id       = (known after apply)
      ~ master_username                     = "postgres" # forces replacement -> (known after apply) # forces replacement
      ~ network_type                        = "IPV4" -> (known after apply)
      ~ preferred_backup_window             = "06:16-06:46" -> (known after apply)
      ~ preferred_maintenance_window        = "sat:05:12-sat:05:42" -> (known after apply)
      ~ reader_endpoint                     = "api-dev.cluster-ro-....us-east-1.rds.amazonaws.com" -> (known after apply)
      + storage_type                        = (known after apply)
      - tags                                = {} -> null
        # (17 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Additional information

N/A

@jamesbursa jamesbursa marked this pull request as ready for review January 23, 2024 20:06
# Generate a random username for the RDS superuser.
# For Aurora PostgreSQL, it must contain 1–63 alphanumeric characters.
resource "random_id" "db_superuser" {
prefix = "root" # Fixed 4 character prefix for identification in logs
Copy link
Collaborator

@coilysiren coilysiren Jan 23, 2024

Choose a reason for hiding this comment

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

💯

Copy link
Collaborator

@coilysiren coilysiren left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@jamesbursa jamesbursa merged commit 3bb37b0 into main Jan 23, 2024
7 checks passed
@jamesbursa jamesbursa deleted the jamesbursa/965-configure-rds branch January 23, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Configure RDS to Pass Security Hub Checks
2 participants