Skip to content

Commit ce7bc72

Browse files
committed
Merge branch 'master' into feat/directory_bucket
2 parents ef6f159 + 5475b21 commit ce7bc72

File tree

10 files changed

+80
-19
lines changed

10 files changed

+80
-19
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [4.5.0](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/compare/v4.4.0...v4.5.0) (2025-01-23)
6+
7+
8+
### Features
9+
10+
* Add optional policy to deny ssec encrypted uploads ([#307](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/issues/307)) ([cfd1452](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/commit/cfd14526fc7f063a43bced5be7db1e4ed3c6f276))
11+
12+
## [4.4.0](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/compare/v4.3.0...v4.4.0) (2025-01-13)
13+
14+
15+
### Features
16+
17+
* Add variable create_lambda_permission in notification module ([#302](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/issues/302)) ([5b71671](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/commit/5b71671533487eec264152701a8e1d11a3113ea9))
18+
519
## [4.3.0](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/compare/v4.2.2...v4.3.0) (2024-12-21)
620

721

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ No modules.
172172
| [aws_iam_policy_document.deny_incorrect_encryption_headers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
173173
| [aws_iam_policy_document.deny_incorrect_kms_key_sse](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
174174
| [aws_iam_policy_document.deny_insecure_transport](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
175+
| [aws_iam_policy_document.deny_ssec_encrypted_object_uploads](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
175176
| [aws_iam_policy_document.deny_unencrypted_object_uploads](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
176177
| [aws_iam_policy_document.elb_log_delivery](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
177178
| [aws_iam_policy_document.inventory_and_analytics_destination_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -198,6 +199,7 @@ No modules.
198199
| <a name="input_attach_deny_incorrect_encryption_headers"></a> [attach\_deny\_incorrect\_encryption\_headers](#input\_attach\_deny\_incorrect\_encryption\_headers) | Controls if S3 bucket should deny incorrect encryption headers policy attached. | `bool` | `false` | no |
199200
| <a name="input_attach_deny_incorrect_kms_key_sse"></a> [attach\_deny\_incorrect\_kms\_key\_sse](#input\_attach\_deny\_incorrect\_kms\_key\_sse) | Controls if S3 bucket policy should deny usage of incorrect KMS key SSE. | `bool` | `false` | no |
200201
| <a name="input_attach_deny_insecure_transport_policy"></a> [attach\_deny\_insecure\_transport\_policy](#input\_attach\_deny\_insecure\_transport\_policy) | Controls if S3 bucket should have deny non-SSL transport policy attached | `bool` | `false` | no |
202+
| <a name="input_attach_deny_ssec_encrypted_object_uploads"></a> [attach\_deny\_ssec\_encrypted\_object\_uploads](#input\_attach\_deny\_ssec\_encrypted\_object\_uploads) | Controls if S3 bucket should deny SSEC encrypted object uploads. | `bool` | `false` | no |
201203
| <a name="input_attach_deny_unencrypted_object_uploads"></a> [attach\_deny\_unencrypted\_object\_uploads](#input\_attach\_deny\_unencrypted\_object\_uploads) | Controls if S3 bucket should deny unencrypted object uploads policy attached. | `bool` | `false` | no |
202204
| <a name="input_attach_elb_log_delivery_policy"></a> [attach\_elb\_log\_delivery\_policy](#input\_attach\_elb\_log\_delivery\_policy) | Controls if S3 bucket should have ELB log delivery policy attached | `bool` | `false` | no |
203205
| <a name="input_attach_inventory_destination_policy"></a> [attach\_inventory\_destination\_policy](#input\_attach\_inventory\_destination\_policy) | Controls if S3 bucket should have bucket inventory destination policy attached. | `bool` | `false` | no |

examples/complete/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,15 @@ module "s3_bucket" {
139139
}
140140

141141
# Bucket policies
142-
attach_policy = true
143-
policy = data.aws_iam_policy_document.bucket_policy.json
144-
attach_deny_insecure_transport_policy = true
145-
attach_require_latest_tls_policy = true
146-
attach_deny_incorrect_encryption_headers = true
147-
attach_deny_incorrect_kms_key_sse = true
148-
allowed_kms_key_arn = aws_kms_key.objects.arn
149-
attach_deny_unencrypted_object_uploads = true
142+
attach_policy = true
143+
policy = data.aws_iam_policy_document.bucket_policy.json
144+
attach_deny_insecure_transport_policy = true
145+
attach_require_latest_tls_policy = true
146+
attach_deny_incorrect_encryption_headers = true
147+
attach_deny_incorrect_kms_key_sse = true
148+
allowed_kms_key_arn = aws_kms_key.objects.arn
149+
attach_deny_unencrypted_object_uploads = true
150+
attach_deny_ssec_encrypted_object_uploads = true
150151

151152
# S3 bucket-level Public Access Block configuration (by default now AWS has made this default as true for S3 bucket-level block public access)
152153
# block_public_acls = true

main.tf

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ locals {
1212

1313
create_bucket_acl = (var.acl != null && var.acl != "null") || length(local.grants) > 0
1414

15-
attach_policy = var.attach_require_latest_tls_policy || var.attach_access_log_delivery_policy || var.attach_elb_log_delivery_policy || var.attach_lb_log_delivery_policy || var.attach_deny_insecure_transport_policy || var.attach_inventory_destination_policy || var.attach_deny_incorrect_encryption_headers || var.attach_deny_incorrect_kms_key_sse || var.attach_deny_unencrypted_object_uploads || var.attach_policy
15+
attach_policy = var.attach_require_latest_tls_policy || var.attach_access_log_delivery_policy || var.attach_elb_log_delivery_policy || var.attach_lb_log_delivery_policy || var.attach_deny_insecure_transport_policy || var.attach_inventory_destination_policy || var.attach_deny_incorrect_encryption_headers || var.attach_deny_incorrect_kms_key_sse || var.attach_deny_unencrypted_object_uploads || var.attach_deny_ssec_encrypted_object_uploads || var.attach_policy
1616

1717
# Variables with type `any` should be jsonencode()'d when value is coming from Terragrunt
1818
grants = try(jsondecode(var.grant), var.grant)
@@ -558,6 +558,7 @@ data "aws_iam_policy_document" "combined" {
558558
var.attach_require_latest_tls_policy ? data.aws_iam_policy_document.require_latest_tls[0].json : "",
559559
var.attach_deny_insecure_transport_policy ? data.aws_iam_policy_document.deny_insecure_transport[0].json : "",
560560
var.attach_deny_unencrypted_object_uploads ? data.aws_iam_policy_document.deny_unencrypted_object_uploads[0].json : "",
561+
var.attach_deny_ssec_encrypted_object_uploads ? data.aws_iam_policy_document.deny_ssec_encrypted_object_uploads[0].json : "",
561562
var.attach_deny_incorrect_kms_key_sse ? data.aws_iam_policy_document.deny_incorrect_kms_key_sse[0].json : "",
562563
var.attach_deny_incorrect_encryption_headers ? data.aws_iam_policy_document.deny_incorrect_encryption_headers[0].json : "",
563564
var.attach_inventory_destination_policy || var.attach_analytics_destination_policy ? data.aws_iam_policy_document.inventory_and_analytics_destination_policy[0].json : "",
@@ -908,6 +909,34 @@ data "aws_iam_policy_document" "deny_unencrypted_object_uploads" {
908909
}
909910
}
910911

912+
data "aws_iam_policy_document" "deny_ssec_encrypted_object_uploads" {
913+
count = local.create_bucket && var.attach_deny_ssec_encrypted_object_uploads ? 1 : 0
914+
915+
statement {
916+
sid = "denySSECEncryptedObjectUploads"
917+
effect = "Deny"
918+
919+
actions = [
920+
"s3:PutObject"
921+
]
922+
923+
resources = [
924+
"${aws_s3_bucket.this[0].arn}/*"
925+
]
926+
927+
principals {
928+
identifiers = ["*"]
929+
type = "*"
930+
}
931+
932+
condition {
933+
test = "Null"
934+
variable = "s3:x-amz-server-side-encryption-customer-algorithm"
935+
values = [false]
936+
}
937+
}
938+
}
939+
911940
resource "aws_s3_bucket_public_access_block" "this" {
912941
count = local.create_bucket && var.attach_public_policy ? 1 : 0
913942

modules/notification/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ No modules.
4040
| <a name="input_bucket"></a> [bucket](#input\_bucket) | Name of S3 bucket to use | `string` | `""` | no |
4141
| <a name="input_bucket_arn"></a> [bucket\_arn](#input\_bucket\_arn) | ARN of S3 bucket to use in policies | `string` | `null` | no |
4242
| <a name="input_create"></a> [create](#input\_create) | Whether to create this resource or not? | `bool` | `true` | no |
43+
| <a name="input_create_lambda_permission"></a> [create\_lambda\_permission](#input\_create\_lambda\_permission) | Whether to create Lambda permissions or not? | `bool` | `true` | no |
4344
| <a name="input_create_sns_policy"></a> [create\_sns\_policy](#input\_create\_sns\_policy) | Whether to create a policy for SNS permissions or not? | `bool` | `true` | no |
4445
| <a name="input_create_sqs_policy"></a> [create\_sqs\_policy](#input\_create\_sqs\_policy) | Whether to create a policy for SQS permissions or not? | `bool` | `true` | no |
4546
| <a name="input_eventbridge"></a> [eventbridge](#input\_eventbridge) | Whether to enable Amazon EventBridge notifications | `bool` | `null` | no |

modules/notification/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "aws_s3_bucket_notification" "this" {
6060

6161
# Lambda
6262
resource "aws_lambda_permission" "allow" {
63-
for_each = var.lambda_notifications
63+
for_each = { for k, v in var.lambda_notifications : k => v if var.create_lambda_permission }
6464

6565
statement_id_prefix = "AllowLambdaS3BucketNotification-"
6666
action = "lambda:InvokeFunction"

modules/notification/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ variable "create_sqs_policy" {
1616
default = true
1717
}
1818

19+
variable "create_lambda_permission" {
20+
description = "Whether to create Lambda permissions or not?"
21+
type = bool
22+
default = true
23+
}
24+
1925
variable "bucket" {
2026
description = "Name of S3 bucket to use"
2127
type = string

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ variable "attach_deny_unencrypted_object_uploads" {
8282
default = false
8383
}
8484

85+
variable "attach_deny_ssec_encrypted_object_uploads" {
86+
description = "Controls if S3 bucket should deny SSEC encrypted object uploads."
87+
type = bool
88+
default = false
89+
}
90+
8591
variable "bucket" {
8692
description = "(Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name."
8793
type = string

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module "wrapper" {
1717
attach_deny_incorrect_encryption_headers = try(each.value.attach_deny_incorrect_encryption_headers, var.defaults.attach_deny_incorrect_encryption_headers, false)
1818
attach_deny_incorrect_kms_key_sse = try(each.value.attach_deny_incorrect_kms_key_sse, var.defaults.attach_deny_incorrect_kms_key_sse, false)
1919
attach_deny_insecure_transport_policy = try(each.value.attach_deny_insecure_transport_policy, var.defaults.attach_deny_insecure_transport_policy, false)
20+
attach_deny_ssec_encrypted_object_uploads = try(each.value.attach_deny_ssec_encrypted_object_uploads, var.defaults.attach_deny_ssec_encrypted_object_uploads, false)
2021
attach_deny_unencrypted_object_uploads = try(each.value.attach_deny_unencrypted_object_uploads, var.defaults.attach_deny_unencrypted_object_uploads, false)
2122
attach_elb_log_delivery_policy = try(each.value.attach_elb_log_delivery_policy, var.defaults.attach_elb_log_delivery_policy, false)
2223
attach_inventory_destination_policy = try(each.value.attach_inventory_destination_policy, var.defaults.attach_inventory_destination_policy, false)

wrappers/notification/main.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ module "wrapper" {
33

44
for_each = var.items
55

6-
bucket = try(each.value.bucket, var.defaults.bucket, "")
7-
bucket_arn = try(each.value.bucket_arn, var.defaults.bucket_arn, null)
8-
create = try(each.value.create, var.defaults.create, true)
9-
create_sns_policy = try(each.value.create_sns_policy, var.defaults.create_sns_policy, true)
10-
create_sqs_policy = try(each.value.create_sqs_policy, var.defaults.create_sqs_policy, true)
11-
eventbridge = try(each.value.eventbridge, var.defaults.eventbridge, null)
12-
lambda_notifications = try(each.value.lambda_notifications, var.defaults.lambda_notifications, {})
13-
sns_notifications = try(each.value.sns_notifications, var.defaults.sns_notifications, {})
14-
sqs_notifications = try(each.value.sqs_notifications, var.defaults.sqs_notifications, {})
6+
bucket = try(each.value.bucket, var.defaults.bucket, "")
7+
bucket_arn = try(each.value.bucket_arn, var.defaults.bucket_arn, null)
8+
create = try(each.value.create, var.defaults.create, true)
9+
create_lambda_permission = try(each.value.create_lambda_permission, var.defaults.create_lambda_permission, true)
10+
create_sns_policy = try(each.value.create_sns_policy, var.defaults.create_sns_policy, true)
11+
create_sqs_policy = try(each.value.create_sqs_policy, var.defaults.create_sqs_policy, true)
12+
eventbridge = try(each.value.eventbridge, var.defaults.eventbridge, null)
13+
lambda_notifications = try(each.value.lambda_notifications, var.defaults.lambda_notifications, {})
14+
sns_notifications = try(each.value.sns_notifications, var.defaults.sns_notifications, {})
15+
sqs_notifications = try(each.value.sqs_notifications, var.defaults.sqs_notifications, {})
1516
}

0 commit comments

Comments
 (0)