-
Notifications
You must be signed in to change notification settings - Fork 49
/
CloudWatchAlarmsForCloudTrailAPIActivity-Template.yaml
371 lines (350 loc) · 13.9 KB
/
CloudWatchAlarmsForCloudTrailAPIActivity-Template.yaml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#
# Taken From the AWS Suggested Template found at:
# https://s3-us-west-2.amazonaws.com/awscloudtrail/cloudwatch-alarms-for-cloudtrail-api-activity/CloudWatch_Alarms_for_CloudTrail_API_Activity.json
#
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudTrail API Activity Alarm Template for CloudWatch Logs
Parameters:
pLogGroupName:
Type: String
Default: CloudTrail/DefaultLogGroup
Description: Enter CloudWatch Logs log group name. Default is CloudTrail/DefaultLogGroup
pParanoiaLevel:
Type: String
Description: Level of alerting to use (defined in mappings)
Default: TopicAlertsNormal
AllowedValues:
- TopicAlertsNormal
- TopicAlertsParanoid
- TopicAlertsLax
pDashboardName:
Type: String
Description: Name of the Dashboard to create with the Alerts and Stuff
Default: Security
Mappings:
TopicAlertsNormal:
SecurityGroupChangesAlarm:
TopicArn: SNSAlertsInfoArn
# Covers NACL, Gateway, & VPC changes
VpcChangesAlarm:
TopicArn: SNSAlertsCriticalArn
ConsoleSignInFailuresAlarm:
TopicArn: SNSAlertsErrorArn
EC2InstanceChangesAlarm:
TopicArn: SNSAlertsInfoArn
EC2LargeInstanceChangesAlarm:
TopicArn: SNSAlertsErrorArn
CloudTrailChangesAlarm:
TopicArn: SNSAlertsCriticalArn
IAMPolicyChangesAlarm:
TopicArn: SNSAlertsInfoArn
TopicAlertsParanoid:
SecurityGroupChangesAlarm:
TopicArn: SNSAlertsErrorArn
# Covers NACL, Gateway, & VPC changes
VpcChangesAlarm:
TopicArn: SNSAlertsCriticalArn
ConsoleSignInFailuresAlarm:
TopicArn: SNSAlertsErrorArn
EC2InstanceChangesAlarm:
TopicArn: SNSAlertsErrorArn
EC2LargeInstanceChangesAlarm:
TopicArn: SNSAlertsErrorArn
CloudTrailChangesAlarm:
TopicArn: SNSAlertsCriticalArn
IAMPolicyChangesAlarm:
TopicArn: SNSAlertsCriticalArn
TopicAlertsLax:
SecurityGroupChangesAlarm:
TopicArn: SNSAlertsInfoArn
# Covers NACL, Gateway, & VPC changes
VpcChangesAlarm:
TopicArn: SNSAlertsInfoArn
ConsoleSignInFailuresAlarm:
TopicArn: SNSAlertsInfoArn
EC2InstanceChangesAlarm:
TopicArn: SNSAlertsInfoArn
EC2LargeInstanceChangesAlarm:
TopicArn: SNSAlertsInfoArn
CloudTrailChangesAlarm:
TopicArn: SNSAlertsInfoArn
IAMPolicyChangesAlarm:
TopicArn: SNSAlertsInfoArn
# Each Resource consists of a Metric Filter and an Alarm on that Metric Filter
Resources:
# Info level alert as these happen frequently
SecurityGroupChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = AuthorizeSecurityGroupIngress) || ($.eventName
= AuthorizeSecurityGroupEgress) || ($.eventName = RevokeSecurityGroupIngress)
|| ($.eventName = RevokeSecurityGroupEgress) || ($.eventName = CreateSecurityGroup)
|| ($.eventName = DeleteSecurityGroup) }'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: SecurityGroupEventCount
MetricValue: '1'
SecurityGroupChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailSecurityGroupChanges
AlarmDescription: Alarms when an API call is made to create, update or delete a Security Group.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, SecurityGroupChangesAlarm, TopicArn ]
MetricName: SecurityGroupEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
# Error Level Event, this should be infrequent
NetworkAclChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = CreateNetworkAcl) || ($.eventName = CreateNetworkAclEntry)
|| ($.eventName = DeleteNetworkAcl) || ($.eventName = DeleteNetworkAclEntry)
|| ($.eventName = ReplaceNetworkAclEntry) || ($.eventName = ReplaceNetworkAclAssociation)
}'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: NetworkAclEventCount
MetricValue: '1'
NetworkAclChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailNetworkAclChanges
AlarmDescription: Alarms when an API call is made to create, update or delete a Network ACL.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, VpcChangesAlarm, TopicArn ]
MetricName: NetworkAclEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
GatewayChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = CreateCustomerGateway) || ($.eventName = DeleteCustomerGateway)
|| ($.eventName = AttachInternetGateway) || ($.eventName = CreateInternetGateway)
|| ($.eventName = DeleteInternetGateway) || ($.eventName = DetachInternetGateway)
}'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: GatewayEventCount
MetricValue: '1'
GatewayChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailGatewayChanges
AlarmDescription: Alarms when an API call is made to create, update or delete
a Customer or Internet Gateway.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, VpcChangesAlarm, TopicArn ]
MetricName: GatewayEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
VpcChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = CreateVpc) || ($.eventName = DeleteVpc) ||
($.eventName = ModifyVpcAttribute) || ($.eventName = AcceptVpcPeeringConnection)
|| ($.eventName = CreateVpcPeeringConnection) || ($.eventName = DeleteVpcPeeringConnection)
|| ($.eventName = RejectVpcPeeringConnection) || ($.eventName = AttachClassicLinkVpc)
|| ($.eventName = DetachClassicLinkVpc) || ($.eventName = DisableVpcClassicLink)
|| ($.eventName = EnableVpcClassicLink) }'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: VpcEventCount
MetricValue: '1'
VpcChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailVpcChanges
AlarmDescription: Alarms when an API call is made to create, update or delete
a VPC, VPC peering connection or VPC connection to classic.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, VpcChangesAlarm, TopicArn ]
MetricName: VpcEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
EC2InstanceChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = RunInstances) || ($.eventName = RebootInstances)
|| ($.eventName = StartInstances) || ($.eventName = StopInstances) || ($.eventName
= TerminateInstances) }'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: EC2InstanceEventCount
MetricValue: '1'
EC2InstanceChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailEC2InstanceChanges
AlarmDescription: Alarms when an API call is made to create, terminate, start, stop or reboot an EC2 instance.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, EC2InstanceChangesAlarm, TopicArn ]
MetricName: EC2InstanceEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
EC2LargeInstanceChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = RunInstances) && (($.requestParameters.instanceType
= *.8xlarge) || ($.requestParameters.instanceType = *.4xlarge)) }'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: EC2LargeInstanceEventCount
MetricValue: '1'
EC2LargeInstanceChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailEC2LargeInstanceChanges
AlarmDescription: Alarms when an API call is made to create, terminate, start, stop or reboot a 4x or 8x-large EC2 instance.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, EC2LargeInstanceChangesAlarm, TopicArn ]
MetricName: EC2LargeInstanceEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
CloudTrailChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = CreateTrail) || ($.eventName = UpdateTrail)
|| ($.eventName = DeleteTrail) || ($.eventName = StartLogging) || ($.eventName
= StopLogging) }'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: CloudTrailEventCount
MetricValue: '1'
CloudTrailChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailChanges
AlarmDescription: Alarms when an API call is made to create, update or delete a CloudTrail trail, or to start or stop logging to a trail.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, CloudTrailChangesAlarm, TopicArn ]
MetricName: CloudTrailEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
ConsoleSignInFailuresMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.eventName = ConsoleLogin) && ($.errorMessage = "Failed authentication") }'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: ConsoleSignInFailureCount
MetricValue: '1'
ConsoleSignInFailuresAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailConsoleSignInFailures
AlarmDescription: Alarms when an unauthenticated API call is made to sign int the console.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, ConsoleSignInFailuresAlarm, TopicArn ]
MetricName: ConsoleSignInFailureCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '3'
TreatMissingData: notBreaching
AuthorizationFailuresMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{ ($.errorCode = "*UnauthorizedOperation") || ($.errorCode = "AccessDenied*") && $.userIdentity.invokedBy != "AWS Internal" }'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: AuthorizationFailureCount
MetricValue: '1'
AuthorizationFailuresAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailAuthorizationFailures
AlarmDescription: Alarms when an unauthorized API call is made.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, ConsoleSignInFailuresAlarm, TopicArn ]
MetricName: AuthorizationFailureCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
IAMPolicyChangesMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref pLogGroupName
FilterPattern: '{($.eventName=DeleteGroupPolicy)||($.eventName=DeleteRolePolicy)||($.eventName=DeleteUserPolicy)||($.eventName=PutGroupPolicy)||($.eventName=PutRolePolicy)||($.eventName=PutUserPolicy)||($.eventName=CreatePolicy)||($.eventName=DeletePolicy)||($.eventName=CreatePolicyVersion)||($.eventName=DeletePolicyVersion)||($.eventName=AttachRolePolicy)||($.eventName=DetachRolePolicy)||($.eventName=AttachUserPolicy)||($.eventName=DetachUserPolicy)||($.eventName=AttachGroupPolicy)||($.eventName=DetachGroupPolicy)}'
MetricTransformations:
- MetricNamespace: CloudTrailMetrics
MetricName: IAMPolicyEventCount
MetricValue: '1'
IAMPolicyChangesAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: CloudTrailIAMPolicyChanges
AlarmDescription: Alarms when an API call is made to change an IAM policy.
AlarmActions:
- Fn::ImportValue:
Fn::FindInMap: [ !Ref pParanoiaLevel, IAMPolicyChangesAlarm, TopicArn ]
MetricName: IAMPolicyEventCount
Namespace: CloudTrailMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '300'
Statistic: Sum
Threshold: '1'
TreatMissingData: notBreaching
Outputs:
TemplateVersion:
Value: 1.0.0