-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudtrail.yaml
More file actions
681 lines (637 loc) · 25.8 KB
/
Copy pathcloudtrail.yaml
File metadata and controls
681 lines (637 loc) · 25.8 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
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
---
# Copyright 2024 Electromech cloudtech Pvt. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Security: CloudTrail across all regions with a single workload region parameter'
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: 'Parent Stacks'
Parameters:
- ParentKmsKeyStack
- ParentAlertStack
- Label:
default: 'CloudTrail Parameters'
Parameters:
- CloudWatchLogsRetentionInDays
- ExternalTrailBucket
- LogFilePrefix
- S3DataEvents
- WorkloadRegion
- Label:
default: 'Permission Parameters'
Parameters:
- PermissionsBoundary
Parameters:
ParentKmsKeyStack:
Description: 'Optional Stack name of parent KMS key stack based on kms-key.yaml template.'
Type: String
Default: ''
ParentAlertStack:
Description: 'Optional but recommended stack name of parent alert stack based on alert.yaml template.'
Type: String
Default: ''
PermissionsBoundary:
Description: 'Optional ARN for a policy that will be used as the permission boundary for all roles created by this template.'
Type: String
Default: ''
CloudWatchLogsRetentionInDays:
Description: 'The number of days log events are kept in CloudWatch Logs'
Type: Number
Default: 14
AllowedValues: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]
ExternalTrailBucket:
Description: 'Optional The name of the Amazon S3 bucket where CloudTrail publishes log files. If you leave this empty, the Amazon S3 bucket is created for you.'
Type: String
Default: ''
LogFilePrefix:
Description: 'Optional The log file prefix.'
Type: String
Default: ''
S3DataEvents:
Description: 'Record data events of all S3 buckets? (Warning: additional charges apply.)'
Type: String
Default: 'false'
AllowedValues:
- 'true'
- 'false'
WorkloadRegion:
Description: "A single workload region. Example: ap-south-1"
Type: String
Default: ap-south-1
Conditions:
HasKmsKey: !Not [!Equals [!Ref ParentKmsKeyStack, '']]
HasAlertTopic: !Not [!Equals [!Ref ParentAlertStack, '']]
HasPermissionsBoundary: !Not [!Equals [!Ref PermissionsBoundary, '']]
InternalBucket: !Equals [!Ref ExternalTrailBucket, '']
ExternalBucket: !Not [!Equals [!Ref ExternalTrailBucket, '']]
HasLogFilePrefix: !Not [!Equals [!Ref LogFilePrefix, '']]
IsS3DataEvents: !Equals [!Ref S3DataEvents, 'true']
Resources:
TrailBucket:
Condition: InternalBucket
Type: 'AWS::S3::Bucket'
Properties: {}
TrailBucketPolicy:
Condition: InternalBucket
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: !Ref TrailBucket
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AWSCloudTrailAclCheck
Effect: Allow
Principal:
Service: 'cloudtrail.amazonaws.com'
Action: 's3:GetBucketAcl'
Resource: !Sub 'arn:aws:s3:::${TrailBucket}'
- Sid: AWSCloudTrailWrite
Effect: Allow
Principal:
Service: 'cloudtrail.amazonaws.com'
Action: 's3:PutObject'
Resource: !If
- HasLogFilePrefix
- !Sub 'arn:aws:s3:::${TrailBucket}/${LogFilePrefix}/AWSLogs/${AWS::AccountId}/*'
- !Sub 'arn:aws:s3:::${TrailBucket}/AWSLogs/${AWS::AccountId}/*'
Condition:
StringEquals:
's3:x-amz-acl': 'bucket-owner-full-control'
TrailLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
RetentionInDays: !Ref CloudWatchLogsRetentionInDays
TrailLogGroupRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AssumeRole1
Effect: Allow
Principal:
Service: 'cloudtrail.amazonaws.com'
Action: 'sts:AssumeRole'
PermissionsBoundary: !If [HasPermissionsBoundary, !Ref PermissionsBoundary, !Ref 'AWS::NoValue']
Policies:
- PolicyName: 'cloudtrail-policy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: !GetAtt 'TrailLogGroup.Arn'
TrailTopic:
Type: 'AWS::SNS::Topic'
Properties:
KmsMasterKeyId: !If
- HasKmsKey
- {'Fn::ImportValue': !Sub '${ParentKmsKeyStack}-KeyId'}
- !Ref 'AWS::NoValue'
TrailTopicPolicy:
Type: 'AWS::SNS::TopicPolicy'
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AWSCloudTrailSNSPolicy
Effect: Allow
Principal:
Service: 'cloudtrail.amazonaws.com'
Resource: !Ref TrailTopic
Action: 'sns:Publish'
Topics:
- !Ref TrailTopic
Trail:
Condition: InternalBucket
DependsOn:
- TrailBucketPolicy
- TrailTopicPolicy
Type: 'AWS::CloudTrail::Trail'
Properties:
IncludeGlobalServiceEvents: true
IsLogging: true
IsMultiRegionTrail: true
EventSelectors: !If
- IsS3DataEvents
- - DataResources:
- Type: 'AWS::S3::Object'
Values: ['arn:aws:s3:::']
IncludeManagementEvents: true
ReadWriteType: All
- !Ref 'AWS::NoValue'
S3BucketName: !Ref TrailBucket
S3KeyPrefix: !Ref LogFilePrefix
EnableLogFileValidation: true
CloudWatchLogsLogGroupArn: !GetAtt 'TrailLogGroup.Arn'
CloudWatchLogsRoleArn: !GetAtt 'TrailLogGroupRole.Arn'
SnsTopicName: !GetAtt 'TrailTopic.TopicName'
ExternalTrail:
Condition: ExternalBucket
DependsOn:
- TrailTopicPolicy
Type: 'AWS::CloudTrail::Trail'
Properties:
IncludeGlobalServiceEvents: true
IsLogging: true
IsMultiRegionTrail: true
EventSelectors: !If
- IsS3DataEvents
- - DataResources:
- Type: 'AWS::S3::Object'
Values: ['arn:aws:s3:::']
IncludeManagementEvents: true
ReadWriteType: All
- !Ref 'AWS::NoValue'
S3BucketName: !Ref ExternalTrailBucket
S3KeyPrefix: !Ref LogFilePrefix
EnableLogFileValidation: true
CloudWatchLogsLogGroupArn: !GetAtt 'TrailLogGroup.Arn'
CloudWatchLogsRoleArn: !GetAtt 'TrailLogGroupRole.Arn'
SnsTopicName: !GetAtt 'TrailTopic.TopicName'
# CIS 3.1
UnauthorizedOperationMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.errorCode = "*UnauthorizedOperation") || ($.errorCode = "AccessDenied*")}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'UnauthorizedOperationCount'
UnauthorizedOperationAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: unauthorized API calls detected'
Namespace: !Ref 'AWS::StackName'
MetricName: UnauthorizedOperationCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.2
NonMfaConsoleLoginMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = "ConsoleLogin") && ($.additionalEventData.MFAUsed != "Yes") && ($.userIdentity.type != "AssumedRole")}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'NonMfaConsoleLoginCount'
NonMfaConsoleLoginAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: Management Console sign-in without MFA detected'
Namespace: !Ref 'AWS::StackName'
MetricName: NonMfaConsoleLoginCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.3
RootUserActivityMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{$.userIdentity.type = "Root" && $.userIdentity.invokedBy NOT EXISTS && $.eventType != "AwsServiceEvent"}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'RootUserActivityCount'
RootUserActivityAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: usage of root account/user detected'
Namespace: !Ref 'AWS::StackName'
MetricName: RootUserActivityCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.4
IamPolicyChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
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)}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'IamPolicyChangeCount'
IamPolicyChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: IAM policy changes detected'
Namespace: !Ref 'AWS::StackName'
MetricName: IamPolicyChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.5
CloudTrailConfigChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = CreateTrail) || ($.eventName = UpdateTrail) || ($.eventName = DeleteTrail) || ($.eventName = StartLogging) || ($.eventName = StopLogging)}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'CloudTrailConfigChangeCount'
CloudTrailConfigChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: CloudTrail configuration changes detected'
Namespace: !Ref 'AWS::StackName'
MetricName: CloudTrailConfigChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.6
ManagementConsoleAuthFailureMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = ConsoleLogin) && ($.errorMessage = "Failed authentication")}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'ManagementConsoleAuthFailureCount'
ManagementConsoleAuthFailureAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: Management Console authentication failures detected'
Namespace: !Ref 'AWS::StackName'
MetricName: ManagementConsoleAuthFailureCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.7
DeletingKmsCmkMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventSource = kms.amazonaws.com) && (($.eventName=DisableKey) || ($.eventName=ScheduleKeyDeletion))}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'DeletingKmsCmkCount'
DeletingKmsCmkAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: disabling or scheduled deletion of customer created CMKs detected'
Namespace: !Ref 'AWS::StackName'
MetricName: DeletingKmsCmkCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.8
S3BucketPolicyChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventSource = s3.amazonaws.com) && (($.eventName = PutBucketAcl) || ($.eventName = PutBucketPolicy) || ($.eventName = PutBucketCors) || ($.eventName = PutBucketLifecycle) || ($.eventName = PutBucketReplication) || ($.eventName = DeleteBucketPolicy) || ($.eventName = DeleteBucketCors) || ($.eventName = DeleteBucketLifecycle) || ($.eventName = DeleteBucketReplication))}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'S3BucketPolicyChangeCount'
S3BucketPolicyChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: S3 bucket policy changes detected'
Namespace: !Ref 'AWS::StackName'
MetricName: S3BucketPolicyChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.9
ConfigChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventSource = config.amazonaws.com) && (($.eventName = StopConfigurationRecorder) || ($.eventName = DeleteDeliveryChannel) || ($.eventName = PutDeliveryChannel) || ($.eventName = PutConfigurationRecorder))}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'ConfigChangeCount'
ConfigChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: AWS Config configuration changes detected'
Namespace: !Ref 'AWS::StackName'
MetricName: ConfigChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# Single workload region logic for unauthorized operations outside this one region:
UnauthorizedOperationRegionMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
LogGroupName: !Ref TrailLogGroup
# We only compare against one region now.
FilterPattern: !Join
- ''
- - '{ ($.eventType = "AwsApiCall") && ($.awsRegion != "'
- !Ref WorkloadRegion
- '") }'
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'UnauthorizedOperationRegionCount'
UnauthorizedOperationRegionAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: Unauthorized Operation detected in non-allowed Region'
Namespace: !Ref 'AWS::StackName'
MetricName: UnauthorizedOperationRegionCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.10
SecurityGroupChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = AuthorizeSecurityGroupIngress) || ($.eventName = AuthorizeSecurityGroupEgress) || ($.eventName = RevokeSecurityGroupIngress) || ($.eventName = RevokeSecurityGroupEgress) || ($.eventName = CreateSecurityGroup) || ($.eventName = DeleteSecurityGroup)}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'SecurityGroupChangeCount'
SecurityGroupChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: security group changes detected'
Namespace: !Ref 'AWS::StackName'
MetricName: SecurityGroupChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.11
NaclChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = CreateNetworkAcl) || ($.eventName = CreateNetworkAclEntry) || ($.eventName = DeleteNetworkAcl) || ($.eventName = DeleteNetworkAclEntry) || ($.eventName = ReplaceNetworkAclEntry) || ($.eventName = ReplaceNetworkAclAssociation)}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'NaclChangeCount'
NaclChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: changes to Network Access Control List (NACL) detected'
Namespace: !Ref 'AWS::StackName'
MetricName: NaclChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.12
NetworkGatewayChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = CreateCustomerGateway) || ($.eventName = DeleteCustomerGateway) || ($.eventName = AttachInternetGateway) || ($.eventName = CreateInternetGateway) || ($.eventName = DeleteInternetGateway) || ($.eventName = DetachInternetGateway)}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'NetworkGatewayChangeChangeCount'
NetworkGatewayChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: changes to network gateways detected'
Namespace: !Ref 'AWS::StackName'
MetricName: NetworkGatewayChangeChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.13
RouteTableChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = CreateRoute) || ($.eventName = CreateRouteTable) || ($.eventName = ReplaceRoute) || ($.eventName = ReplaceRouteTableAssociation) || ($.eventName = DeleteRouteTable) || ($.eventName = DeleteRoute) || ($.eventName = DisassociateRouteTable)}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'RouteTableChangeCount'
RouteTableChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: changes to route tables detected'
Namespace: !Ref 'AWS::StackName'
MetricName: RouteTableChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# CIS 3.14
VpcChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventName = CreateVpc) || ($.eventName = DeleteVpc) || ($.eventName = ModifyVpcAttribute) || ($.eventName = AcceptVpcPeeringConnection) || ($.eventName = CreateVpcPeeringConnection) || ($.eventName = DeleteVpcPeeringConnection) || ($.eventName = RejectVpcPeeringConnection) || ($.eventName = AttachClassicLinkVpc) || ($.eventName = DetachClassicLinkVpc) || ($.eventName = DisableVpcClassicLink) || ($.eventName = EnableVpcClassicLink)}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'VpcChangeCount'
VpcTableChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: changes to VPCs detected'
Namespace: !Ref 'AWS::StackName'
MetricName: VpcChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
# Additional SecurityHub Alert Example
SecurityHubConfigChangeMetricFilter:
Condition: HasAlertTopic
Type: 'AWS::Logs::MetricFilter'
Properties:
FilterPattern: '{($.eventSource = securityhub.amazonaws.com) && (($.eventName = DisableSecurityHub) || ($.eventName = DisassociateFromMasterAccount) || ($.eventName = DisassociateMembers))}'
LogGroupName: !Ref TrailLogGroup
MetricTransformations:
- MetricValue: '1'
MetricNamespace: !Ref 'AWS::StackName'
MetricName: 'SecurityHubConfigChangeCount'
SecurityHubConfigChangeAlarm:
Condition: HasAlertTopic
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'CloudTrail: SecurityHub configuration changes detected'
Namespace: !Ref 'AWS::StackName'
MetricName: SecurityHubConfigChangeCount
Statistic: Sum
Period: 300
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- {'Fn::ImportValue': !Sub '${ParentAlertStack}-TopicARN'}
TreatMissingData: notBreaching
Outputs:
TemplateID:
Description: 'Template id.'
Value: 'cloudtrail'
TemplateVersion:
Description: 'Template version.'
Value: '__VERSION__'
StackName:
Description: 'Stack name.'
Value: !Sub '${AWS::StackName}'