-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VEGA-2289 - S3 Storage & Replication #minor (#103)
* VEGA-2289 - Add local localstack config and local lpa-store-static bucket #minor * VEGA-2289 - Add initial cross region S3 setup #minor * VEGA-2289 - Remove redundant keys and sort permissions for cross region replication #minor * VEGA-2289 - Add Accces Logging to ccount Buckets #minor * VEGA-2289 - Add Cross Account S3 Backup #minor * VEGA-2289 - Grant Lambda Roles S3 & KMS Permissions for Object Put #minor * VEGA-2289 - Move lambda policy rather than destroy/create #patch * VEGA-2289 - Remove Life Cycle configuration from S3 Modules as we want to keep everything #minor
- Loading branch information
1 parent
97fd851
commit 2619972
Showing
28 changed files
with
968 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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 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,33 @@ | ||
#! /usr/bin/env bash | ||
create_bucket() { | ||
BUCKET=$1 | ||
# Create Private Bucket | ||
awslocal s3api create-bucket \ | ||
--acl private \ | ||
--region eu-west-1 \ | ||
--create-bucket-configuration LocationConstraint=eu-west-1 \ | ||
--bucket "$BUCKET" | ||
|
||
# Add Public Access Block | ||
awslocal s3api put-public-access-block \ | ||
--public-access-block-configuration "BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true" \ | ||
--bucket "$BUCKET" | ||
|
||
# Add Default Encryption | ||
awslocal s3api put-bucket-encryption \ | ||
--bucket "$BUCKET" \ | ||
--server-side-encryption-configuration '{ "Rules": [ { "ApplyServerSideEncryptionByDefault": { "SSEAlgorithm": "AES256" } } ] }' | ||
|
||
# Add Encryption Policy | ||
awslocal s3api put-bucket-policy \ | ||
--policy '{ "Statement": [ { "Sid": "DenyUnEncryptedObjectUploads", "Effect": "Deny", "Principal": { "AWS": "*" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::'${BUCKET}'/*", "Condition": { "StringNotEquals": { "s3:x-amz-server-side-encryption": "AES256" } } }, { "Sid": "DenyUnEncryptedObjectUploads", "Effect": "Deny", "Principal": { "AWS": "*" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::'${BUCKET}'/*", "Condition": { "Bool": { "aws:SecureTransport": false } } } ] }' \ | ||
--bucket "$BUCKET" | ||
|
||
# Add Bucket Versioning | ||
awslocal s3api put-bucket-versioning \ | ||
--versioning-configuration '{ "MFADelete": "Disabled", "Status": "Enabled" }' \ | ||
--bucket "$BUCKET" | ||
} | ||
|
||
# S3 | ||
create_bucket "opg-lpa-store-static-eu-west-1" |
This file contains 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,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# S3 | ||
buckets=$(awslocal s3 ls) | ||
|
||
echo $buckets | grep "opg-lpa-store-static-eu-west-1" || exit 1 |
This file contains 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 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,3 @@ | ||
data "aws_caller_identity" "current" { | ||
provider = aws.eu_west_1 | ||
} |
This file contains 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,70 @@ | ||
moved { | ||
from = aws_iam_role_policy.lambda | ||
to = aws_iam_role_policy.lambda_dynamodb | ||
} | ||
|
||
resource "aws_iam_role_policy" "lambda_dynamodb" { | ||
for_each = local.functions | ||
name = "LambdaAllowDynamoDB" | ||
role = module.lambda[each.key].iam_role.id | ||
policy = data.aws_iam_policy_document.lambda_dynamodb_policy.json | ||
provider = aws.region | ||
} | ||
|
||
data "aws_iam_policy_document" "lambda_dynamodb_policy" { | ||
statement { | ||
sid = "allowDynamoDB" | ||
effect = "Allow" | ||
resources = [var.dynamodb_arn] | ||
actions = [ | ||
"dynamodb:PutItem", | ||
"dynamodb:GetItem", | ||
] | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy" "lambda_s3" { | ||
for_each = local.functions | ||
name = "LambdaAllowS3" | ||
role = module.lambda[each.key].iam_role.id | ||
policy = data.aws_iam_policy_document.lambda_s3_policy.json | ||
provider = aws.region | ||
} | ||
|
||
data "aws_iam_policy_document" "lambda_s3_policy" { | ||
statement { | ||
sid = "allowS3Access" | ||
effect = "Allow" | ||
resources = [ | ||
var.lpa_store_static_bucket.arn, | ||
"${var.lpa_store_static_bucket.arn}/*", | ||
] | ||
actions = [ | ||
"s3:PutObject", | ||
] | ||
} | ||
statement { | ||
sid = "allowS3KMS" | ||
effect = "Allow" | ||
resources = [var.lpa_store_static_bucket_kms_key.arn] | ||
actions = [ | ||
"kms:GenerateDataKey", | ||
"kms:Encrypt" | ||
] | ||
|
||
condition { | ||
test = "StringLike" | ||
variable = "kms:ViaService" | ||
values = ["s3.${data.aws_region.current.name}.amazonaws.com"] | ||
} | ||
|
||
condition { | ||
test = "StringLike" | ||
variable = "kms:EncryptionContext:aws:s3:arn" | ||
values = [ | ||
"${var.lpa_store_static_bucket.arn}/*", | ||
] | ||
} | ||
} | ||
} | ||
|
This file contains 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 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,9 @@ | ||
output "base_url" { | ||
value = "https://${local.domain_name}" | ||
} | ||
|
||
output "lambda_iam_roles" { | ||
value = [ | ||
for lambda in module.lambda : lambda.iam_role | ||
] | ||
} |
This file contains 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 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.