Skip to content

Commit 054e5ca

Browse files
mfjarvisdlzhry2nhs
authored andcommitted
Make id-sync SQS policy more restrictive. (#1186)
* Make id-sync SQS policy more restrictive. * Format tfvars files.
1 parent 4029062 commit 054e5ca

5 files changed

Lines changed: 55 additions & 11 deletions

File tree

infrastructure/instance/environments/prod/blue/variables.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
environment = "prod"
22
immunisation_account_id = "664418956997"
33
dspp_core_account_id = "232116723729"
4+
mns_account_id = "758334270304"
45
pds_environment = "prod"
56
error_alarm_notifications_enabled = true
67

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
environment = "prod"
22
immunisation_account_id = "664418956997"
33
dspp_core_account_id = "232116723729"
4+
mns_account_id = "758334270304"
45
pds_environment = "prod"
56
error_alarm_notifications_enabled = true
67

78
# mesh no invocation period metric set to 1 day (in seconds) for prod environment i.e 1 * 24 * 60 * 60
89
mesh_no_invocation_period_seconds = 86400
910
create_mesh_processor = true
1011
has_sub_environment_scope = false
11-
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"
12+
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"

infrastructure/instance/sqs_id_sync.tf

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,36 @@ resource "aws_sqs_queue_redrive_allow_policy" "id_sync_queue_redrive_allow_polic
2323

2424
data "aws_iam_policy_document" "id_sync_sqs_policy" {
2525
statement {
26-
sid = "id-sync-queue SQS statement"
26+
sid = "mns-allow-send"
2727
effect = "Allow"
2828

2929
principals {
3030
type = "AWS"
31-
identifiers = ["*"]
31+
identifiers = ["arn:aws:iam::${var.mns_account_id}:role/nhs-mns-events-lambda-delivery"]
3232
}
3333

3434
actions = [
3535
"sqs:SendMessage",
36-
"sqs:ReceiveMessage"
3736
]
37+
38+
resources = [
39+
aws_sqs_queue.id_sync_queue.arn
40+
]
41+
}
42+
43+
statement {
44+
sid = "id-sync-allow-receive"
45+
effect = "Allow"
46+
47+
principals {
48+
type = "AWS"
49+
identifiers = [aws_iam_role.id_sync_lambda_exec_role.arn]
50+
}
51+
52+
actions = [
53+
"sqs:ReceiveMessage",
54+
]
55+
3856
resources = [
3957
aws_sqs_queue.id_sync_queue.arn
4058
]

infrastructure/instance/variables.tf

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
variable "environment" {}
1+
variable "environment" {
2+
type = string
3+
description = "Environment (AWS Account) name - dev, preprod or prod"
4+
}
25

36
variable "sub_environment" {
4-
description = "The value is set in the makefile"
7+
type = string
8+
description = "Sub-environment name, e.g. internal-dev, internal-qa. The value is set in the Makefile"
59
}
610

7-
variable "immunisation_account_id" {}
8-
variable "dspp_core_account_id" {}
11+
variable "immunisation_account_id" {
12+
type = string
13+
description = "Immunisation AWS Account ID"
14+
}
15+
variable "dspp_core_account_id" {
16+
type = string
17+
description = "DSPP Core AWS Account ID"
18+
}
919
variable "csoc_account_id" {
10-
default = "693466633220"
20+
type = string
21+
description = "CSOC AWS Account ID - destination for forwarded logs"
22+
default = "693466633220"
23+
}
24+
variable "mns_account_id" {
25+
type = string
26+
description = "MNS AWS account ID - trusted source for MNS notifications"
27+
default = "631615744739"
1128
}
1229

1330
variable "dspp_kms_key_alias" {
@@ -17,18 +34,22 @@ variable "dspp_kms_key_alias" {
1734
}
1835

1936
variable "create_mesh_processor" {
37+
type = bool
2038
default = false
2139
}
2240

2341
variable "project_name" {
42+
type = string
2443
default = "immunisation"
2544
}
2645

2746
variable "project_short_name" {
47+
type = string
2848
default = "imms"
2949
}
3050

3151
variable "service" {
52+
type = string
3253
default = "fhir-api"
3354
}
3455

@@ -43,6 +64,7 @@ variable "aws_region" {
4364
}
4465

4566
variable "pds_environment" {
67+
type = string
4668
default = "int"
4769
}
4870

@@ -60,7 +82,9 @@ variable "error_alarm_notifications_enabled" {
6082
}
6183

6284
variable "has_sub_environment_scope" {
63-
default = false
85+
description = "True if the sub-environment is a standalone environment, e.g. internal-dev. False if it is part of a blue-green split, e.g. int-green."
86+
type = bool
87+
default = false
6488
}
6589

6690
locals {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"poetry -P quality_checks run ruff check --fix",
2727
"poetry -P quality_checks run ruff format"
2828
],
29-
"*.tf": "terraform fmt",
29+
"*.{tf,tfvars}": "terraform fmt",
3030
"immunisation-fhir-api.{yaml,json}": "redocly lint --skip-rule=security-defined"
3131
}
3232
}

0 commit comments

Comments
 (0)