Skip to content

Commit 5819b08

Browse files
committed
Adding bucket default encryption and policy
1 parent cb30195 commit 5819b08

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

main.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ resource "aws_s3_bucket_acl" "this" {
2727
acl = "private"
2828
}
2929

30+
resource "aws_s3_bucket_ownership_controls" "this" {
31+
bucket = aws_s3_bucket.this.id
32+
33+
rule {
34+
object_ownership = "BucketOwnerEnforced"
35+
}
36+
}
37+
38+
resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
39+
bucket = aws_s3_bucket.this.bucket
40+
41+
rule {
42+
apply_server_side_encryption_by_default {
43+
sse_algorithm = "AES256"
44+
}
45+
}
46+
}
47+
3048
resource "aws_s3_bucket_website_configuration" "this" {
3149
bucket = aws_s3_bucket.this.id
3250

@@ -62,6 +80,40 @@ data "aws_iam_policy_document" "s3_this" {
6280
]
6381
}
6482
}
83+
statement {
84+
sid = "DenyIncorrectEncryptionHeader"
85+
effect = "Deny"
86+
actions = ["s3:PutObject"]
87+
resources = ["${aws_s3_bucket.this.arn}/*"]
88+
principals {
89+
type = "AWS"
90+
identifiers = [
91+
"*",
92+
]
93+
}
94+
condition {
95+
test = "StringNotEquals"
96+
variable = "s3:x-amz-server-side-encryption"
97+
values = ["AES256"]
98+
}
99+
}
100+
statement {
101+
sid = "DenyUnEncryptedObjectUploads"
102+
effect = "Deny"
103+
actions = ["s3:PutObject"]
104+
resources = ["${aws_s3_bucket.this.arn}/*"]
105+
principals {
106+
type = "AWS"
107+
identifiers = [
108+
"*",
109+
]
110+
}
111+
condition {
112+
test = "Null"
113+
variable = "s3:x-amz-server-side-encryption"
114+
values = ["true"]
115+
}
116+
}
65117
}
66118

67119
resource "aws_s3_bucket_policy" "this" {

0 commit comments

Comments
 (0)