-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/kabo5 nrl 853 cloud backup red line #743
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e716136
NRL-853 WIP cloud backup setup
katebobyn-nhs 732c833
[NRL-853] Fix perms errors with AWSCC resources for backup restore te…
mattdean3-nhs b00d598
[NRL-853] Move notification email config out of lambda-error module a…
mattdean3-nhs b465e2b
NRL-853 combine dynamodb and s3 policies, protect access to report bu…
katebobyn-nhs 87b7316
NRL-853 add backup tag to pointer table
katebobyn-nhs e18d117
NRL-853 disallow http requests in s3 buckets
katebobyn-nhs a4a9fd8
[NRL-853] Move backup infrastructure TF state into S3 and add README.…
mattdean3-nhs bd0ce6b
NRL-853 fix tags for table and buckets
katebobyn-nhs ef6a542
NRL-853 fix tags to match policy
katebobyn-nhs 1d715a2
NRL-853 split back into different plans for s3 and ddb
katebobyn-nhs 179eeb9
NRL-853 split back into different plans for s3 and ddb
katebobyn-nhs cd14fd7
Merge branch 'develop' into feature/kabo5-NRL-853-cloud-backup-red-line
katebobyn-nhs 2eea40c
NRL-853 use different tags for S3 an dynamodb resources
katebobyn-nhs 3ba98a4
Merge branch 'feature/kabo5-NRL-853-cloud-backup-red-line' of https:/…
katebobyn-nhs 61fad34
[NRL-853] Added backup destination vault arn as secret. Moved backup …
mattdean3-nhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
158 changes: 158 additions & 0 deletions
158
terraform/account-wide-infrastructure/dev/aws-backup.tf
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
|
|
||
| # First, we create an S3 bucket for compliance reports. | ||
| resource "aws_s3_bucket" "backup_reports" { | ||
| bucket_prefix = "${local.prefix}-backup-reports" | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_public_access_block" "backup_reports" { | ||
| bucket = aws_s3_bucket.backup_reports.id | ||
|
|
||
| block_public_acls = true | ||
| block_public_policy = true | ||
| ignore_public_acls = true | ||
| restrict_public_buckets = true | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_server_side_encryption_configuration" "backup_reports" { | ||
| bucket = aws_s3_bucket.backup_reports.bucket | ||
|
|
||
| rule { | ||
| apply_server_side_encryption_by_default { | ||
| sse_algorithm = "AES256" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_policy" "backup_reports_bucket_policy" { | ||
| bucket = aws_s3_bucket.backup_reports.id | ||
|
|
||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Id = "backup_reports_bucket_policy" | ||
| Statement = [ | ||
| { | ||
| Sid = "HTTPSOnly" | ||
| Effect = "Deny" | ||
| Principal = "*" | ||
| Action = "s3:*" | ||
| Resource = [ | ||
| aws_s3_bucket.backup_reports.arn, | ||
| "${aws_s3_bucket.backup_reports.arn}/*", | ||
| ] | ||
| Condition = { | ||
| Bool = { | ||
| "aws:SecureTransport" = "false" | ||
| } | ||
| } | ||
| }, | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
|
|
||
| resource "aws_s3_bucket_ownership_controls" "backup_reports" { | ||
| bucket = aws_s3_bucket.backup_reports.id | ||
| rule { | ||
| object_ownership = "BucketOwnerPreferred" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_acl" "backup_reports" { | ||
| depends_on = [aws_s3_bucket_ownership_controls.backup_reports] | ||
|
|
||
| bucket = aws_s3_bucket.backup_reports.id | ||
| acl = "private" | ||
| } | ||
|
|
||
| # We need a key for the SNS topic that will be used for notifications from AWS Backup. This key | ||
| # will be used to encrypt the messages sent to the topic before they are sent to the subscribers, | ||
| # but isn't needed by the recipients of the messages. | ||
|
|
||
| # First we need some contextual data | ||
| data "aws_caller_identity" "current" {} | ||
| data "aws_region" "current" {} | ||
|
|
||
| # Now we can define the key itself | ||
| resource "aws_kms_key" "backup_notifications" { | ||
| description = "KMS key for AWS Backup notifications" | ||
| deletion_window_in_days = 7 | ||
| enable_key_rotation = true | ||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Effect = "Allow" | ||
| Sid = "Enable IAM User Permissions" | ||
| Principal = { | ||
| AWS = "arn:aws:iam::${var.assume_account}:root" | ||
| } | ||
| Action = "kms:*" | ||
| Resource = "*" | ||
| }, | ||
| { | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "sns.amazonaws.com" | ||
| } | ||
| Action = ["kms:GenerateDataKey*", "kms:Decrypt"] | ||
| Resource = "*" | ||
| }, | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| # Now we can deploy the source and destination modules, referencing the resources we've created above. | ||
|
|
||
| module "source" { | ||
| source = "../modules/backup-source" | ||
|
|
||
| backup_copy_vault_account_id = jsondecode(data.aws_secretsmanager_secret_version.backup_destination_parameters.secret_string)["account-id"] | ||
| backup_copy_vault_arn = jsondecode(data.aws_secretsmanager_secret_version.backup_destination_parameters.secret_string)["vault-arn"] | ||
| environment_name = local.environment | ||
| bootstrap_kms_key_arn = aws_kms_key.backup_notifications.arn | ||
| project_name = "${local.prefix}-" | ||
| reports_bucket = aws_s3_bucket.backup_reports.bucket | ||
| terraform_role_arn = "arn:aws:iam::${var.assume_account}:role/${var.assume_role}" | ||
|
|
||
| notification_target_email_addresses = local.notification_emails | ||
|
|
||
| backup_plan_config = { | ||
| "compliance_resource_types" : [ | ||
| "S3" | ||
| ], | ||
| "enable" = true, | ||
| "rules" : [ | ||
| { | ||
| "copy_action" : { | ||
| "delete_after" : 4 | ||
| }, | ||
| "lifecycle" : { | ||
| "delete_after" : 2 | ||
| }, | ||
| "name" : "daily_kept_for_2_days", | ||
| "schedule" : "cron(0 0 * * ? *)" | ||
| } | ||
| ], | ||
| "selection_tag" : "NHSE-Enable-S3-Backup" | ||
| } | ||
|
|
||
| backup_plan_config_dynamodb = { | ||
| "compliance_resource_types" : [ | ||
| "DynamoDB" | ||
| ], | ||
| "enable" : true, | ||
| "rules" : [ | ||
| { | ||
| "copy_action" : { | ||
| "delete_after" : 4 | ||
| }, | ||
| "lifecycle" : { | ||
| "delete_after" : 2 | ||
| }, | ||
| "name" : "daily_kept_for_2_days", | ||
| "schedule" : "cron(0 0 * * ? *)" | ||
| } | ||
| ], | ||
| "selection_tag" : "NHSE-Enable-DDB-Backup" | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| data "aws_secretsmanager_secret_version" "identities_account_id" { | ||
| secret_id = aws_secretsmanager_secret.identities_account_id.name | ||
| } | ||
|
|
||
| data "aws_secretsmanager_secret_version" "backup_destination_parameters" { | ||
| secret_id = aws_secretsmanager_secret.backup_destination_parameters.name | ||
| } | ||
|
|
||
| data "aws_secretsmanager_secret" "emails" { | ||
| name = "${local.prefix}-emails" | ||
| } | ||
|
|
||
| data "aws_secretsmanager_secret_version" "emails" { | ||
| secret_id = data.aws_secretsmanager_secret.emails.id | ||
| } |
5 changes: 3 additions & 2 deletions
5
terraform/account-wide-infrastructure/dev/dynamodb__pointers-table.tf
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.