Skip to content

Commit a031808

Browse files
CCM-8840 Adding S3 Access Logging (#341)
1 parent aceac3c commit a031808

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

infrastructure/terraform/components/acct/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
| Name | Source | Version |
2828
|------|--------|---------|
29+
| <a name="module_s3bucket_access_logs"></a> [s3bucket\_access\_logs](#module\_s3bucket\_access\_logs) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
2930
| <a name="module_s3bucket_backup_reports"></a> [s3bucket\_backup\_reports](#module\_s3bucket\_backup\_reports) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
3031
## Outputs
3132

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
module "s3bucket_access_logs" {
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket?ref=v1.0.8"
3+
4+
name = "access-logs"
5+
6+
aws_account_id = var.aws_account_id
7+
region = var.region
8+
project = var.project
9+
environment = var.environment
10+
component = var.component
11+
12+
acl = "private"
13+
force_destroy = false
14+
versioning = true
15+
16+
lifecycle_rules = [
17+
{
18+
enabled = true
19+
20+
noncurrent_version_transition = [
21+
{
22+
noncurrent_days = "30"
23+
storage_class = "STANDARD_IA"
24+
}
25+
]
26+
27+
noncurrent_version_expiration = {
28+
noncurrent_days = "90"
29+
}
30+
31+
abort_incomplete_multipart_upload = {
32+
days = "1"
33+
}
34+
}
35+
]
36+
37+
policy_documents = [
38+
data.aws_iam_policy_document.s3bucket_access_logs.json
39+
]
40+
41+
public_access = {
42+
block_public_acls = true
43+
block_public_policy = true
44+
ignore_public_acls = true
45+
restrict_public_buckets = true
46+
}
47+
48+
49+
default_tags = {
50+
Name = "S3 bucket access logs"
51+
}
52+
}
53+
54+
data "aws_iam_policy_document" "s3bucket_access_logs" {
55+
statement {
56+
sid = "DontAllowNonSecureConnection"
57+
effect = "Deny"
58+
59+
actions = [
60+
"s3:*",
61+
]
62+
63+
resources = [
64+
module.s3bucket_access_logs.arn,
65+
"${module.s3bucket_access_logs.arn}/*",
66+
]
67+
68+
principals {
69+
type = "AWS"
70+
71+
identifiers = [
72+
"*",
73+
]
74+
}
75+
76+
condition {
77+
test = "Bool"
78+
variable = "aws:SecureTransport"
79+
80+
values = [
81+
"false",
82+
]
83+
}
84+
}
85+
86+
statement {
87+
sid = "AllowManagedAccountsToList"
88+
effect = "Allow"
89+
90+
actions = [
91+
"s3:ListBucket",
92+
]
93+
94+
resources = [
95+
module.s3bucket_lambda_artefacts.arn,
96+
]
97+
98+
principals {
99+
type = "AWS"
100+
identifiers = [
101+
"arn:aws:iam::${var.aws_account_id}:root"
102+
]
103+
}
104+
}
105+
106+
statement {
107+
sid = "AllowManagedAccountsToGet"
108+
effect = "Allow"
109+
110+
actions = [
111+
"s3:GetObject",
112+
]
113+
114+
resources = [
115+
"${module.s3bucket_lambda_artefacts.arn}/*",
116+
]
117+
118+
principals {
119+
type = "AWS"
120+
identifiers = [
121+
"arn:aws:iam::${var.aws_account_id}:root"
122+
]
123+
}
124+
}
125+
126+
statement {
127+
sid = "AllowS3AccessLogging"
128+
effect = "Allow"
129+
130+
actions = [
131+
"s3:PutObject",
132+
]
133+
134+
resources = [
135+
"${module.s3bucket_access_logs.arn}/*",
136+
]
137+
138+
principals {
139+
type = "Service"
140+
141+
identifiers = [
142+
"logging.s3.amazonaws.com",
143+
]
144+
}
145+
}
146+
}

infrastructure/terraform/components/acct/module_s3bucket_backup_reports.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ module "s3bucket_backup_reports" {
3838
data.aws_iam_policy_document.s3bucket_backup_reports.json
3939
]
4040

41+
bucket_logging_target = {
42+
bucket = module.s3bucket_access_logs.id
43+
}
44+
4145
public_access = {
4246
block_public_acls = true
4347
block_public_policy = true

0 commit comments

Comments
 (0)