Giter Club home page Giter Club logo

forms-terraform's Introduction

Forms Terraform

Infrastructure as Code for the GC Forms environment.

Contributing

Pull Requests in this repository require all commits to be signed before they can be merged. Please see this guide for more information.

Prerequisites:

If using Colima

  • Docker: brew install docker docker-compose docker-credential-manager

Modify the docker config file to use mac os keychain as credStore

nano ~/.docker/config.json

{
    ...
    "credsStore": "osxkeychain",
    ...
}
  • Colima: brew insteall colima
# as /var/ is a protected directory, we will need sudo
sudo ln ~/.colima/default/docker.sock /var/run

# we can verify this has worked by running
ls /var/run
# and confirming that docker.sock is now in the directory

Colima can be set as a service to start on login: brew services start colima

Request Localstack Pro license

You will need to create a Localstack account using your CDS email address here and then ask your supervisor to assign you a Pro license license.

Set your environment variables

Create an .env file at the root of the project and use the .env.example as a template. You can find some of the values in 1Password > Local Development .ENV secure note. The LOCALSTACK_AUTH_TOKEN value will be accessible here once you have been assigned a Pro license.

Start Localstack

$ docker-compose up
See expected console output
[+] Building 0.0s (0/0)
[+] Running 2/2
 ✔ Network forms-terraform_default  Created                                                                               0.1s
 ✔ Container GCForms_LocalStack     Created                                                                               0.1s
Attaching to GCForms_LocalStack
GCForms_LocalStack  |
GCForms_LocalStack  | LocalStack version: 3.2.1.dev20240306170817
GCForms_LocalStack  | LocalStack Docker container id: 00e39dc6785e
GCForms_LocalStack  | LocalStack build date: 2024-03-06
GCForms_LocalStack  | LocalStack build git hash: 93fc329
GCForms_LocalStack  |
GCForms_LocalStack  | 2024-03-27T14:11:56.175  INFO --- [  MainThread] l.bootstrap.licensingv2    : Successfully requested and activated new license <license_identifier>:pro 🔑✅
GCForms_LocalStack  | 2024-03-27T14:11:58.611  INFO --- [  MainThread] l.p.snapshot.plugins       : registering ON_STARTUP load strategy
GCForms_LocalStack  | 2024-03-27T14:11:59.649  INFO --- [  MainThread] l.p.snapshot.plugins       : registering SCHEDULED save strategy
GCForms_LocalStack  | 2024-03-27T14:11:59.713  INFO --- [  MainThread] l.extensions.platform      : loaded 0 extensions
GCForms_LocalStack  | 2024-03-27T14:12:00.097  INFO --- [-functhread4] hypercorn.error            : Running on https://0.0.0.0:4566 (CTRL + C to quit)
GCForms_LocalStack  | 2024-03-27T14:12:00.097  INFO --- [-functhread4] hypercorn.error            : Running on https://0.0.0.0:4566 (CTRL + C to quit)
GCForms_LocalStack  | 2024-03-27T14:12:00.098  INFO --- [-functhread4] hypercorn.error            : Running on https://0.0.0.0:443 (CTRL + C to quit)
GCForms_LocalStack  | 2024-03-27T14:12:00.098  INFO --- [-functhread4] hypercorn.error            : Running on https://0.0.0.0:443 (CTRL + C to quit)
GCForms_LocalStack  | 2024-03-27T14:12:00.316  INFO --- [  MainThread] localstack.utils.bootstrap : Execution of "start_runtime_components" took 602.48ms
GCForms_LocalStack  | Ready.
GCForms_LocalStack  | 2024-03-27T14:12:03.093  INFO --- [  MainThread] l.p.snapshot.plugins       : restoring state of all services on startup

Once Localstack is ready to use you should be able to interact with local AWS services using the Localstack web application.

If the Localstack web application is not able to connect to the instance you just started you may have to add 127.0.0.1 localhost.localstack.cloud to your /etc/hosts.

Deploy infrastructure

Now that we have localstack up and running it's time to deploy our local AWS services to mimic our cloud environments.

$ ./localstack_services.sh

Please note that if you stop Localstack you don't need to run this script again. Localstack Pro offers automatic persistence for all deployed services. This is enabled by default and can be tweaked through your .env file.

Congratulations! You should now have all the necessary infrastructure configured on Localstack to support all the web applications functions completely locally without needing an AWS account.

How to manually invoke a Lambda function

$ awslocal lambda invoke --function-name <name_of_the_function> output.txt

In case you want to invoke a function that expects a specific payload you can pass it using the --payload '{}' argument.

Containerized Lambda functions

The deps.sh script allows you to download required dependencies for all Lambda packages available under /lambda-code.

$ cd lambda-code/
$ ./deps.sh install

Once you have changed the code in one or multiple Lambda packages, you can call the deploy-lambda-images.sh. It will build, tag and push all Lambda images to ECR as well as letting the Lambda service know that a new version of the code should be used.

$ cd lambda-code/
$ ./deploy-lambda-images.sh

There is a skip argument you can pass to that script if you only want to deploy the Lambda images for which you have made changes. It uses the git diff HEAD . command in every single Lambda folder to know whether the image should be deployed or skipped

Dynamo Database Table Schemas

Vault Table

Table

Vault Table

Archive Global Secondary Index

This Index supports the archiving of Vault responses Archive GSI

Status Global Secondary Index

This Index supports the future feature of the Retrieval API. Essentially the ability to retrieve responses without using the Application Interface. Status Index

Nagware Global Secondary Index

This Index supports the Nagware feature. It gives the ability to retrieve form submissions with a specific status and creation date. Nagware Index

Traduction en français à venir...

forms-terraform's People

Contributors

anikbrazeau avatar bryan-robitaille avatar craigzour avatar daine avatar dsamojlenko avatar falila avatar fitore-cds avatar jeberhardt avatar michaelfagan avatar mnigh avatar mohdnr avatar moro-code avatar patheard avatar renovate[bot] avatar sre-read-write[bot] avatar thiessenp-cds avatar timarney avatar wmoussa-gc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

forms-terraform's Issues

Add Cognito sign-in attempts exceeded CloudWatch alarm

Summary

Add a CloudWatch alarm that is triggered when there is a high number of failed Cognito sign-in attempts to catch account brute forcing attempts.

Steps

  1. Update the authorize method to log the Cognito exception type to the Form's CloudWatch log group.
  2. Create a metric filter and CloudWatch alarm based on this filter:
resource "aws_cloudwatch_log_metric_filter" "cognito_signin_exceeded" {
  name           = "CognitoSigninExceeded"
  pattern        = "NotAuthorizedException: Password attempts exceeded" # adjust based on logging in step 1 
  log_group_name = var.ecs_cloudwatch_log_group_name

  metric_transformation {
    name          = "CognitoSigninExceeded"
    namespace     = "forms"
    value         = "1"
    default_value = "0"
  }
}

resource "aws_cloudwatch_metric_alarm" "cognito_signin_exceeded" {
  alarm_name          = "CognitoSigninExceeded"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "1"
  metric_name         = aws_cloudwatch_log_metric_filter.cognito_signin_exceeded.metric_transformation[0].name
  namespace           = aws_cloudwatch_log_metric_filter.cognito_signin_exceeded.metric_transformation[0].namespace
  period              = "60"
  statistic           = "Sum"
  threshold           = "10" # this could also be adjusted depending on what we think is a good threshold
  treat_missing_data  = "notBreaching"
  alarm_description   = "Cognito - multiple failed sign-in attempts detected."

  alarm_actions = [var.sns_topic_alert_warning_arn]

  tags = {
    (var.billing_tag_key) = var.billing_tag_value
    Terraform             = true
  }
}

Test

Perform multiple failed login attempts and expect the alarm to trigger.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/github-script action to v7
  • chore(deps): update google-github-actions/release-please-action action to v4
  • chore(deps): update public.ecr.aws/lambda/nodejs docker tag to v20
  • chore(deps): update terraform github.com/cds-snc/terraform-modules to v9
  • fix(deps): update dependency json2md to v2
  • fix(deps): update dependency notifications-node-client to v8
  • fix(deps): update dependency uuid to v9
  • 🔐 Create all pending approval PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
.devcontainer/docker-compose.yml
  • localstack/localstack sha256:1d6c671daa4ecd65b44a4ecbb12fff0fb82dd1bd62f19728e5e05e18dff831c8
docker-compose.yml
  • localstack/localstack-pro latest
dockerfile
.devcontainer/Dockerfile
  • mcr.microsoft.com/vscode/devcontainers/base buster@sha256:b42cb5b189abb742fbc2de3db825b4c174569e79bbe34f01fa055aba075c924d
lambda-code/audit-logs-archiver/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/audit-logs/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/cognito-email-sender/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/cognito-pre-sign-up/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/form-archiver/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/load-testing/Dockerfile
  • amazon/aws-lambda-python 3.11@sha256:99cadc3bd9674a32a4ef694ff2e27f0b3d6c7f369b174db792b0099699fa0da4
lambda-code/nagware/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/notify-slack/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/reliability-dlq-consumer/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/reliability/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/response-archiver/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/submission/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
lambda-code/vault-integrity/Dockerfile
  • public.ecr.aws/lambda/nodejs 18
  • public.ecr.aws/lambda/nodejs 18
github-actions
.github/workflows/conventional-commit-lint.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/setup-node v4.0.2@60edb5dd545a775178f52524783378180af0d1f8
.github/workflows/diff-comment.yml
  • actions/github-script v4.2.0@10b53a9ec6c222bb4ce97aa6bd2b5f739696b536
  • actions/github-script v4.2.0@10b53a9ec6c222bb4ce97aa6bd2b5f739696b536
.github/workflows/release_generator.yml
  • actions/create-github-app-token v1.6.0@e995b4e40ace2eb5bf13137d9abe242c98f3aab6
  • google-github-actions/release-please-action v3.7.13@db8f2c60ee802b3748b512940dde88eabd7b7e01
.github/workflows/request-lambda-functions-to-use-new-image/action.yml
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • aws-actions/amazon-ecr-login v2
.github/workflows/tag-and-push-lambda-images/action.yml
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • aws-actions/amazon-ecr-login v2
.github/workflows/terraform-security-scan.yml
  • actions/checkout v2.7.0@ee0669bd1cc54295c223e0bb666b733df41de1c5
.github/workflows/terraform-variable-check.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
.github/workflows/terraform-version-check.yml
  • actions/checkout v2.7.0@ee0669bd1cc54295c223e0bb666b733df41de1c5
  • actions/github-script v4.2.0@10b53a9ec6c222bb4ce97aa6bd2b5f739696b536
  • actions/github-script v4.2.0@10b53a9ec6c222bb4ce97aa6bd2b5f739696b536
.github/workflows/terragrunt-apply-production.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • cds-snc/terraform-tools-setup v1
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • dorny/paths-filter v3.0.2@de90cc6fb38fc0963ad72b210f1f284cd68cea36
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • cds-snc/terraform-tools-setup v1
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
.github/workflows/terragrunt-apply-staging.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • cds-snc/terraform-tools-setup v1
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • dorny/paths-filter v3.0.2@de90cc6fb38fc0963ad72b210f1f284cd68cea36
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • cds-snc/terraform-tools-setup v1
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
.github/workflows/terragrunt-plan-all-staging.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • cds-snc/terraform-tools-setup v1
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
.github/workflows/terragrunt-plan-production.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • dorny/paths-filter v3.0.2@de90cc6fb38fc0963ad72b210f1f284cd68cea36
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • cds-snc/terraform-tools-setup v1
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
.github/workflows/terragrunt-plan-staging.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • dorny/paths-filter v3.0.2@de90cc6fb38fc0963ad72b210f1f284cd68cea36
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • cds-snc/terraform-tools-setup v1
  • aws-actions/configure-aws-credentials v4.0.1@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
  • dorny/paths-filter v3.0.2@de90cc6fb38fc0963ad72b210f1f284cd68cea36
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
  • cds-snc/terraform-plan v3.2.2@4719878d72d1b0078e0bce2e7571e854e79903b8
html
aws/load_balancer/static_website/index-fr.html
  • font-awesome 6.4.2
aws/load_balancer/static_website/index.html
  • font-awesome 6.4.2
npm
lambda-code/audit-logs-archiver/package.json
  • @aws-sdk/client-dynamodb 3.430.0
  • @aws-sdk/lib-dynamodb 3.430.0
  • @aws-sdk/client-s3 3.430.0
  • @types/aws-lambda ^8.10.128
  • @types/node ^20.9.4
  • typescript ^5.3.2
lambda-code/audit-logs/package.json
  • @aws-sdk/client-dynamodb 3.430.0
  • @aws-sdk/lib-dynamodb 3.430.0
  • @types/aws-lambda ^8.10.126
  • @types/node ^20.9.0
  • typescript ^5.2.2
lambda-code/cognito-email-sender/package.json
  • @aws-crypto/client-node 4.0.0
  • @aws-sdk/client-secrets-manager ^3.478.0
  • axios ^1.6.8
  • notifications-node-client ^5.1.0
  • @types/aws-lambda ^8.10.126
  • @types/node ^20.9.0
  • typescript ^5.2.2
lambda-code/cognito-pre-sign-up/package.json
  • @types/aws-lambda ^8.10.128
  • @types/node ^20.9.4
  • typescript ^5.3.2
lambda-code/form-archiver/package.json
  • @aws-sdk/client-rds-data 3.430.0
  • @types/aws-lambda ^8.10.126
  • @types/node ^20.9.0
  • typescript ^5.2.2
lambda-code/nagware/package.json
  • @aws-sdk/client-dynamodb 3.430.0
  • @aws-sdk/client-rds-data 3.430.0
  • @aws-sdk/client-secrets-manager ^3.478.0
  • axios ^1.6.2
  • notifications-node-client 5.2.3
  • @types/aws-lambda ^8.10.128
  • @types/node ^20.12.8
  • typescript ^5.3.2
lambda-code/notify-slack/package.json
  • @types/aws-lambda ^8.10.128
  • @types/node ^20.9.4
  • typescript ^5.3.2
  • vitest ^1.6.0
  • @vitest/coverage-v8 ^1.6.0
lambda-code/reliability-dlq-consumer/package.json
  • @aws-sdk/client-sqs 3.430.0
  • @types/aws-lambda ^8.10.129
  • @types/node ^20.10.0
  • typescript ^5.3.2
lambda-code/reliability/package.json
  • @aws-sdk/client-dynamodb 3.430.0
  • @aws-sdk/client-lambda 3.430.0
  • @aws-sdk/client-rds-data 3.430.0
  • @aws-sdk/client-s3 3.430.0
  • @aws-sdk/client-secrets-manager ^3.478.0
  • @aws-sdk/client-sqs 3.430.0
  • @aws-sdk/lib-dynamodb 3.430.0
  • axios ^1.0.0
  • json2md ^1.10.0
  • notifications-node-client ^5.1.0
  • uuid ^8.3.2
  • @types/aws-lambda ^8.10.126
  • @types/json2md ^1.5.4
  • @types/node ^20.9.0
  • @types/uuid ^9.0.7
  • typescript ^5.2.2
lambda-code/response-archiver/package.json
  • @aws-sdk/client-dynamodb 3.430.0
  • @aws-sdk/lib-dynamodb 3.430.0
  • @aws-sdk/client-s3 3.430.0
  • @types/aws-lambda ^8.10.128
  • @types/node ^20.9.4
  • typescript ^5.3.2
lambda-code/submission/package.json
  • @aws-sdk/client-dynamodb 3.430.0
  • @aws-sdk/client-sqs 3.430.0
  • @aws-sdk/lib-dynamodb 3.430.0
  • uuid ^8.3.2
  • @types/aws-lambda ^8.10.128
  • @types/node ^20.9.4
  • @types/uuid ^9.0.7
  • typescript ^5.3.2
lambda-code/vault-integrity/package.json
  • @types/aws-lambda ^8.10.126
  • @types/node ^20.9.0
  • typescript ^5.2.2
pip_requirements
lambda-code/load-testing/requirements.txt
  • invokust ==0.77
terraform
aws/alarms/athena.tf
  • github.com/cds-snc/terraform-modules bd904d01094f196fd3e8ff5c46e73838f1f1be26
  • github.com/cds-snc/terraform-modules bd904d01094f196fd3e8ff5c46e73838f1f1be26
aws/file_scanning/vault_scan_object.tf
  • github.com/cds-snc/terraform-modules 1e2debaf58fdb65da1910f0d42efcc786ddd0722
aws/oidc_roles/iam_roles.tf
  • github.com/cds-snc/terraform-modules dca686fdd6670f0b3625bc17a5661bec3ea5aa62
env/common/local-provider.tf
  • aws 5.32.0
  • random =3.6.0
  • hashicorp/terraform 1.6.6
env/common/provider.tf
  • aws 5.32.0
  • random =3.6.0
  • hashicorp/terraform 1.6.6
terragrunt
env/cloud/alarms/terragrunt.hcl
env/cloud/app/terragrunt.hcl
env/cloud/cognito/terragrunt.hcl
env/cloud/dynamodb/terragrunt.hcl
env/cloud/ecr/terragrunt.hcl
env/cloud/file_scanning/terragrunt.hcl
env/cloud/hosted_zone/terragrunt.hcl
env/cloud/kms/terragrunt.hcl
env/cloud/lambdas/terragrunt.hcl
env/cloud/load_balancer/terragrunt.hcl
env/cloud/load_testing/terragrunt.hcl
env/cloud/network/terragrunt.hcl
env/cloud/oidc_roles/terragrunt.hcl
env/cloud/pr_review/terragrunt.hcl
env/cloud/rds/terragrunt.hcl
env/cloud/redis/terragrunt.hcl
env/cloud/s3/terragrunt.hcl
env/cloud/secrets/terragrunt.hcl
env/cloud/sns/terragrunt.hcl
env/cloud/sqs/terragrunt.hcl
env/terragrunt.hcl

  • Check this box to trigger a request for Renovate to run again on this repository

Increase Lambda Function RuntimeTimeout

As file uploads become more and more popular the runtime for Lambda functions is also increasing. The current default is 3 seconds however there has recently been an instance of the timeout being hit when processing a form with 2 pdf files.

Increase Lambda Execution timeout to 5 min (300 seconds)

Implement Terragrunt to simplify staging and production environments.

We currently have an issue keeping two separate terraform repos as moving changes through staging to production is cumbersome and error prone.

Terragrunt will allow for the declaration of separate stand alone modules allowing for easy injection of variables that differ between the staging and production environment.

Requires complete refactoring of terraform code for extraction of modules and variables.

Project that have already gone this path:
Notifications
Covid Alert Metrics

Add an archive for processed form submissions

Add an archive that stores processed form submissions for a set amount of time before purging expired submissions. If there is ever an issue with a client (system crash, inadvertent deletion, etc.) we need a process to be able to provide the client with form submission backups.

Potential solution:

  • Once a form submission is processed move the raw submission to an S3 bucket that is set to purge entries older than x days (check with policy for exact value).

Create alarm to be informed when a Lambda function times out

We had a case where the response archiver lambda was timing out in both Production and Staging and there was no way for us to know that other than logging into the AWS admin console and manually checking the logs.

Create CloudWatch alarms so that a notification is sent on Slack when a Lambda times out.

Issue when uploading files with spaces in filename

Ran into this while testing a Branding upload form on Staging.

If you're logged in on Staging, you can see the form here: https://forms-staging.cdssandbox.xyz/en/form-builder/edit/clfgzqv7705358bx84qjps43y

Alternatively, here's a JSON form definition you can use: https://github.com/cds-snc/platform-forms-client/pull/1755/files

If you try to upload a file with spaces (or presumably other special characters that require escaping), the following error will cause it to fail in the reliability queue: Failed to retrieve files from reliability storage because of following error: Request path contains unescaped characters..

Here is a form submission that failed:

{"formID":"clfgymbb801888bx8jgnaqqif","language":"en","responses":{"1":"CA","2":"CAFR","3":"https://canada.ca/","4":"https://canada.ca/","7":"form_attachments/2023-03-20/13830c12-bce6-4817-a576-15e68683924e/Screenshot 2023-03-20 at 11.09.23 AM.png","8":"form_attachments/2023-03-20/2ab76646-1dc4-48c5-9659-dd2096587a2a/Screenshot 2023-03-20 at 11.09.23 AM.png"},"deliveryOption":{"emailAddress":"[[email protected]](mailto:[email protected])"}}

RDS: investigate fixes for checkov issues

Summary

Checkov has identified the following issues with the RDS cluster:

- CKV2_AWS_8  # RDS enable Query Logging
- CKV2_AWS_27 # RDS setup AWS Backup plan 

Once the existing AWS resources have been imported into the new Terraform state, we should attempt to fix them.

Related

Dynamic Row losing rows after form validation

When completing a form with validated fields, if the validation errors are triggered on any field the Dynamic Row only renders a single row instead of the x number of rows that were completed before the submission attempt.

Before Validation After Validation
Screen Shot 2021-10-07 at 8.38.37 AM.png Screen Shot 2021-10-07 at 8.45.07 AM.png

Acceptance Criteria:

  • On render after error validation the dynamic row should appear as it did before the submission event
  • All error references are able to reach their intended fields (For example a dynamic row with more than one row should still be reachable by the error summary at the top of the page).

Filter for PR Review Environment

Create a filter on the github action that ensures it only creates PR Review Environments for PR's that do not include database migrations/changes.

State migration: checklist for moving from Terraform to Terragrunt

Summary

The following steps will be required to migrate the existing AWS resources from the Terraform remote state to the new Terragrunt module remote states.

Staging

  • Merge new changes from forms/aws into Terragrunt modules
  • List resources in Terraform state
  • Taint the ECS service
  • Terraform import all resources into respective Terragrunt module remote states
  • Run Terragrunt apply for all modules and ensure no unexpected changes
  • Remove forms/aws folder and terraform.yml workflow from repo

Production

  • Compare Production and Staging Terraform and merge any changes required
  • List resources in Terraform state
  • Taint the ECS service
  • Terraform import all resources into respective Terragrunt module remote states
  • Run Terragrunt apply for all modules and ensure no unexpected changes
  • Archive forms-production-terraform repo

Finish

  • Rename this repo to forms-terraform

Notes

The aws_ecs_service.form_viewer must be tainted and recreated, otherwise CodeDeploy prevents any changes to it.

cd "env/$ENV/app"
terragrunt taint aws_ecs_service.form_viewer

⚠️ This will cause a few minutes of downtime in the environment.

Related

Make all ECR repositories immutable

Related to this discussion

When implementing containerized Lambda functions we had a discussion concerning the mutability of our ECR repositories. The recommendation is to make them immutable so that there is no chance an image is being mistakenly overridden.
In our current infra, for simplicity, we decided to have all Lambda function point to the tag named latest and every time we deploy a new version we tag it with both the commit SHA and latest tags.
There is an ongoing discussion in this ticket aws/containers-roadmap#878 to see if AWS can support immutability expect for latest which would become some kind of a pointer to the newest image. If this gets implemented then we would be able to tweak our implementation so that we switch our repositories to being immutable.

More information in the discussion linked at the beginning.

Transition Redis to Serverless Instance

Transition our Redis cluster from using a consistent reserved capacity (cache.t2.micro) to a serverless engine.

Pros:

  • Reduced costs
  • Ability to scale independently
  • Leverage latest Redis engine (7.2)
    • Allows to leverage new JSON type instead of converting form configurations to strings.

Cons:

  • Request application mitigation so that there is no downtime during the Production release.

Refactor Sign In From Outside Country Detection

Leverage the ability of the WAF to inject headers into a request so that the Application is aware the request is from outside the country and can trigger alerts as required.

Acceptance Criteria:

  • WAF adds specific header to the request when the request is detected from outside of the accepted Geo Zone.
  • Application verifies header during the JWT callback to ensure that any authenticated action is done from within the accepted Geo Zone.
  • Application produces different alarms based on forbidden action:
    • Sign In at Cognito Level from outside Geo Zone
    • Sigin In Mfa level from outside Geo Zone
    • Authenticated action from outside Geo Zone.

Add maintenance page when GCForms is unavailable

Problem: Currently end users will either be presented with a 500 page when the GCForms application is no longer functioning or is undergoing maintenance.
Work: Add a maintenance page to inform users that the application is not available

Involves:

  • Creating a route53 check that verifies if the app is running
  • Created a CloudFront CDN end point
  • Create a primary and fallback route53 entry for GCForms
  • Create a static site (en and fr) that users will be directed to when the route53 entry is in fallback mode

Redis: investigate if encryption in transit and at rest can be enabled

Description

Currently the ElastiCache Redis replication group does not have encryption enabled in transit or at rest. This has a low impact because the data is only for feature flags, but it does cause the following 3 checkov failures around encryption and authorization:

- CKV_AWS_29  # Elasticache enable at-rest data encryption
- CKV_AWS_30  # Elasticache enable in-transit data encryption
- CKV_AWS_31  # Elasticache enable in-transit data encryption and auth token  

Once the Terragrunt conversion has been applied to Staging, we should check the impact of enable at-rest and in-transit encryption.

Notes

Terraform settings for the AWS provider:

Related

File scanning proof of concept: trigger scan of new S3 objects

Summary

Create a Lambda function that triggers a scan of new objects created in an S3 bucket. This will be a proof-of-concept for the proposed asynchronous solution in Design Doc 008: File upload for API and UI + content scanning:

image.png

Acceptance criteria

  • The function should be triggered automatically by S3 s3:ObjectCreated:* events.
  • The S3 object that triggered the scan should be updated with metadata related to the scan: IN_PROGRESS and FAILED_TO_SCAN.
  • The function should also respond to SNS event triggers from the Scan Files service to update the S3 object metadata with the scan result.

Encrypt RDS Clusters using KMS CMKs (CKV_AWS_327)

Implement resources to resolve following checkov policy "Ensure RDS Clusters are encrypted using KMS CMKs"

Search for "CKV_AWS_327" in the infra repository in order to see places that requires modifications.

Update firewall rules to only allow known url paths

The Staging and Production environments received multiple Fuzzy attacks per day with requests similar to the following:
-Requested and resolved page mismatch: /%0ASet-Cookie%3Acrlfinjection/.. /

  • Requested and resolved page mismatch: /en/./RestAPI/Connection /en/RestAPI/Connection
  • Requested and resolved page mismatch: /./RestAPI/LogonCustomization /RestAPI/LogonCustomization

Ensure that only known and valid url paths are allowed through the Firewall.
AWS Resources:

Acceptance Critera

  • WAF rule blocks invalid or non-existent paths before reaching the application

Add S3 scan object Terraform module to Vault file storage

Summary

Add the S3 scan object Terraform module to the forms-${var.env}-vault-file-storage bucket to enable ClamAV file scanning on all newly created S3 objects.

The module behaves as follows:

  1. When an S3 object is created in the bucket, it triggers a scan using Scan Files ClamAV endpoint.
  2. This marks the S3 object scanning status as in_progress using object tags.
  3. Once Scan Files has completed the scan, it publishes the scan verdict to an SNS topic, which causes the lambda to update the S3 object tag with the scan verdict.

Related

Use Template record for Delivery Option

When fetching the template during reliability queue processing also retrieve the delivery method. This ensures that if a user needs to change an email address due to technical problems that responses are not left in limbo with the old information.

TF:

  • Modify reliability queue to fetch delivery option when pulling template from DB
  • getTemplateFormConfig in /lambda/reliability/lib/templates.js
    App:
  • Remove inclusion of deliveryOption in Lambda Call in api/submit
  • Remove unused function getTemplateDeliveryOptionByID in lib/templates

Archive Audit Logs

PR #336 added the functionality to store Audit Logs in DynamoDB. The logs are currently set with a TTL of 1 year, which means after 1 year they'll be automatically deleted from the DynamoDB database.

Before that event occurs an archiving solution that reads from the DynamoDb stream for the AuditLogs table that filters on TTL deletions must be put in place in order to save the deleted items in S3.

See AWS reference material for solution: Reference material

Remove egress from ECS task

Remove egress from ECS task over port 443. The NextJS server does not need to initiate calls to external services.

Load balancer: enable access logging

Summary

Checkov identified the following issue with the load balancer:

- CKV_AWS_91 # Load balancer enable access logging

Once the existing AWS resources have been imported into the new Terraform state, we should attempt to fix them.

Related

Add a replay action for the Dead Letter Queue

If ever one of our outbound service calls (Notify, etc.) are down the form submissions will eventually be sent to the Dead Letter Queue. (DLQ). In a situation where Notify can be down for a few hours that could mean 100's of form submissions in the DLQ. A lambda is needed in order to automatically process the DQL and resend those messages back through the reliability queue once Notify service is active again. This lambda would be manually triggered by an AWS admin/dev once confirmed the DQL is ready is playback.

Add general rate limiting rule

Add a general rate-limiting rule to complement our post-request rate-limiting rule.

Investigation is required to determine an appropriate cutoff value.

Add Load Balancer access logs

Summary

Currently we do not have load balancer access logs setup. As a result, it's difficult to trace a user request to our service into the ECS form viewer task logs.

This will be enabled as part of the Cloud Based Sensor PR in #173.

ECS Task Definitions CleanUp

On every terraform apply a new ECS Task is created and the older versions remain in AWS. This can lead to thousands of ECS Task Definitions existing in our AWS account with the frequency that we push.

Implement a solution that only keeps the last 5 ECS Task Definitions and removes all previous versions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.