This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
/
template.yaml
2784 lines (2641 loc) · 93.8 KB
/
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
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
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >-
This creates the necessary serverless components for the Life Events Platform.
Globals:
Function:
Timeout: 30
Environment:
Variables:
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
POWERTOOLS_TRACER_CAPTURE_ERROR: false
POWERTOOLS_TRACER_CAPTURE_RESPONSE: falsehttps://di-team-manual.london.cloudapps.digital/development-standards-processes/github-policies/#signed-commits
AWS_LAMBDA_EXEC_WRAPPER: /opt/dynatrace
DT_CONNECTION_AUTH_TOKEN: !Sub
- '{{resolve:secretsmanager:${SecretArn}:SecretString:DT_CONNECTION_AUTH_TOKEN}}'
- SecretArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, dynatraceSecretArn ]
DT_CONNECTION_BASE_URL: !Sub
- '{{resolve:secretsmanager:${SecretArn}:SecretString:DT_CONNECTION_BASE_URL}}'
- SecretArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, dynatraceSecretArn ]
DT_CLUSTER_ID: !Sub
- '{{resolve:secretsmanager:${SecretArn}:SecretString:DT_CLUSTER_ID}}'
- SecretArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, dynatraceSecretArn ]
DT_LOG_COLLECTION_AUTH_TOKEN: !Sub
- '{{resolve:secretsmanager:${SecretArn}:SecretString:DT_LOG_COLLECTION_AUTH_TOKEN}}'
- SecretArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, dynatraceSecretArn ]
DT_TENANT: !Sub
- '{{resolve:secretsmanager:${SecretArn}:SecretString:DT_TENANT}}'
- SecretArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, dynatraceSecretArn ]
DT_OPEN_TELEMETRY_ENABLE_INTEGRATION: "true"
POWERTOOLS_METRICS_NAMESPACE: "di-data-lep"
AWS_XRAY_CONTEXT_MISSING: "IGNORE_ERROR"
Runtime: java17
Architectures:
- x86_64
MemorySize: 2048
KmsKeyArn: !GetAtt MainKmsKey.Arn
Tracing: Active
SnapStart:
ApplyOn: PublishedVersions
VpcConfig:
SecurityGroupIds:
- !Ref LambdaSecurityGroup
CodeSigningConfigArn: !If
- UseCodeSigning
- !Ref CodeSigningConfigArn
- !Ref AWS::NoValue
PermissionsBoundary: !If
- UsePermissionsBoundary
- !Ref PermissionsBoundary
- !Ref AWS::NoValue
Layers:
- !Sub
- '{{resolve:secretsmanager:${SecretArn}:SecretString:JAVA_LAYER}}'
- SecretArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, dynatraceSecretArn ]
Parameters:
Environment:
Type: String
Description: The name of the environment to deploy to
VpcStackName:
Type: String
Description: The name of the stack used to create the VPC
Developer:
Type: String
Description: The name of the developer running the stack in dev
Default: ""
CodeSigningConfigArn:
Type: String
Description: The ARN of the Code Signing Config to use, provided by the deployment pipeline
Default: none
PermissionsBoundary:
Type: String
Description: The ARN of the permissions boundary to apply when creating IAM roles
Default: none
Conditions:
IsDev:
!Equals [ dev, !Ref Environment ]
IsHmpoDev:
!And [ !Equals [ hmpo, !Ref Developer ], Condition: IsDev ]
IsIntegration:
!Equals [ integration, !Ref Environment ]
IsNotProduction:
!Not [ !Equals [ production, !Ref Environment ] ]
UseCodeSigning:
!Not [ !Equals [ none, !Ref CodeSigningConfigArn ] ]
UsePermissionsBoundary:
!Not [ !Equals [ none, !Ref PermissionsBoundary ] ]
Mappings:
EnvironmentConfiguration:
dev:
domainName: life-events.dev.account.gov.uk
txmaAccountArn: arn:aws:iam::248098332657:root
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
build:
domainName: life-events.build.account.gov.uk
txmaAccountArn: arn:aws:iam::750703655225:root
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
staging:
domainName: life-events.staging.account.gov.uk
txmaAccountArn: arn:aws:iam::178023842775:root
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
integration:
domainName: life-events.integration.account.gov.uk
txmaAccountArn: arn:aws:iam::729485541398:root
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
production:
domainName: life-events.account.gov.uk
txmaAccountArn: arn:aws:iam::451773080033:root
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceProductionVariables
Resources:
MainKmsKey:
Type: AWS::KMS::Key
Properties:
Description: Key used to encrypt the Life Events Platform
EnableKeyRotation: true
KeyPolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: kms:*
Resource: "*"
- Effect: Allow
Principal:
Service: !Sub logs.${AWS::Region}.amazonaws.com
Action:
- kms:Encrypt*
- kms:Decrypt*
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:Describe*
Resource: "*"
Condition:
ArnLike:
kms:EncryptionContext:aws:logs:arn: !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*
- Effect: Allow
Principal:
Service: sns.amazonaws.com
Action:
- kms:Decrypt
- kms:GenerateDataKey*
Resource: "*"
LogsBucket:
Type: AWS::S3::Bucket
Properties:
# checkov:skip=CKV_AWS_18: The logs bucket doesn't need logging.
AccessControl: Private
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: aws:kms
KMSMasterKeyID: !GetAtt MainKmsKey.Arn
BucketName: !Sub ${Environment}${Developer}-life-events-logs-bucket
LifecycleConfiguration:
Rules:
- Id: "logs-bucket-lifecycle-rule"
Status: Enabled
Transitions:
- TransitionInDays: 180
StorageClass: INTELLIGENT_TIERING
NotificationConfiguration:
EventBridgeConfiguration:
EventBridgeEnabled: true
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
Tags:
- Key: PersonalIdentifyingInformation
Value: true
LogsBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref LogsBucket
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: AllowSSLRequestsOnly
Action: s3:*
Effect: Deny
Principal: "*"
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref LogsBucket
- "/*"
Condition:
Bool:
aws:SecureTransport: false
- Sid: EnforceTLSv12orHigher
Action: s3:*
Effect: Deny
Principal: "*"
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref LogsBucket
- "/*"
Condition:
NumericLessThan:
s3:TlsVersion: 1.2
- Action:
- "s3:PutObject"
Effect: Allow
Principal:
Service: logging.s3.amazonaws.com
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref LogsBucket
- "/*"
Condition:
StringEquals:
'aws:SourceAccount': !Sub "${AWS::AccountId}"
LambdaSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Lambda Security Group permissions ruleset
VpcId:
Fn::ImportValue: !Sub ${VpcStackName}-VpcId
SecurityGroupEgress:
- DestinationSecurityGroupId:
Fn::ImportValue: !Sub ${VpcStackName}-AWSServicesEndpointSecurityGroupId
Description: Allow outbound traffic to vpc endpoints
IpProtocol: tcp
FromPort: 443
ToPort: 443
- CidrIp: 0.0.0.0/0
Description: Allow outbound HTTPS traffic to Internet - The Network Firewall rules will prevent access to anything other than the allowed rules of our VPC
FromPort: 443
IpProtocol: tcp
ToPort: 443
- CidrIp: 0.0.0.0/0
Description: Allow outbound SSH traffic to Internet - The Network Firewall rules will prevent access to anything other than the allowed rules of our VPC
FromPort: 22
IpProtocol: tcp
ToPort: 22
XRayPolicy:
Type: AWS::XRay::ResourcePolicy
Properties:
BypassPolicyLockoutCheck: false
PolicyName: !Sub "AllowSNSXrayTracing${Developer}"
PolicyDocument: !Sub "{
\"Version\": \"2012-10-17\",
\"Statement\": [
{
\"Sid\": \"SNSAccess\",
\"Effect\": \"Allow\",
\"Principal\": {
\"Service\": \"sns.amazonaws.com\"
},
\"Action\": [
\"xray:PutTraceSegments\",
\"xray:GetSamplingRules\",
\"xray:GetSamplingTargets\"
],
\"Resource\": \"*\",
\"Condition\": {
\"StringEquals\": {
\"aws:SourceAccount\": \"${AWS::AccountId}\"
},
\"StringLike\": {
\"aws:SourceArn\": \"${DeathDistributionTopic.TopicArn}\"
}
}
}
]
}"
UserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: !Sub UserPool-${Environment}${Developer}
UserPoolDomain:
Type: AWS::Cognito::UserPoolDomain
Properties:
UserPoolId: !Ref UserPool
Domain: !Sub ${Environment}${Developer}-life-events
AdminUserPoolResourceServer:
Type: AWS::Cognito::UserPoolResourceServer
Properties:
Identifier: Admin
Name: AdminUserPoolResourceServer
Scopes:
- ScopeDescription: Can manage at an admin level
ScopeName: Manage
UserPoolId: !Ref UserPool
AdminClient:
Type: AWS::Cognito::UserPoolClient
DependsOn:
- AdminUserPoolResourceServer
Properties:
AccessTokenValidity: 60
AllowedOAuthFlows:
- client_credentials
AllowedOAuthFlowsUserPoolClient: true
AllowedOAuthScopes:
- Admin/Manage
ClientName: AdminClient
EnableTokenRevocation: false
ExplicitAuthFlows:
- ALLOW_USER_PASSWORD_AUTH
- ALLOW_REFRESH_TOKEN_AUTH
GenerateSecret: true
PreventUserExistenceErrors: ENABLED
UserPoolId: !Ref UserPool
TokenValidityUnits:
AccessToken: minutes
UserPoolResourceServer:
Type: AWS::Cognito::UserPoolResourceServer
Properties:
Identifier: EventType
Name: UserPoolResourceServer
Scopes:
- ScopeDescription: Can publish death notification events
ScopeName: DeathNotification
UserPoolId: !Ref UserPool
DwpIntegrationManagedPolicy:
Type: AWS::IAM::ManagedPolicy
Condition: IsIntegration
Properties:
ManagedPolicyName: dwp-integration-managed-policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: DwpIntegrationSqsAccess
Effect: Allow
Resource:
- !GetAtt DwpDevDeathDeliveryQueue.Arn
- !GetAtt DwpTestDeathDeliveryQueue.Arn
- !GetAtt DwpStageDeathDeliveryQueue.Arn
- !GetAtt DwpOldFormatConvertedDeathQueue.Arn
Action:
- SQS:GetQueueUrl
- SQS:GetQueueAttributes
- SQS:ChangeMessageVisibility
- SQS:ReceiveMessage
- SQS:DeleteMessage
- Sid: DwpIntegrationKmsKeyAccess
Effect: Allow
Action:
- kms:GenerateDataKey
- kms:Decrypt
Resource:
- !GetAtt DwpDevDeathKmsKey.Arn
- !GetAtt DwpTestDeathKmsKey.Arn
- !GetAtt DwpStageDeathKmsKey.Arn
- !GetAtt DwpOldFormatDeathKmsKey.Arn
HmpoDevManagedPolicy:
Type: AWS::IAM::ManagedPolicy
Condition: IsHmpoDev
Properties:
ManagedPolicyName: hmpo-dev-managed-policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: HmpoDevSqsAccess
Effect: Allow
Resource:
- !GetAtt DwpDeathDeliveryQueue.Arn
Action:
- SQS:GetQueueUrl
- SQS:GetQueueAttributes
- SQS:ChangeMessageVisibility
- SQS:ReceiveMessage
- SQS:DeleteMessage
- Sid: HmpoDevKmsKeyAccess
Effect: Allow
Action:
- kms:GenerateDataKey
- kms:Decrypt
Resource:
- !GetAtt DwpDeathKmsKey.Arn
DeveloperHostedZone:
Type: AWS::Route53::HostedZone
Condition: IsDev
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
Name: !Join [ ".", [ !Ref Developer, !FindInMap [ EnvironmentConfiguration, !Ref Environment, domainName ] ] ]
DeveloperRecordSet:
Type: AWS::Route53::RecordSet
Condition: IsDev
Properties:
Name: !Join [ ".", [ !Ref Developer, !FindInMap [ EnvironmentConfiguration, !Ref Environment, domainName ] ] ]
Type: NS
HostedZoneId: !ImportValue HostedZoneId
ResourceRecords: !GetAtt DeveloperHostedZone.NameServers
TTL: 60
DevCertificate:
Type: AWS::CertificateManager::Certificate
Condition: IsDev
Properties:
DomainName: !Join [ ".", [ !Ref Developer, !FindInMap [ EnvironmentConfiguration, !Ref Environment, domainName ] ] ]
DomainValidationOptions:
- DomainName: !Join [ ".", [ !Ref Developer, !FindInMap [ EnvironmentConfiguration, !Ref Environment, domainName ] ] ]
HostedZoneId: !Ref DeveloperHostedZone
ValidationMethod: DNS
CertificateTransparencyLoggingPreference: ENABLED
AuditKmsKey:
Type: AWS::KMS::Key
Properties:
Description: Symmetric key used to encrypt TxMA audit messages at rest in SQS
EnableKeyRotation: true
KeySpec: SYMMETRIC_DEFAULT
KeyPolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: kms:*
Resource: "*"
- Sid: AllowTxMADecryption
Effect: Allow
Principal:
AWS: !FindInMap [ EnvironmentConfiguration, !Ref Environment, txmaAccountArn ]
Action:
- kms:Decrypt*
Resource: "*"
AuditKmsKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub alias/${Environment}${Developer}/AuditEncryptionKey
TargetKeyId: !Ref AuditKmsKey
AuditQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub ${Environment}${Developer}-audit
MessageRetentionPeriod: 1209600 # 14 days
KmsMasterKeyId: !Ref AuditKmsKeyAlias
RedriveAllowPolicy:
redrivePermission: denyAll
RedrivePolicy:
deadLetterTargetArn: !GetAtt AuditDeadLetterQueue.Arn
maxReceiveCount: 10
Tags:
- Key: PersonalIdentifyingInformation
Value: true
AuditQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref AuditQueue
PolicyDocument:
Statement:
- Sid: AllowReadByTxMAAccount
Effect: Allow
Principal:
AWS: !FindInMap [ EnvironmentConfiguration, !Ref Environment, txmaAccountArn ]
Action:
- sqs:ChangeMessageVisibility
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:GetQueueAttributes
Resource: !GetAtt AuditQueue.Arn
AuditDeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub ${Environment}${Developer}-audit-dlq
MessageRetentionPeriod: 1209600 # 14 days
KmsMasterKeyId: !Ref AuditKmsKeyAlias
Tags:
- Key: PersonalIdentifyingInformation
Value: true
AlertTopic:
Type: AWS::SNS::Topic
Properties:
# checkov:skip=CKV_AWS_26: We do not need to encrypt this data on the SNS topic as alerts aren't sensitive
DisplayName: !Sub ${Environment}${Developer}-alert-topic
TopicName: !Sub ${Environment}${Developer}-alert-topic
Tags:
- Key: CheckovRulesToSkip
Value: CKV_AWS_26
AlertTopicSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: di-life-events-platform@digital.cabinet-office.gov.uk
Protocol: email
TopicArn: !Ref AlertTopic
AuditDeadLetterQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-audit-dead-letter-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt AuditDeadLetterQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
DeathValidationDeadLetterQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-death-validation-dead-letter-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt DeathValidationDlq.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
DeathEnrichmentDeadLetterQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-death-enrichment-dead-letter-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt DeathEnrichmentDlq.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
DwpDeathDistributionDeadLetterQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-dwp-death-distribution-dead-letter-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt DwpDeathDistributionDlq.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
DwpDeathMinimisationDeadLetterQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-dwp-death-minimisation-dead-letter-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt DwpDeathMinimisationDlq.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
DwpDeathDeliveryDeadLetterQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-dwp-death-delivery-dead-letter-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt DwpDeathDeliveryDlq.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
OneMinuteOnDeathEnrichmentQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-one-hour-on-death-enrichment-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateAgeOfOldestMessage
Dimensions:
- Name: QueueName
Value: !GetAtt DeathEnrichmentQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 60
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
OneMinuteOnDeathMinimisationQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-one-hour-on-death-minimisation-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateAgeOfOldestMessage
Dimensions:
- Name: QueueName
Value: !GetAtt DwpDeathMinimisationQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 60
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
OneMinuteOnDwpDeathDeliveryQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-one-hour-on-dwp-death-delivery-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateAgeOfOldestMessage
Dimensions:
- Name: QueueName
Value: !GetAtt DwpDeathDeliveryQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 60
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
OneDayOnDwpDeathDeliveryQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-one-day-on-dwp-death-delivery-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateAgeOfOldestMessage
Dimensions:
- Name: DwpDeathDeliveryQueue
Value: !GetAtt DwpDeathDeliveryQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 86400
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
ThreeDaysOnDwpDeathDeliveryQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}${Developer}-three-days-on-dwp-death-delivery-queue-alarm
Namespace: AWS/SQS
MetricName: ApproximateAgeOfOldestMessage
Dimensions:
- Name: DwpDeathDeliveryQueue
Value: !GetAtt DwpDeathDeliveryQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 259200
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlertTopic
ApiGateway:
Type: AWS::Serverless::Api
Properties:
# checkov:skip=CKV_AWS_120: We do not need gateway caching on a post only gateway.
Auth:
Authorizers:
AdminCognitoAuthoriser:
AuthorizationScopes:
- Admin/Manage
UserPoolArn: !GetAtt UserPool.Arn
Identity:
Header: Authorization
DeathCognitoAuthoriser:
AuthorizationScopes:
- EventType/DeathNotification
UserPoolArn: !GetAtt UserPool.Arn
Identity:
Header: Authorization
DefaultAuthorizer: AdminCognitoAuthoriser
StageName: Prod
TracingEnabled: true
Domain:
DomainName: !If
- IsDev
- !Join [ ".", [ !Ref Developer, !FindInMap [ EnvironmentConfiguration, !Ref Environment, domainName ] ] ]
- !FindInMap [ EnvironmentConfiguration, !Ref Environment, domainName ]
CertificateArn: !If
- IsDev
- !Ref DevCertificate
- !ImportValue CertificateArn
EndpointConfiguration: REGIONAL
Route53:
HostedZoneId: !If
- IsDev
- !Ref DeveloperHostedZone
- Fn::ImportValue: HostedZoneId
EvaluateTargetHealth: true
IpV6: true
AccessLogSetting:
DestinationArn: !GetAtt ApiGatewayLogGroup.Arn
Format: >-
{
"requestId":"$context.requestId",
"ip":"$context.identity.sourceIp",
"requestTime":"$context.requestTime",
"httpMethod":"$context.httpMethod",
"path":"$context.path",
"routeKey":"$context.routeKey",
"status":"$context.status",
"protocol":"$context.protocol",
"responseLatency":"$context.responseLatency",
"responseLength":"$context.responseLength"
}
Tags:
CheckovRulesToSkip: CKV_AWS_120
ApiGatewayLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/apigateway/${AWS::StackName}-access-logs
RetentionInDays: 14
KmsKeyId: !GetAtt MainKmsKey.Arn
DeathValidationDlq:
Type: AWS::SQS::Queue
Properties:
MessageRetentionPeriod: 1209600 # 14 days
QueueName: !Sub ${Environment}${Developer}-death-validation-dlq
KmsMasterKeyId: !Ref MainKmsKey
Tags:
- Key: PersonalIdentifyingInformation
Value: true
DeathEnrichmentQueue:
Type: AWS::SQS::Queue
Properties:
MessageRetentionPeriod: 604800 # 7 days
QueueName: !Sub ${Environment}${Developer}-death-enrichment
KmsMasterKeyId: !Ref MainKmsKey
RedrivePolicy:
deadLetterTargetArn: !GetAtt DeathEnrichmentDlq.Arn
maxReceiveCount: 5
Tags:
- Key: PersonalIdentifyingInformation
Value: true
DeathEnrichmentDlq:
Type: AWS::SQS::Queue
Properties:
MessageRetentionPeriod: 1209600 # 14 days
QueueName: !Sub ${Environment}${Developer}-death-enrichment-dlq
KmsMasterKeyId: !Ref MainKmsKey
Tags:
- Key: PersonalIdentifyingInformation
Value: true
DeathDistributionTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Sub ${Environment}${Developer}-death-distribution-topic
KmsMasterKeyId: !Ref MainKmsKey
TracingConfig: Active
Tags:
- Key: PersonalIdentifyingInformation
Value: true
DeathValidationFunction:
Type: AWS::Serverless::Function
DependsOn:
- DeathValidationFunctionLogGroup
Properties:
# checkov:skip=CKV_AWS_115: We do not have enough data to allocate the concurrent execution allowance per function.
# checkov:skip=CKV_AWS_117: VPC settings are set globally.
# checkov:skip=CKV_AWS_173: Encryption settings are set globally.
FunctionName: !Sub ${Environment}${Developer}-death-validation
CodeUri: lambdas/death-validation
Handler: uk.gov.di.data.lep.DeathValidation::handleRequest
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: death-validation
TARGET_QUEUE: !GetAtt DeathEnrichmentQueue.QueueUrl
AUDIT_QUEUE: !GetAtt AuditQueue.QueueUrl
AutoPublishAlias: latest
AutoPublishAliasAllProperties: true
Events:
DeathApiEvent:
Type: Api
Properties:
Auth:
Authorizer: DeathCognitoAuthoriser
RestApiId: !Ref ApiGateway
Method: POST
Path: /events/deathNotification/
DeadLetterQueue:
Type: SQS
TargetArn: !GetAtt DeathValidationDlq.Arn
Policies:
- Statement:
- Sid: MainKmsKeyAccess
Effect: Allow
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource:
- !GetAtt MainKmsKey.Arn
- Sid: AuditKmsKeyAccess
Effect: Allow
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource:
- !GetAtt AuditKmsKey.Arn
- SQSSendMessagePolicy:
QueueName: !GetAtt DeathEnrichmentQueue.QueueName
- SQSSendMessagePolicy:
QueueName: !GetAtt AuditQueue.QueueName
VpcConfig:
SubnetIds:
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdA
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdB
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdC
Tags:
CheckovRulesToSkip: CKV_AWS_115.CKV_AWS_117.CKV_AWS_173
DeathValidationFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 14
LogGroupName: !Sub /aws/lambda/${Environment}${Developer}-death-validation
KmsKeyId: !GetAtt MainKmsKey.Arn
DeathEnrichmentFunction:
Type: AWS::Serverless::Function
DependsOn:
- DeathEnrichmentFunctionLogGroup
Properties:
# checkov:skip=CKV_AWS_115: We do not have enough data to allocate the concurrent execution allowance per function.
# checkov:skip=CKV_AWS_117: VPC settings are set globally.
# checkov:skip=CKV_AWS_173: Encryption settings are set globally.
FunctionName: !Sub ${Environment}${Developer}-death-enrichment
CodeUri: lambdas/death-enrichment
Handler: uk.gov.di.data.lep.DeathEnrichment::handleRequest
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: death-enrichment
TARGET_TOPIC: !GetAtt DeathDistributionTopic.TopicArn
AUDIT_QUEUE: !GetAtt AuditQueue.QueueUrl
AutoPublishAlias: latest
AutoPublishAliasAllProperties: true
Events:
DeathValidatedEvent:
Type: SQS
Properties:
Queue: !GetAtt DeathEnrichmentQueue.Arn
BatchSize: 1
DeadLetterQueue:
Type: SQS
TargetArn: !GetAtt DeathEnrichmentDlq.Arn
Policies:
- Statement:
- Sid: MainKmsKeyAccess
Effect: Allow
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource:
- !GetAtt MainKmsKey.Arn
- Sid: AuditKmsKeyAccess
Effect: Allow
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource:
- !GetAtt AuditKmsKey.Arn
- SNSPublishMessagePolicy:
TopicName: !GetAtt DeathDistributionTopic.TopicName
- SQSSendMessagePolicy:
QueueName: !GetAtt AuditQueue.QueueName
VpcConfig:
SubnetIds:
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdA
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdB
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdC
Tags:
CheckovRulesToSkip: CKV_AWS_115.CKV_AWS_117.CKV_AWS_173
DeathEnrichmentFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 14
LogGroupName: !Sub /aws/lambda/${Environment}${Developer}-death-enrichment
KmsKeyId: !GetAtt MainKmsKey.Arn
Tags:
- Key: PersonalIdentifyingInformation
Value: true
DwpDeathKmsKey:
Type: AWS::KMS::Key
Properties:
Description: Key used to encrypt the Death notification delivery queue for DWP
EnableKeyRotation: true
KeyPolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: kms:*
Resource: "*"
- Effect: Allow
Principal:
Service: !Sub logs.${AWS::Region}.amazonaws.com
Action:
- kms:Encrypt*
- kms:Decrypt*
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:Describe*
Resource: "*"
Condition:
ArnLike:
kms:EncryptionContext:aws:logs:arn: !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*
DwpDeathKmsKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub alias/${Environment}${Developer}/DwpDeathKmsKey
TargetKeyId: !Ref DwpDeathKmsKey
DwpDeathSnsToSqsPolicy:
Type: AWS::SQS::QueuePolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: Allow SNS publish to SQS
Effect: Allow
Principal:
AWS: "*"
Resource: "*"
Action: SQS:SendMessage
Condition:
ArnEquals:
aws:SourceArn: !Ref DeathDistributionTopic
Queues:
- !Ref DwpDeathMinimisationQueue
- !Ref DwpDeathDistributionDlq
DwpDeathDistributionDlq:
Type: AWS::SQS::Queue
Properties:
MessageRetentionPeriod: 1209600 # 14 days