-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve syncer s3 kms encryption
manual merge of #1915 Co-authored-by: Julius Adamek <[email protected]>
- Loading branch information
Showing
5 changed files
with
65 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
*id_rsa* | ||
|
||
# other | ||
node_modules/ | ||
.idea | ||
.DS_Store | ||
*.out | ||
|
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 |
---|---|---|
|
@@ -35,7 +35,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "bucket-config" { | |
|
||
resource "aws_s3_bucket_server_side_encryption_configuration" "action_dist" { | ||
bucket = aws_s3_bucket.action_dist.id | ||
count = length(keys(lookup(var.server_side_encryption_configuration, "rule", {}))) == 0 ? 0 : 1 | ||
count = try(var.server_side_encryption_configuration, null) != null ? 1 : 0 | ||
|
||
dynamic "rule" { | ||
for_each = [lookup(var.server_side_encryption_configuration, "rule", {})] | ||
|
@@ -63,3 +63,41 @@ resource "aws_s3_bucket_public_access_block" "action_dist" { | |
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
} | ||
|
||
|
||
|
||
data "aws_iam_policy_document" "action_dist_sse_policy" { | ||
count = try(var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default, null) != null ? 1 : 0 | ||
|
||
statement { | ||
effect = "Deny" | ||
|
||
principals { | ||
type = "AWS" | ||
|
||
identifiers = [ | ||
"*", | ||
] | ||
} | ||
|
||
actions = [ | ||
"s3:PutObject", | ||
] | ||
|
||
resources = [ | ||
"${aws_s3_bucket.action_dist.arn}/*", | ||
] | ||
|
||
condition { | ||
test = "StringNotEquals" | ||
variable = "s3:x-amz-server-side-encryption" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
marekaf
Contributor
|
||
values = [var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default.sse_algorithm] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_policy" "action_dist_sse_policy" { | ||
count = try(var.server_side_encryption_configuration.rule.apply_server_side_encryption_by_default, null) != null ? 1 : 0 | ||
bucket = aws_s3_bucket.action_dist.id | ||
policy = data.aws_iam_policy_document.action_dist_sse_policy[0].json | ||
} |
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,10 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": ["kms:GenerateDataKey", "kms:Decrypt"], | ||
"Resource": "${kms_key_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
I'm not sure this works. I upgraded today the module to a version that has this and upload the s3 object trigger with terraform fails with an error. I had to manually delete the bucket policy to upload it successfully.