Skip to content

Commit acc91b6

Browse files
[PRMP 866] Alarm & Alerting for AWS Transfer Family kill switch (#523)
Co-authored-by: Robert Gaskin <[email protected]>
1 parent 49db814 commit acc91b6

File tree

5 files changed

+51
-16
lines changed

5 files changed

+51
-16
lines changed

infrastructure/lambda-transfer-kill-switch.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
module "transfer_kill_switch_lambda" {
1+
module "transfer_family_kill_switch_lambda" {
22
source = "./modules/lambda"
3-
name = "TransferKillSwitch"
4-
handler = "handlers.transfer_kill_switch_handler.lambda_handler"
3+
name = "TransferFamilyKillSwitch"
4+
handler = "handlers.transfer_family_kill_switch_handler.lambda_handler"
55

66
iam_role_policy_documents = [
7-
aws_iam_policy.transfer_kill_switch.policy,
7+
aws_iam_policy.transfer_family_kill_switch.policy,
88
data.aws_iam_policy.aws_lambda_vpc_access_execution_role.policy,
99
]
1010

@@ -22,7 +22,7 @@ module "transfer_kill_switch_lambda" {
2222
vpc_security_group_ids = length(data.aws_security_groups.virus_scanner_api.ids) == 1 ? [data.aws_security_groups.virus_scanner_api.ids[0]] : []
2323

2424
depends_on = [
25-
aws_iam_policy.transfer_kill_switch,
25+
aws_iam_policy.transfer_family_kill_switch,
2626
# aws_transfer_server.your_transfer_server, # if transfer family is ever defined in terraform
2727
aws_api_gateway_rest_api.ndr_doc_store_api,
2828
module.ndr-bulk-staging-store,

infrastructure/policies.tf

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ resource "aws_iam_policy" "administrator_permission_restrictions" {
6868
}
6969
}
7070

71-
resource "aws_iam_policy" "transfer_kill_switch" {
72-
name = "${terraform.workspace}-transfer-kill-switch"
71+
resource "aws_iam_policy" "transfer_family_kill_switch" {
72+
name = "${terraform.workspace}-transfer-family-kill-switch"
7373
description = "Permissions for Transfer kill switch Lambda"
7474
policy = jsonencode({
7575
Version = "2012-10-17",
@@ -92,6 +92,19 @@ resource "aws_iam_policy" "transfer_kill_switch" {
9292
"transfer:ListServers",
9393
],
9494
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+
}
95108
}
96109
]
97110
})

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/variable.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,3 @@ variable "kms_deletion_window" {
314314
type = number
315315
default = 30
316316
}
317-
318-
variable "transfer_server_id" {
319-
description = "AWS Transfer Family server ID used by the kill switch Lambda (e.g. s-0123456789abcdef0). Leave empty to disable stopping."
320-
type = string
321-
default = ""
322-
}

infrastructure/virusscanner.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ resource "aws_sns_topic_subscription" "proactive_virus_scanning_kill_switch" {
108108
count = local.is_production ? 1 : 0
109109
topic_arn = module.cloud_storage_security[0].proactive_notifications_topic_arn
110110
protocol = "lambda"
111-
endpoint = module.transfer_kill_switch_lambda.lambda_arn
111+
endpoint = module.transfer_family_kill_switch_lambda.lambda_arn
112112

113113
filter_policy = jsonencode({
114114
"notificationType" : ["scanResult"],
115115
"scanResult" : ["Infected", "Error", "Unscannable", "Suspicious"]
116116
})
117117
}
118118

119-
resource "aws_lambda_permission" "allow_sns_invoke_transfer_kill_switch" {
119+
resource "aws_lambda_permission" "allow_sns_invoke_transfer_family_kill_switch" {
120120
count = local.is_production ? 1 : 0
121121
statement_id = "AllowExecutionFromVirusScanSNS"
122122
action = "lambda:InvokeFunction"
123-
function_name = module.transfer_kill_switch_lambda.lambda_arn
123+
function_name = module.transfer_family_kill_switch_lambda.lambda_arn
124124
principal = "sns.amazonaws.com"
125125
source_arn = module.cloud_storage_security[0].proactive_notifications_topic_arn
126126
}

0 commit comments

Comments
 (0)