-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
821 lines (750 loc) · 26.5 KB
/
template.yaml
File metadata and controls
821 lines (750 loc) · 26.5 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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
SAM version of 609-Automating-Forensic-Disk-Collection.
Self-contained, can be installed in any number of regions.
Parameters:
ORGID:
Type: String
Default: o-0000000000
Description: AWS Organizations ID to Allow use of KMS key
ArtifactBucketName:
Type: String
Default: OpenSecOps-soar-forensic-artifacts
Description: Base name for the regional S3 bucket used to store forensic artifacts (account ID and region will be added)
ArtifactBucketExpirationInDays:
Type: Number
Default: 3650
Description: The number of days before artifact bucket objects expire
ForensicsAMIs:
Type: String
Default: "us-east-1: ami-000000000000, eu-west-1: ami-1111111111111"
Description: AMI identifier map for forensics image
AllowInvokeFromAccountId:
Type: String
Default: ''
Description:
To allow the DiskForensicsInvoke function to be called explicitly from another account, enter its
12-digit account number here. Otherwise, leave this parameter empty.
TerminateRogueAfterInitialSnapshot:
Type: String
AllowedValues: ['Yes', 'No']
Default: 'Yes'
Description:
Select Yes to terminate the rogue server after the initial snapshot has been captured.
Select No to leave it running.
InstanceType:
Type: String
Description: The name of the IAM Instance Type to use
Default: 'm5.large'
VPCCIDR:
Type: String
Default: 172.16.0.0/16
Description: Default VPC CIDR
AZ1Letter:
Type: String
Default: a
Description: Default AZ1 letter indicator (region will be used as a prefix)
AZ1CIDR:
Type: String
Default: 172.16.20.0/20
Description: Default AZ1 CIDR
AZ2Letter:
Type: String
Default: b
Description: Default AZ2 letter indicator (region will be used as a prefix)
AZ2CIDR:
Type: String
Default: 172.16.32.0/20
Description: Default AZ2 CIDR
MemberAutomationRole:
Type: String
Default: IR-Automation-Member-Role
Description: Base name of the member Automation Role (region will be added).
Do not change this parameter - it is used by an IAM Role with a hardcoded
name in diskMember.yaml.
ForensicAuditLogGroupName:
Type: String
Default: ForensicDiskAudit
Description: Name for the CloudWatch Log Group used for Forensic Audit Logs
ForensicReadinessLogGroupName:
Type: String
Default: ForensicDiskReadiness
Description: Name for the CloudWatch Log Group used for Forensic Readiness Logs
ForensicCaptureLogGroupName:
Type: String
Default: ForensicDiskCapture
Description: Name for the CloudWatch Log Group used for Forensic Capture Logs
EC2ForensicRole:
Type: String
Default: EC2ForensicsCollectionRole
Description: Base name of the EC2 instance profile (region will be added)
ForensicStepFunctionLogGroupName:
Type: String
Default: ForensicStepFunctionLogs
Description: Name for the CloudWatch Log Group used for Forensic Step Function Workflow
Globals:
Function:
Runtime: python3.12
Handler: lambda_function.lambda_handler
MemorySize: 128
Timeout: 15
Architectures:
- x86_64
Conditions:
AllowInvokeFromAccountIdBlank: !Equals
- !Ref AllowInvokeFromAccountId
- ''
CreateExternalPermissions: !Not
- !Condition AllowInvokeFromAccountIdBlank
Resources:
############################################################################
#
# forensicsResources
#
############################################################################
forensicsVPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: !Ref VPCCIDR
EnableDnsHostnames: true
Tags:
- Key: Name
Value: ForensicsVPC
forensicsSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone: !Sub '${AWS::Region}${AZ1Letter}'
CidrBlock: !Ref AZ1CIDR
VpcId: !Ref forensicsVPC
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: ForensicsSubnet1
forensicsSubnet2:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone: !Sub '${AWS::Region}${AZ2Letter}'
CidrBlock: !Ref AZ2CIDR
VpcId: !Ref forensicsVPC
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: ForensicsSubnet2
forensicsRT:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref forensicsVPC
Tags:
- Key: Name
Value: ForensicsRouteTable
forensicsSubnet1RTAttach:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref forensicsSubnet1
RouteTableId: !Ref forensicsRT
forensicsSubnet2RTAttach:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref forensicsSubnet2
RouteTableId: !Ref forensicsRT
S3Endpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3'
VpcId: !Ref forensicsVPC
RouteTableIds:
- !Ref forensicsRT
LogsServiceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Allow https to client host
VpcId: !Ref forensicsVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: LogsInterfaceEndpointSG
LogsEndpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
SecurityGroupIds:
- !Ref LogsServiceSecurityGroup
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.logs'
PrivateDnsEnabled: true
SubnetIds:
- !Ref forensicsSubnet1
- !Ref forensicsSubnet2
VpcEndpointType: Interface
VpcId: !Ref forensicsVPC
ForensicsCaptureSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Allow output to S3 and Logs to client host
VpcId: !Ref forensicsVPC
SecurityGroupEgress:
- IpProtocol: '-1'
Description: Allow Outbound access
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: ForensicsInstanceSG
ForensicEncryptionKey:
Type: 'AWS::KMS::Key'
Properties:
Description: KMS Key for Forensic capture and automation
Enabled: true
PendingWindowInDays: 7
KeyPolicy:
Version: 2012-10-17
Id: key-default-1
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Join
- ''
- - 'arn:aws:iam::'
- !Ref 'AWS::AccountId'
- ':root'
Action: 'kms:*'
Resource: '*'
- Sid: Allow use of the key and attachment of persistent resources
Effect: Allow
Principal:
AWS: '*'
Action:
- 'kms:Encrypt'
- 'kms:ReEncrypt*'
- 'kms:GenerateDataKey*'
- 'kms:DescribeKey'
Resource: '*'
Condition:
StringEquals:
'aws:PrincipalOrgID': !Ref ORGID
- Sid: Allow attachment of persistent resources
Effect: Allow
Principal:
AWS: '*'
Action:
- 'kms:CreateGrant'
- 'kms:ListGrants'
- 'kms:RevokeGrant'
Resource: '*'
Condition:
Bool:
'kms:GrantIsForAWSResource': 'true'
StringEquals:
'aws:PrincipalOrgID': !Ref ORGID
ForensicKeyAlias:
Type: 'AWS::KMS::Alias'
Properties:
AliasName: alias/ForensicEncryptionKey
TargetKeyId: !Ref ForensicEncryptionKey
ForensicArtifactBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
KMSMasterKeyID: !Ref ForensicEncryptionKey
SSEAlgorithm: 'aws:kms'
BucketName: !Sub '${ArtifactBucketName}-${AWS::AccountId}-${AWS::Region}'
VersioningConfiguration:
Status: Enabled
LifecycleConfiguration:
Rules:
-
Id: FinalExpiration
Status: Enabled
ExpirationInDays: !Ref ArtifactBucketExpirationInDays
ForensicAuditLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: !Ref ForensicAuditLogGroupName
ForensicCaptureLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: !Ref ForensicCaptureLogGroupName
ForensicReadinessLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: !Ref ForensicReadinessLogGroupName
EC2ForensicsCollectionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action: 'sts:AssumeRole'
Description: Role to provide access for EC2 to write forensic artifacts
RoleName: !Sub '${EC2ForensicRole}_${AWS::Region}'
EC2ForensicsCollectionPolicy:
Type: 'AWS::IAM::ManagedPolicy'
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: KMSPermissions
Effect: Allow
Action:
- 'kms:Decrypt'
- 'kms:DescribeKey'
- 'kms:GenerateDataKey'
Resource: !GetAtt
- ForensicEncryptionKey
- Arn
- Sid: LogsPermissions
Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:DescribeLogGroups'
- 'logs:DescribeLogStreams'
- 'logs:PutLogEvents'
Resource: '*'
- Sid: S3Permissions
Effect: Allow
Action: 's3:PutObject'
Resource: !Sub '${ForensicArtifactBucket.Arn}/*'
ManagedPolicyName: !Sub 'EC2ForensicsCollectionPolicy_${AWS::Region}'
Roles:
- !Ref EC2ForensicsCollectionRole
EC2ForensicsCollectionInstanceProfile:
Type: 'AWS::IAM::InstanceProfile'
Properties:
InstanceProfileName: !Sub '${EC2ForensicRole}_${AWS::Region}'
Roles:
- !Ref EC2ForensicsCollectionRole
############################################################################
#
# diskFunctions
#
############################################################################
DiskForensicAutomationRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: 'sts:AssumeRole'
Description: >-
Disk Forensic Automation Role to provide access for Lambda to invoke
disk collection functions
RoleName: !Sub 'DiskForensicAutomationRole_${AWS::Region}' # Important that this name is explicit
DiskForensicAutomationPolicy:
Type: 'AWS::IAM::ManagedPolicy'
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: EC2Permissions
Effect: Allow
Action:
- 'ec2:AttachVolume'
- 'ec2:CopySnapshot'
- 'ec2:CreateTags'
- 'ec2:CreateVolume'
- 'ec2:DescribeSnapshots'
- 'ec2:DescribeSubnets'
- 'ec2:RunInstances'
Resource: '*'
- Sid: KMSPermissions
Effect: Allow
Action:
- 'kms:CreateGrant'
- 'kms:Decrypt'
- 'kms:DescribeKey'
- 'kms:Encrypt'
- 'kms:GenerateDataKey*'
- 'kms:ReEncrypt*'
Resource: !GetAtt ForensicEncryptionKey.Arn
- Sid: LogsPermissions
Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:DescribeLogGroups'
- 'logs:DescribeLogStreams'
- 'logs:GetLogEvents'
- 'logs:PutLogEvents'
Resource: '*'
- Sid: IAMPermissions
Effect: Allow
Action:
- 'iam:PassRole'
Resource: !GetAtt EC2ForensicsCollectionRole.Arn
- Sid: S3Permissions
Effect: Allow
Action:
- 's3:PutObject'
Resource: !Sub '${ForensicArtifactBucket.Arn}/*'
- Sid: STSPermissions
Effect: Allow
Action: 'sts:AssumeRole'
Resource: !Sub 'arn:aws:iam::*:role/${MemberAutomationRole}_${AWS::Region}'
ManagedPolicyName: !Sub 'DiskForensicAutomationPolicy_${AWS::Region}'
Roles:
- !Ref DiskForensicAutomationRole
CreateSnapshotLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/CreateSnapshot/
Description: Create Snapshot Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 180
Environment:
Variables:
EVIDENCE_BUCKET: !Sub '${ArtifactBucketName}-${AWS::AccountId}-${AWS::Region}'
LOG_GROUP: !Ref ForensicAuditLogGroupName
ROLE_NAME: !Sub '${MemberAutomationRole}_${AWS::Region}'
CheckSnapshotLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/CheckSnapshot/
Description: Check Snapshot Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 15
Environment:
Variables:
ROLE_NAME: !Sub '${MemberAutomationRole}_${AWS::Region}'
CopySnapshotLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/CopySnapshot/
Description: Copy Snapshot Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 180
Environment:
Variables:
ROLE_NAME: !Sub '${MemberAutomationRole}_${AWS::Region}'
KMS_KEY: !GetAtt ForensicEncryptionKey.Arn
CheckCopySnapshotLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/CheckCopySnapshot/
Description: Check Copy Snapshot Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 15
Environment:
Variables:
ROLE_NAME: !Sub '${MemberAutomationRole}_${AWS::Region}'
ShareSnapshotLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/ShareSnapshot/
Description: Share Snapshot Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 15
Environment:
Variables:
ROLE_NAME: !Sub '${MemberAutomationRole}_${AWS::Region}'
SECURITY_ACCOUNT: !Ref 'AWS::AccountId'
FinalCopySnapshotLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/FinalCopySnapshot/
Description: Final Copy Snapshot Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 15
Environment:
Variables:
KMS_KEY: !GetAtt ForensicEncryptionKey.Arn
FinalCheckSnapshotLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/FinalCheckSnapshot/
Description: Final Check Snapshot Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 15
CreateVolumeLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/CreateVolume/
Description: Create Volume Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 15
Environment:
Variables:
KMS_KEY: !GetAtt ForensicEncryptionKey.Arn
SUPPORTED_AZS: !Sub '["${AWS::Region}${AZ1Letter}","${AWS::Region}${AZ2Letter}"]'
RunInstancesLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/RunInstances/
Description: Run Instances Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 60
Environment:
Variables:
AMI_IDS: !Ref ForensicsAMIs
REGION: !Sub "${AWS::Region}"
INSTANCE_PROFILE_NAME: !Sub '${EC2ForensicRole}_${AWS::Region}'
SECURITY_GROUP: !GetAtt ForensicsCaptureSecurityGroup.GroupId
VPC_ID: !Ref forensicsVPC
INSTANCE_TYPE: !Ref InstanceType
MountVolumeLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/MountVolume/
Description: Mount Volume Function
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 60
Environment:
Variables:
LOG_GROUP: !Ref ForensicAuditLogGroupName
TerminateInstanceLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/TerminateInstance/
Description: Terminate an instance
Role: !GetAtt DiskForensicAutomationRole.Arn
Timeout: 60
Environment:
Variables:
ROLE_NAME: !Sub '${MemberAutomationRole}_${AWS::Region}'
############################################################################
#
# diskStepFunction
#
############################################################################
DiskForensicStepFunction:
Type: AWS::Serverless::StateMachine
Properties:
DefinitionUri: statemachine/disk_forensics.asl.yaml
DefinitionSubstitutions:
CreateSnapshotLambdaArn: !GetAtt CreateSnapshotLambda.Arn
CheckSnapshotLambdaArn: !GetAtt CheckSnapshotLambda.Arn
CopySnapshotLambdaArn: !GetAtt CopySnapshotLambda.Arn
CheckCopySnapshotLambdaArn: !GetAtt CheckCopySnapshotLambda.Arn
ShareSnapshotLambdaArn: !GetAtt ShareSnapshotLambda.Arn
FinalCopySnapshotLambdaArn: !GetAtt FinalCopySnapshotLambda.Arn
FinalCheckSnapshotLambdaArn: !GetAtt FinalCheckSnapshotLambda.Arn
CreateVolumeLambdaArn: !GetAtt CreateVolumeLambda.Arn
RunInstancesLambdaArn: !GetAtt RunInstancesLambda.Arn
MountVolumeLambdaArn: !GetAtt MountVolumeLambda.Arn
TerminateInstanceLambdaArn: !GetAtt TerminateInstanceLambda.Arn
DiskForensicsSNSTopicArn: !Ref DiskForensicsSNSTopic
TerminateRogueAfterInitialSnapshot: !Ref TerminateRogueAfterInitialSnapshot
Policies:
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'xray:PutTraceSegments'
- 'xray:PutTelemetryRecords'
- 'xray:GetSamplingRules'
- 'xray:GetSamplingTargets'
Resource:
- '*'
- Effect: Allow
Action:
- 'logs:CreateLogDelivery'
- 'logs:GetLogDelivery'
- 'logs:UpdateLogDelivery'
- 'logs:DeleteLogDelivery'
- 'logs:ListLogDeliveries'
- 'logs:PutResourcePolicy'
- 'logs:DescribeResourcePolicies'
- 'logs:DescribeLogGroups'
Resource: '*'
- LambdaInvokePolicy:
FunctionName: !Ref CreateSnapshotLambda
- LambdaInvokePolicy:
FunctionName: !Ref CheckSnapshotLambda
- LambdaInvokePolicy:
FunctionName: !Ref CopySnapshotLambda
- LambdaInvokePolicy:
FunctionName: !Ref CheckCopySnapshotLambda
- LambdaInvokePolicy:
FunctionName: !Ref ShareSnapshotLambda
- LambdaInvokePolicy:
FunctionName: !Ref FinalCopySnapshotLambda
- LambdaInvokePolicy:
FunctionName: !Ref FinalCheckSnapshotLambda
- LambdaInvokePolicy:
FunctionName: !Ref CreateVolumeLambda
- LambdaInvokePolicy:
FunctionName: !Ref RunInstancesLambda
- LambdaInvokePolicy:
FunctionName: !Ref MountVolumeLambda
- LambdaInvokePolicy:
FunctionName: !Ref TerminateInstanceLambda
- SNSPublishMessagePolicy:
TopicName: !GetAtt DiskForensicsSNSTopic.TopicName
Logging:
Destinations:
- CloudWatchLogsLogGroup:
LogGroupArn: !GetAtt ForensicStepFunctionLogGroup.Arn
IncludeExecutionData: true
Level: ALL
ForensicStepFunctionLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: !Ref ForensicStepFunctionLogGroupName
DiskForensicsSNSTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: 'Disk Forensics Error Topic'
TopicName: 'DiskForensicsErrorTopic'
KmsMasterKeyId: alias/aws/sns
############################################################################
#
# diskForensicsInvoke
#
############################################################################
DiskForensicsInvoke:
Type: AWS::Serverless::Function
Properties:
Description: Lambda used to Invoke Forensic Step Function
Handler: index.lambda_handler # The "index" module name required for Zip
Events:
GuardDutyTriggerRule:
Type: EventBridgeRule
Properties:
Pattern:
source:
- 'aws.securityhub'
detail-type:
- 'REMOVETHISTOENABLESecurity Hub Findings - Imported'
detail:
findings:
ProductFields:
aws/securityhub/SeverityLabel:
- 'CRITICAL'
- 'HIGH'
- 'MEDIUM'
aws/securityhub/ProductName:
- 'GuardDuty'
Policies:
- Statement:
- Effect: Allow
Action:
- states:StartExecution
Resource:
- !Ref DiskForensicStepFunction
- Sid: LogsPermissions
Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:DescribeLogGroups'
- 'logs:DescribeLogStreams'
- 'logs:GetLogEvents'
- 'logs:PutLogEvents'
Resource: '*'
FunctionName: DiskForensicsInvoke
Timeout: 15
Environment:
Variables:
ForensicSFNARN: !Ref DiskForensicStepFunction
InlineCode: |
# Copyright 2017 Amazon Web Services, Inc. or its affiliates. All Rights Reserved.
# This file is licensed to you under the AWS Customer Agreement (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at http://aws.amazon.com/agreement/ .
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import json
import os
import boto3
import time
sfnArn = os.environ['ForensicSFNARN']
def buildEvent(event):
triggeredEvent = {}
triggeredEvent['AwsAccountId'] = event['AwsAccountId']
triggeredEvent['Types'] = event['Types']
triggeredEvent['FirstObservedAt'] = event['FirstObservedAt']
triggeredEvent['LastObservedAt'] = event['LastObservedAt']
triggeredEvent['CreatedAt'] = event['CreatedAt']
triggeredEvent['UpdatedAt'] = event['UpdatedAt']
triggeredEvent['Severity'] = event['Severity']
triggeredEvent['Title'] = event['Title']
triggeredEvent['Description'] = event['Description']
triggeredEvent['FindingId'] = event['ProductFields']['aws/securityhub/FindingId']
for item in event['Resources']:
if item['Type'] == "AwsEc2Instance":
triggeredEvent['Resource'] = {}
arn = item['Id'].split("/")
triggeredEvent['Resource']['Type'] = item['Type']
triggeredEvent['Resource']['Arn'] = item['Id']
triggeredEvent['Resource']['Id'] = arn[1]
triggeredEvent['Resource']['Partition'] = item['Partition']
triggeredEvent['Resource']['Region'] = item['Region']
triggeredEvent['Resource']['Details'] = item['Details']
if 'Tags' in item:
triggeredEvent['Resource']['Tags'] = item['Tags']
print(triggeredEvent)
invokeStep(triggeredEvent)
def invokeStep(event):
client = boto3.client('stepfunctions')
response = client.start_execution(
stateMachineArn=sfnArn,
name=str(time.time()) + "-" + event['Resource']['Id'],
input=json.dumps(event)
)
print(response)
def lambda_handler(event, context):
for item in event['Resources']:
### Add More filters here to invoke only for certain events such as different finding Types. event['Types']
if item['Type'] == "AwsEc2Instance":
triggeredEvent = buildEvent(event)
break
ExternalPermission:
Type: AWS::Lambda::Permission
Condition: CreateExternalPermissions
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !GetAtt DiskForensicsInvoke.Arn
Principal: !Ref AllowInvokeFromAccountId
#-------------------------------------------------------------------------------
#
# Monitoring. Only the state machines should be monitored as they
# orchestrate the lambda functions which are expected to fail in certain
# circumstances without this generating an incident.
#
# These CloudWatch alarms conform to the naming conventions used by the
# logic defined in the "all-alarms-to-sec-hub" SAM project. This will
# automatically create incidents and tickets in ServiceNow or Jira.
#
#-------------------------------------------------------------------------------
AlarmDiskForensicStepFunction:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: INFRA-DiskForensicStepFunction-SM-Failure-HIGH
AlarmDescription: The DiskForensicStepFunction state machine failed.
ActionsEnabled: true
OKActions: []
AlarmActions: []
InsufficientDataActions: []
MetricName: ExecutionsFailed
Namespace: AWS/States
Statistic: Sum
Dimensions:
- Name: StateMachineArn
Value: !Ref DiskForensicStepFunction
Period: 60
EvaluationPeriods: 1
DatapointsToAlarm: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
TreatMissingData: notBreaching
############################################################################
#
# Outputs
#
############################################################################
Outputs:
DiskForensicsInvokeARN:
Description: The ARN of the Disk Forensics invocation Lambda
Value: !GetAtt DiskForensicsInvoke.Arn
Export:
Name: DiskForensicsInvokeARN