-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudwatch.tf
More file actions
68 lines (61 loc) · 1.86 KB
/
cloudwatch.tf
File metadata and controls
68 lines (61 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
variable "cloudtrail_logs" {
type = string
}
variable "alert_email" {
type = string
}
data "aws_cloudwatch_log_group" "cloudtrail_logs" {
name = var.cloudtrail_logs
}
resource "aws_sns_topic" "honeypot-notifications" {
#tfsec:ignore:AWS016 - SNS topic encryption beyond scope of demo deployment
name = "honeypotAlarmsTopic"
delivery_policy = <<EOF
{
"http": {
"defaultHealthyRetryPolicy": {
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numRetries": 3,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 0,
"numMinDelayRetries": 0,
"backoffFunction": "linear"
},
"disableSubscriptionOverrides": false,
"defaultThrottlePolicy": {
"maxReceivesPerSecond": 1
}
}
}
EOF
}
resource "aws_cloudwatch_log_metric_filter" "honeyuser-metric" {
name = "HoneyUser_Activity"
pattern = "{ $.userIdentity.accessKeyId = ${aws_iam_access_key.honeyuser_key.id} }"
log_group_name = data.aws_cloudwatch_log_group.cloudtrail_logs.name
metric_transformation {
name = "HoneyUser_Activity"
namespace = "HoneyTokens-tf"
value = "1"
}
}
resource "aws_cloudwatch_metric_alarm" "honeyuser-activity" {
alarm_name = "honeyUserActivity"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "2"
metric_name = aws_cloudwatch_log_metric_filter.honeyuser-metric.name
namespace = "HoneyTokens-tf"
period = "60"
statistic = "Sum"
threshold = "0"
alarm_description = "Malicious activity from honey user"
alarm_actions = [aws_sns_topic.honeypot-notifications.arn]
treat_missing_data = "notBreaching"
datapoints_to_alarm = 1
}
resource "aws_sns_topic_subscription" "honeytoken_trigger" {
topic_arn = aws_sns_topic.honeypot-notifications.arn
protocol = "email"
endpoint = var.alert_email
}