Skip to content

Commit 30d165e

Browse files
[PRMP 862] Implement an AWS Transfer Family kill switch (#512)
Co-authored-by: Robert Gaskin <[email protected]>
1 parent 81ee2a4 commit 30d165e

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module "transfer_family_kill_switch_lambda" {
2+
source = "./modules/lambda"
3+
name = "TransferFamilyKillSwitch"
4+
handler = "handlers.transfer_family_kill_switch_handler.lambda_handler"
5+
6+
iam_role_policy_documents = [
7+
aws_iam_policy.transfer_family_kill_switch.policy,
8+
data.aws_iam_policy.aws_lambda_vpc_access_execution_role.policy,
9+
]
10+
11+
kms_deletion_window = var.kms_deletion_window
12+
13+
lambda_environment_variables = {
14+
WORKSPACE = terraform.workspace
15+
STAGING_STORE_BUCKET_NAME = "${terraform.workspace}-${var.staging_store_bucket_name}"
16+
}
17+
18+
is_gateway_integration_needed = false
19+
is_invoked_from_gateway = false
20+
21+
vpc_subnet_ids = length(data.aws_security_groups.virus_scanner_api.ids) == 1 ? module.ndr-vpc-ui.private_subnets : []
22+
vpc_security_group_ids = length(data.aws_security_groups.virus_scanner_api.ids) == 1 ? [data.aws_security_groups.virus_scanner_api.ids[0]] : []
23+
24+
depends_on = [
25+
aws_iam_policy.transfer_family_kill_switch,
26+
# aws_transfer_server.your_transfer_server, # if transfer family is ever defined in terraform
27+
aws_api_gateway_rest_api.ndr_doc_store_api,
28+
module.ndr-bulk-staging-store,
29+
module.ndr-lloyd-george-store,
30+
module.lloyd_george_reference_dynamodb_table,
31+
]
32+
}

infrastructure/policies.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,45 @@ resource "aws_iam_policy" "administrator_permission_restrictions" {
6767
Workspace = "core"
6868
}
6969
}
70+
71+
resource "aws_iam_policy" "transfer_family_kill_switch" {
72+
name = "${terraform.workspace}-transfer-family-kill-switch"
73+
description = "Permissions for Transfer kill switch Lambda"
74+
policy = jsonencode({
75+
Version = "2012-10-17",
76+
Statement = [
77+
{
78+
Sid = "DescribeAndStopTransferServers",
79+
Effect = "Allow",
80+
Action = [
81+
"transfer:DescribeServer",
82+
"transfer:StopServer",
83+
],
84+
Resource = [
85+
"arn:aws:transfer:${var.region}:${data.aws_caller_identity.current.account_id}:server/*",
86+
]
87+
},
88+
{
89+
Sid = "ListTransferServers",
90+
Effect = "Allow",
91+
Action = [
92+
"transfer:ListServers",
93+
],
94+
Resource = "*"
95+
},
96+
{
97+
Sid = "PublishTransferFamilyKillSwitchMetrics",
98+
Effect = "Allow",
99+
Action = [
100+
"cloudwatch:PutMetricData",
101+
],
102+
Resource = "*",
103+
Condition = {
104+
StringEquals = {
105+
"cloudwatch:namespace" = "Custom/TransferFamilyKillSwitch"
106+
}
107+
}
108+
}
109+
]
110+
})
111+
}

infrastructure/transfer_alarms.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
resource "aws_cloudwatch_metric_alarm" "transfer_family_kill_switch_stopped_server" {
2+
alarm_name = "${terraform.workspace}_transfer_family_kill_switch_stopped"
3+
namespace = "Custom/TransferFamilyKillSwitch"
4+
metric_name = "ServerStopped"
5+
statistic = "Sum"
6+
period = 60 #check every 10 mins
7+
evaluation_periods = 1
8+
comparison_operator = "GreaterThanThreshold"
9+
threshold = 0
10+
treat_missing_data = "notBreaching"
11+
12+
dimensions = {
13+
Workspace = terraform.workspace
14+
}
15+
16+
alarm_description = "Alarm when the Transfer Family kill switch stops a server in workspace ${terraform.workspace}."
17+
18+
alarm_actions = [module.sqs_alarm_lambda_topic.arn]
19+
ok_actions = [module.sqs_alarm_lambda_topic.arn]
20+
21+
tags = {
22+
Name = "${terraform.workspace}_transfer_family_kill_switch_stopped"
23+
severity = "high"
24+
alarm_group = "${terraform.workspace}-transfer-family-kill-switch"
25+
alarm_metric = "ServerStopped"
26+
is_kpi = "false"
27+
}
28+
}

infrastructure/virusscanner.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,24 @@ resource "aws_sns_topic_subscription" "proactive_virus_scanning_notifications" {
103103
"scanResult" : ["Infected", "Error", "Unscannable", "Suspicious"]
104104
})
105105
}
106+
107+
resource "aws_sns_topic_subscription" "proactive_virus_scanning_kill_switch" {
108+
count = local.is_production ? 1 : 0
109+
topic_arn = module.cloud_storage_security[0].proactive_notifications_topic_arn
110+
protocol = "lambda"
111+
endpoint = module.transfer_family_kill_switch_lambda.lambda_arn
112+
113+
filter_policy = jsonencode({
114+
"notificationType" : ["scanResult"],
115+
"scanResult" : ["Infected", "Error", "Unscannable", "Suspicious"]
116+
})
117+
}
118+
119+
resource "aws_lambda_permission" "allow_sns_invoke_transfer_family_kill_switch" {
120+
count = local.is_production ? 1 : 0
121+
statement_id = "AllowExecutionFromVirusScanSNS"
122+
action = "lambda:InvokeFunction"
123+
function_name = module.transfer_family_kill_switch_lambda.lambda_arn
124+
principal = "sns.amazonaws.com"
125+
source_arn = module.cloud_storage_security[0].proactive_notifications_topic_arn
126+
}

0 commit comments

Comments
 (0)