Skip to content

Commit 3ba0f4a

Browse files
authored
Merge pull request #277 from NHSDigital/bugfix/eja-eli-388-enable-audit-logging-by-adding-permissions
eli-388 adding access log permissions for audit buckets
2 parents 0f07e27 + 43abb81 commit 3ba0f4a

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

  • infrastructure/modules/s3

infrastructure/modules/s3/s3.tf

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,57 @@ data "aws_iam_policy_document" "access_logs_s3_bucket_policy" {
105105
variable = "aws:SecureTransport"
106106
}
107107
}
108+
109+
# Allow S3 Log Delivery service to write access logs
110+
statement {
111+
sid = "S3ServerAccessLogsPolicy"
112+
effect = "Allow"
113+
principals {
114+
type = "Service"
115+
identifiers = ["logging.s3.amazonaws.com"]
116+
}
117+
actions = [
118+
"s3:PutObject"
119+
]
120+
resources = [
121+
"${aws_s3_bucket.storage_bucket_access_logs.arn}/*"
122+
]
123+
condition {
124+
test = "ArnEquals"
125+
variable = "aws:SourceArn"
126+
values = [aws_s3_bucket.storage_bucket.arn]
127+
}
128+
}
129+
130+
# Allow S3 Log Delivery service to check bucket location and get bucket ACL
131+
statement {
132+
sid = "S3ServerAccessLogsDeliveryRootAccess"
133+
effect = "Allow"
134+
principals {
135+
type = "Service"
136+
identifiers = ["logging.s3.amazonaws.com"]
137+
}
138+
actions = [
139+
"s3:GetBucketAcl",
140+
"s3:ListBucket"
141+
]
142+
resources = [
143+
aws_s3_bucket.storage_bucket_access_logs.arn
144+
]
145+
condition {
146+
test = "ArnEquals"
147+
variable = "aws:SourceArn"
148+
values = [aws_s3_bucket.storage_bucket.arn]
149+
}
150+
}
108151
}
109152

110153
resource "aws_s3_bucket_server_side_encryption_configuration" "storage_bucket_access_logs_server_side_encryption_config" {
111154
bucket = aws_s3_bucket.storage_bucket_access_logs.id
112155

113156
rule {
114157
apply_server_side_encryption_by_default {
115-
sse_algorithm = "aws:kms"
158+
sse_algorithm = "aws:kms"
116159
kms_master_key_id = aws_kms_key.storage_bucket_cmk.arn
117160
}
118161
}

0 commit comments

Comments
 (0)