Skip to content

Commit 2a6c34d

Browse files
committed
CCM-12615: APIM Authentication
1 parent cc1c040 commit 2a6c34d

2 files changed

Lines changed: 176 additions & 0 deletions

File tree

infrastructure/terraform/components/dl/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ No requirements.
4040
| <a name="module_lambda_apim_key_generation"></a> [lambda\_apim\_key\_generation](#module\_lambda\_apim\_key\_generation) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
4141
| <a name="module_lambda_lambda_apim_refresh_token"></a> [lambda\_lambda\_apim\_refresh\_token](#module\_lambda\_lambda\_apim\_refresh\_token) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
4242
| <a name="module_mesh_poll"></a> [mesh\_poll](#module\_mesh\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
43+
| <a name="module_s3bucket_cf_logs"></a> [s3bucket\_cf\_logs](#module\_s3bucket\_cf\_logs) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |
4344
| <a name="module_s3bucket_letters"></a> [s3bucket\_letters](#module\_s3bucket\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
4445
| <a name="module_s3bucket_static_assets"></a> [s3bucket\_static\_assets](#module\_s3bucket\_static\_assets) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |
4546
| <a name="module_sqs_event_publisher_errors"></a> [sqs\_event\_publisher\_errors](#module\_sqs\_event\_publisher\_errors) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
module "s3bucket_cf_logs" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip"
3+
providers = {
4+
aws = aws.us-east-1
5+
}
6+
7+
name = "cf-logs"
8+
9+
aws_account_id = var.aws_account_id
10+
region = "us-east-1"
11+
project = var.project
12+
environment = var.environment
13+
component = var.component
14+
15+
acl = "private"
16+
force_destroy = var.force_destroy
17+
versioning = true
18+
19+
object_ownership = "ObjectWriter"
20+
21+
lifecycle_rules = [
22+
{
23+
prefix = ""
24+
enabled = true
25+
26+
transition = [
27+
{
28+
days = "90"
29+
storage_class = "STANDARD_IA"
30+
},
31+
{
32+
days = "180"
33+
storage_class = "GLACIER"
34+
}
35+
]
36+
37+
expiration = {
38+
days = "365"
39+
}
40+
41+
42+
noncurrent_version_transition = [
43+
{
44+
noncurrent_days = "30"
45+
storage_class = "STANDARD_IA"
46+
},
47+
{
48+
noncurrent_days = "180"
49+
storage_class = "GLACIER"
50+
}
51+
52+
]
53+
54+
noncurrent_version_expiration = {
55+
noncurrent_days = "365"
56+
}
57+
58+
abort_incomplete_multipart_upload = {
59+
days = "1"
60+
}
61+
}
62+
]
63+
64+
policy_documents = [
65+
data.aws_iam_policy_document.s3bucket_cf_logs.json
66+
]
67+
68+
bucket_logging_target = {
69+
bucket = local.acct.s3_buckets["access_logs_us"]["id"]
70+
}
71+
72+
public_access = {
73+
block_public_acls = true
74+
block_public_policy = true
75+
ignore_public_acls = true
76+
restrict_public_buckets = true
77+
}
78+
79+
default_tags = {
80+
Name = "Cloudfront Logs"
81+
}
82+
}
83+
84+
data "aws_iam_policy_document" "s3bucket_cf_logs" {
85+
statement {
86+
sid = "DontAllowNonSecureConnection"
87+
effect = "Deny"
88+
89+
actions = [
90+
"s3:*",
91+
]
92+
93+
resources = [
94+
module.s3bucket_cf_logs.arn,
95+
"${module.s3bucket_cf_logs.arn}/*",
96+
]
97+
98+
principals {
99+
type = "AWS"
100+
101+
identifiers = [
102+
"*",
103+
]
104+
}
105+
106+
condition {
107+
test = "Bool"
108+
variable = "aws:SecureTransport"
109+
110+
values = [
111+
"false",
112+
]
113+
}
114+
}
115+
116+
statement {
117+
effect = "Allow"
118+
actions = ["s3:PutObject"]
119+
resources = [
120+
"${module.s3bucket_cf_logs.arn}/*",
121+
]
122+
123+
principals {
124+
type = "Service"
125+
identifiers = ["logging.s3.amazonaws.com"]
126+
}
127+
condition {
128+
test = "StringEquals"
129+
variable = "aws:SourceAccount"
130+
values = [
131+
var.aws_account_id
132+
]
133+
}
134+
}
135+
136+
statement {
137+
sid = "AllowManagedAccountsToList"
138+
effect = "Allow"
139+
140+
actions = [
141+
"s3:ListBucket",
142+
]
143+
144+
resources = [
145+
module.s3bucket_cf_logs.arn,
146+
]
147+
148+
principals {
149+
type = "AWS"
150+
identifiers = [
151+
"arn:aws:iam::${var.aws_account_id}:root"
152+
]
153+
}
154+
}
155+
156+
statement {
157+
sid = "AllowManagedAccountsToGet"
158+
effect = "Allow"
159+
160+
actions = [
161+
"s3:GetObject",
162+
]
163+
164+
resources = [
165+
"${module.s3bucket_cf_logs.arn}/*",
166+
]
167+
168+
principals {
169+
type = "AWS"
170+
identifiers = [
171+
"arn:aws:iam::${var.aws_account_id}:root"
172+
]
173+
}
174+
}
175+
}

0 commit comments

Comments
 (0)