Skip to content

Commit 5d10020

Browse files
committed
eli-327 fixing SSL transport as default, changing arn to id to avoid terraform constantly updating CMKs
1 parent e574e1e commit 5d10020

3 files changed

Lines changed: 70 additions & 35 deletions

File tree

infrastructure/modules/s3/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ output "storage_bucket_id" {
2121
output "storage_bucket_kms_key_arn" {
2222
value = aws_kms_key.storage_bucket_cmk.arn
2323
}
24+
25+
output "storage_bucket_kms_key_id" {
26+
value = aws_kms_key.storage_bucket_cmk.id
27+
}

infrastructure/modules/s3/s3.tf

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,6 @@ resource "aws_s3_bucket_versioning" "storage_bucket_versioning_config" {
1414
}
1515
}
1616

17-
# ensure only secure transport is allowed
18-
19-
resource "aws_s3_bucket_policy" "storage_bucket" {
20-
bucket = aws_s3_bucket.storage_bucket.id
21-
policy = data.aws_iam_policy_document.storage_s3_bucket_policy.json
22-
}
23-
24-
data "aws_iam_policy_document" "storage_s3_bucket_policy" {
25-
statement {
26-
sid = "AllowSslRequestsOnly"
27-
actions = [
28-
"s3:*",
29-
]
30-
effect = "Deny"
31-
resources = [
32-
aws_s3_bucket.storage_bucket.arn,
33-
"${aws_s3_bucket.storage_bucket.arn}/*",
34-
]
35-
principals {
36-
type = "*"
37-
identifiers = ["*"]
38-
}
39-
condition {
40-
test = "Bool"
41-
values = [
42-
"false",
43-
]
44-
45-
variable = "aws:SecureTransport"
46-
}
47-
}
48-
}
49-
5017
# Block public access to the bucket
5118
resource "aws_s3_bucket_public_access_block" "storage_bucket_block_public_access" {
5219
bucket = aws_s3_bucket.storage_bucket.id

infrastructure/stacks/api-layer/iam_policies.tf

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,70 @@ data "aws_iam_policy_document" "s3_rules_bucket_policy" {
7171
}
7272
}
7373

74+
# ensure only secure transport is allowed
75+
76+
resource "aws_s3_bucket_policy" "rules_s3_bucket" {
77+
bucket = module.s3_rules_bucket.storage_bucket_id
78+
policy = data.aws_iam_policy_document.rules_s3_bucket_policy.json
79+
}
80+
81+
data "aws_iam_policy_document" "rules_s3_bucket_policy" {
82+
statement {
83+
sid = "AllowSslRequestsOnly"
84+
actions = [
85+
"s3:*",
86+
]
87+
effect = "Deny"
88+
resources = [
89+
module.s3_rules_bucket.storage_bucket_arn,
90+
"${module.s3_rules_bucket.storage_bucket_arn}/*",
91+
]
92+
principals {
93+
type = "*"
94+
identifiers = ["*"]
95+
}
96+
condition {
97+
test = "Bool"
98+
values = [
99+
"false",
100+
]
101+
102+
variable = "aws:SecureTransport"
103+
}
104+
}
105+
}
106+
107+
resource "aws_s3_bucket_policy" "audit_s3_bucket" {
108+
bucket = module.s3_audit_bucket.storage_bucket_id
109+
policy = data.aws_iam_policy_document.audit_s3_bucket_policy.json
110+
}
111+
112+
data "aws_iam_policy_document" "audit_s3_bucket_policy" {
113+
statement {
114+
sid = "AllowSslRequestsOnly"
115+
actions = [
116+
"s3:*",
117+
]
118+
effect = "Deny"
119+
resources = [
120+
module.s3_audit_bucket.storage_bucket_arn,
121+
"${module.s3_audit_bucket.storage_bucket_arn}/*",
122+
]
123+
principals {
124+
type = "*"
125+
identifiers = ["*"]
126+
}
127+
condition {
128+
test = "Bool"
129+
values = [
130+
"false",
131+
]
132+
133+
variable = "aws:SecureTransport"
134+
}
135+
}
136+
}
137+
74138
# Attach s3 read policy to Lambda role
75139
resource "aws_iam_role_policy" "lambda_s3_read_policy" {
76140
name = "S3ReadAccess"
@@ -216,7 +280,7 @@ data "aws_iam_policy_document" "s3_rules_kms_key_policy" {
216280
}
217281

218282
resource "aws_kms_key_policy" "s3_rules_kms_key" {
219-
key_id = module.s3_rules_bucket.storage_bucket_kms_key_arn
283+
key_id = module.s3_rules_bucket.storage_bucket_kms_key_id
220284
policy = data.aws_iam_policy_document.s3_rules_kms_key_policy.json
221285
}
222286

@@ -253,7 +317,7 @@ data "aws_iam_policy_document" "s3_audit_kms_key_policy" {
253317
}
254318

255319
resource "aws_kms_key_policy" "s3_audit_kms_key" {
256-
key_id = module.s3_audit_bucket.storage_bucket_kms_key_arn
320+
key_id = module.s3_audit_bucket.storage_bucket_kms_key_id
257321
policy = data.aws_iam_policy_document.s3_audit_kms_key_policy.json
258322
}
259323

0 commit comments

Comments
 (0)