/
template.yaml
2542 lines (2439 loc) · 110 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
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
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
LoggingSubscriptionEndpointArn:
Type: String
Description: The ARN of the subscription endpoint to send logs to splunk
Default: "arn:aws:logs:eu-west-2:885513274347:destination:csls_cw_logs_destination_prodpython-2"
Conditions:
UsePermissionsBoundary:
!Not [ !Equals [ none, !Ref PermissionsBoundary ] ]
UseCodeSigning:
!Not [ !Equals [ none, !Ref CodeSigningConfigArn ] ]
IsNotDevEnvironment:
!Not [ !Equals [!Ref Environment, 'dev'] ]
IsBuild:
!Equals [ build, !Ref Environment ]
AisAbortOnError:
!Not [ !Or [ !Equals [ integration, !Ref Environment ], !Equals [ production, !Ref Environment ] ] ]
IdentityEnabled:
!Or [ !Equals [ staging, !Ref Environment ], !Equals [ integration, !Ref Environment ], !Equals [ production, !Ref Environment ] ]
SendStorageToken:
!Not [ !Or [ !Equals [ integration, !Ref Environment ], !Equals [ production, !Ref Environment ] ] ]
Mappings:
EnvironmentConfiguration:
dev:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
authApiId: "dfwubyergf"
authExternalApiId: "48oqh70cm7"
authAccountId: "761723964695"
authEnvironment: sandpit
serviceDomain: sandpit.account.gov.uk
idTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/87bbefac-6fac-4450-8ed6-9ad75c36fdf1
idTokenKeyRsaArn: arn:aws:kms:eu-west-2:761723964695:key/170fc24d-b278-49b0-a860-4fa1f3fa7a48
storageTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/8447683f-8800-4920-b4fe-1f410bf52ce0
ipvTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/a12c7616-57d4-4d9b-b98a-d0df5ee583d7
orchToAuthKeyArn: arn:aws:kms:eu-west-2:761723964695:key/f2b0090b-56aa-4ff1-80fd-e8f8334199a7
userInfoEncryptionKeyArn: arn:aws:kms:eu-west-2:761723964695:key/8bc4e01c-466b-4663-9c60-c29d5e9f2fcf
backchannelLogoutQueueArn: arn:aws:sqs:eu-west-2:761723964695:sandpit-back-channel-logout-queue
docAppBackendUri: https://dcmaw-cri.build.stubs.account.gov.uk
docAppCriDataV2Endpoint: credentials/issue
docAppAud: https://dcmaw-cri.build.stubs.account.gov.uk
docAppAuthorisationUrl: https://dcmaw-cri.build.stubs.account.gov.uk/authorize
docAppClientId: orch-dev
docAppCredentialTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/d2806c70-0832-46f3-9612-75cc9e745186
docAppEncryptionKeyId: KUqkB4-J06g0jznBi1uAdrBZNumQ41dgXGjXNVgmuUs
docAppSigningKeyArn: arn:aws:kms:eu-west-2:761723964695:key/885ed2d5-21a9-4e26-bb87-24ecbb4b1875
clientRegistryTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/daf80bee-5f09-496f-ba91-c1846de193c9
userProfileTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/79b55133-ed01-45d8-94cd-99be01711e2c
txmaEventEncryptionKeyArn: arn:aws:kms:eu-west-2:816047645251:key/d74787b0-8d11-4dd9-8691-7c0e26856225
orchToAuthTokenSigningKeyAlias: arn:aws:kms:eu-west-2:761723964695:key/f2b0090b-56aa-4ff1-80fd-e8f8334199a7
identityCredentialsTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/51014e2f-859d-436e-ad58-feff9d6cf87b
ipvTokenAuthKeyArn: arn:aws:kms:eu-west-2:761723964695:key/a12c7616-57d4-4d9b-b98a-d0df5ee583d7
spotRequestQueueKmsArn: arn:aws:kms:eu-west-2:761723964695:key/65c56d6b-b341-4be8-aff6-224a2717379a
build:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
authApiId: "6of9f4amvg"
authExternalApiId: "fag06zqnve"
authAccountId: "761723964695"
authEnvironment: build
serviceDomain: build.account.gov.uk
idTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/ca2e4723-7ae8-478d-8fa2-baad3f71f506
idTokenKeyRsaArn: arn:aws:kms:eu-west-2:761723964695:key/0189356a-b80f-4f12-9f31-60f5b34a574f
storageTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/5fcebbac-6a3a-4948-9700-e061ef3d308e
ipvTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/227f9cdd-3de3-4519-ab01-45302a10de95
orchToAuthKeyArn: arn:aws:kms:eu-west-2:761723964695:key/1800ecc2-e04d-4cf5-9b4e-72eafa0c71f6
userInfoEncryptionKeyArn: arn:aws:kms:eu-west-2:761723964695:key/5fdfad8b-ca31-4afc-a948-59fd498c0f3c
backchannelLogoutQueueArn: arn:aws:sqs:eu-west-2:761723964695:build-back-channel-logout-queue
docAppBackendUri: https://dcmaw-cri.build.stubs.account.gov.uk
docAppCriDataV2Endpoint: credentials/issue
docAppAud: https://dcmaw-cri.build.stubs.account.gov.uk
docAppAuthorisationUrl: https://dcmaw-cri.build.stubs.account.gov.uk/authorize
docAppClientId: orch-build
docAppCredentialTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/f2603fe5-7d09-4279-a42d-e2363e11efb5
docAppEncryptionKeyId: KUqkB4-J06g0jznBi1uAdrBZNumQ41dgXGjXNVgmuUs
docAppSigningKeyArn: arn:aws:kms:eu-west-2:761723964695:key/0096ee31-26aa-4c92-bea4-9dd9fa73dcf6
clientRegistryTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/147435a7-f01d-4ed3-9485-ebe7f72808dd
userProfileTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/12f40ae0-84a0-4840-a497-129366eef354
txmaEventEncryptionKeyArn: arn:aws:kms:eu-west-2:767397776536:key/4d851d1e-acd1-4c73-a754-617ffd380b3d
orchToAuthTokenSigningKeyAlias: arn:aws:kms:eu-west-2:761723964695:key/1800ecc2-e04d-4cf5-9b4e-72eafa0c71f6
identityCredentialsTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/b1bc6357-0578-45cc-a192-50e609094b4e
ipvTokenAuthKeyArn: arn:aws:kms:eu-west-2:761723964695:key/227f9cdd-3de3-4519-ab01-45302a10de95
spotRequestQueueKmsArn: arn:aws:kms:eu-west-2:761723964695:key/fd8afa13-ccee-4199-9a01-d85483f3431d
staging:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
authApiId: "1rvwudxmbk"
authExternalApiId: "fag06zqnve"
authAccountId: "758531536632"
authEnvironment: staging
serviceDomain: staging.account.gov.uk
idTokenKeyArn: arn:aws:kms:eu-west-2:758531536632:key/11af3935-0304-4813-bc16-302ab942c75a
idTokenKeyRsaArn: arn:aws:kms:eu-west-2:758531536632:key/1d506b73-c506-4cec-bc46-db0ac1a54149
storageTokenKeyArn: arn:aws:kms:eu-west-2:758531536632:key/01d22c46-bccf-4a2f-bd3b-149fe03f5321
ipvTokenKeyArn: arn:aws:kms:eu-west-2:758531536632:key/91836141-8c92-43ac-99a8-a586c73b6683
orchToAuthKeyArn: arn:aws:kms:eu-west-2:758531536632:key/7a18b3e2-b98c-431e-8955-736837ee24cf
userInfoEncryptionKeyArn: arn:aws:kms:eu-west-2:758531536632:key/3d990d7b-0042-4115-8263-e6b472d84cc2
backchannelLogoutQueueArn: arn:aws:sqs:eu-west-2:758531536632:staging-back-channel-logout-queue
docAppBackendUri: https://api-backend-api.review-b.staging.account.gov.uk
docAppCriDataV2Endpoint: userinfo/v2
docAppAud: https://www.review-b.staging.account.gov.uk
docAppAuthorisationUrl: https://www.review-b.staging.account.gov.uk/dca/oauth2/authorize
docAppClientId: authOrchestratorDocApp
docAppCredentialTableKeyArn: arn:aws:kms:eu-west-2:758531536632:key/63ce28d6-5482-4886-933d-33cd27f469d3
docAppEncryptionKeyId: ca6d5930-77a6-41a4-8192-125df996c084
docAppSigningKeyArn: arn:aws:kms:eu-west-2:758531536632:key/00051d8b-de72-4952-baab-3be6460ad844
clientRegistryTableKeyArn: arn:aws:kms:eu-west-2:758531536632:key/32415ead-d88f-4724-aedf-5fe3ce8ed48e
userProfileTableKeyArn: arn:aws:kms:eu-west-2:758531536632:key/a152899b-1c48-4053-b883-74855739fc16
txmaEventEncryptionKeyArn: arn:aws:kms:eu-west-2:590183975515:key/c653db36-52fa-475c-8866-e167e3e85761
orchToAuthTokenSigningKeyAlias: arn:aws:kms:eu-west-2:758531536632:key/7a18b3e2-b98c-431e-8955-736837ee24cf
identityCredentialsTableKeyArn: arn:aws:kms:eu-west-2:758531536632:key/d028f444-33fa-47b1-96ac-dcc830e5e37e
ipvTokenAuthKeyArn: arn:aws:kms:eu-west-2:758531536632:key/91836141-8c92-43ac-99a8-a586c73b6683
spotRequestQueueKmsArn: arn:aws:kms:eu-west-2:758531536632:key/3afafd1f-59f2-4ceb-806c-f67c0c120968
integration:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
authApiId: "k2skqhxed6"
authExternalApiId: "fag06zqnve"
authAccountId: "761723964695"
authEnvironment: integration
serviceDomain: integration.account.gov.uk
idTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/44d26c18-f460-4d6f-b94c-3f356540a055
idTokenKeyRsaArn: arn:aws:kms:eu-west-2:761723964695:key/6eadd5bf-8a7f-4062-88c4-7774f070df02
storageTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/6dccb5b3-2754-4c66-ba66-c11f861ad55f
ipvTokenKeyArn: arn:aws:kms:eu-west-2:761723964695:key/42a8b69b-9488-44d2-94b8-144b4ff3b35c
orchToAuthKeyArn: arn:aws:kms:eu-west-2:761723964695:key/c92ae9b2-2e2e-4476-a7c9-b52010440bc1
userInfoEncryptionKeyArn: arn:aws:kms:eu-west-2:761723964695:key/e34095ae-a65b-4609-99b3-9c1f407eff73
backchannelLogoutQueueArn: arn:aws:sqs:eu-west-2:761723964695:integration-back-channel-logout-queue
docAppBackendUri: https://api-backend-api.review-b.integration.account.gov.uk
docAppCriDataV2Endpoint: userinfo/v2
docAppAud: https://www.review-b.integration.account.gov.uk
docAppAuthorisationUrl: https://www.review-b.integration.account.gov.uk/dca/oauth2/authorize
docAppClientId: authOrchestratorDocApp
docAppCredentialTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/37aea309-c4a2-4ac7-8361-c1789f54df77
docAppEncryptionKeyId: 0948190d-384c-498d-81e2-a20dd30f147c
docAppSigningKeyArn: arn:aws:kms:eu-west-2:761723964695:key/031ece8b-a59a-4991-a2aa-98f486c69f60
clientRegistryTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/f8897cf9-760f-463e-bb27-a86cc9e629de
userProfileTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/7f17084d-14a7-4482-8a7b-e392d1f60d41
txmaEventEncryptionKeyArn: arn:aws:kms:eu-west-2:058264132019:key/d1aefc2a-038d-460f-b6fd-d0ee749d3ad5
orchToAuthTokenSigningKeyAlias: arn:aws:kms:eu-west-2:761723964695:key/c92ae9b2-2e2e-4476-a7c9-b52010440bc1
identityCredentialsTableKeyArn: arn:aws:kms:eu-west-2:761723964695:key/96c3e909-da89-4149-9ac1-c782738b8954
ipvTokenAuthKeyArn: arn:aws:kms:eu-west-2:761723964695:key/42a8b69b-9488-44d2-94b8-144b4ff3b35c
spotRequestQueueKmsArn: arn:aws:kms:eu-west-2:761723964695:key/2c2b295b-4ec7-41dd-b399-a2e98b7b39f9
production:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceProductionVariables
authApiId: "s4gj268zy6"
authExternalApiId: "fag06zqnve"
authAccountId: "172348255554"
authEnvironment: production
serviceDomain: account.gov.uk
idTokenKeyArn: arn:aws:kms:eu-west-2:172348255554:key/01c412c6-98de-48b2-9a6d-51f57e8c3d7a
idTokenKeyRsaArn: arn:aws:kms:eu-west-2:172348255554:key/ce5d0a05-909c-449b-be82-87009f5bef9a
storageTokenKeyArn: arn:aws:kms:eu-west-2:172348255554:key/0fce68a7-62bd-407d-919e-07f3fd621304
ipvTokenKeyArn: arn:aws:kms:eu-west-2:172348255554:key/b1897252-b34b-4094-9e0b-466feed2b7f1
orchToAuthKeyArn: arn:aws:kms:eu-west-2:172348255554:key/cb986cd8-8ac7-43f1-8a74-15d1b77509d9
userInfoEncryptionKeyArn: arn:aws:kms:eu-west-2:172348255554:key/0e5c92f4-26a1-442d-a57b-87db810a40d1
backchannelLogoutQueueArn: arn:aws:sqs:eu-west-2:172348255554:production-back-channel-logout-queue
docAppBackendUri: https://api-backend-api.review-b.account.gov.uk
docAppCriDataV2Endpoint: userinfo/v2
docAppAud: https://www.review-b.account.gov.uk
docAppAuthorisationUrl: https://www.review-b.account.gov.uk/dca/oauth2/authorize
docAppClientId: authOrchestratorDocApp
docAppCredentialTableKeyArn: arn:aws:kms:eu-west-2:172348255554:key/ab10facb-aa4d-47b9-92bb-3974b9585fd4
docAppEncryptionKeyId: 7958938d-eea0-4e6d-9ea1-ec0b9d421f77
docAppSigningKeyArn: arn:aws:kms:eu-west-2:172348255554:key/c6448889-ae6d-4db1-916c-9338a3c2bd1b
clientRegistryTableKeyArn: arn:aws:kms:eu-west-2:172348255554:key/afefa38f-5797-4722-9969-c7ad5ec6d6fe
userProfileTableKeyArn: arn:aws:kms:eu-west-2:172348255554:key/365c4de5-6a6d-43db-8569-eca00e889177
txmaEventEncryptionKeyArn: arn:aws:kms:eu-west-2:533266965190:key/4bc0dac2-f40f-4c3e-9f9e-30549dd8769d
orchToAuthTokenSigningKeyAlias: arn:aws:kms:eu-west-2:172348255554:key/cb986cd8-8ac7-43f1-8a74-15d1b77509d9
identityCredentialsTableKeyArn: arn:aws:kms:eu-west-2:172348255554:key/36023c7d-ec27-45c8-9edd-0761974dd0d3
ipvTokenAuthKeyArn: arn:aws:kms:eu-west-2:172348255554:key/b1897252-b34b-4094-9e0b-466feed2b7f1
spotRequestQueueKmsArn: arn:aws:kms:eu-west-2:172348255554:key/4a4d1b21-d38d-4ce3-bf7f-6778423b297b
Globals:
Function:
Environment:
Variables:
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"
MemorySize: 1536
Timeout: 30
Runtime: java17
Architectures:
- x86_64
PermissionsBoundary: !If
- UsePermissionsBoundary
- !Ref PermissionsBoundary
- !Ref AWS::NoValue
CodeSigningConfigArn: !If
- UseCodeSigning
- !Ref CodeSigningConfigArn
- !Ref AWS::NoValue
Layers:
- !Sub
- '{{resolve:secretsmanager:${SecretArn}:SecretString:JAVA_LAYER}}'
- SecretArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, dynatraceSecretArn ]
VpcConfig:
SecurityGroupIds:
- !Ref LambdaSecurityGroup
SubnetIds:
- Fn::ImportValue: !Sub ${VpcStackName}-PrivateSubnetIdA
- Fn::ImportValue: !Sub ${VpcStackName}-PrivateSubnetIdB
- Fn::ImportValue: !Sub ${VpcStackName}-PrivateSubnetIdC
Resources:
MainKmskeyAlias:
Type: 'AWS::KMS::Alias'
Properties:
AliasName: "alias/mainKmsKey"
TargetKeyId: !Ref MainKmsKey
MainKmsKey:
Type: AWS::KMS::Key
Properties:
Description: Key used to encrypt Orchestration
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}:*
#region Open ID Configuration Lambda
OpenIdConfigurationFunction:
Type: AWS::Serverless::Function
# checkov:skip=CKV_AWS_116: DLQ is not appropriate for a Lambda invoked by an API
# checkov:skip=CKV_AWS_117: Lambdas will migrate to our own VPC in future work
Properties:
FunctionName: !Sub ${Environment}-OpenIdConfigurationFunction
AutoPublishAlias: latest
CodeUri: ./oidc-api
Handler: uk.gov.di.authentication.oidc.lambda.WellknownHandler::handleRequest
ReservedConcurrentExecutions: 1
LoggingConfig:
LogGroup: !Ref OpenIdConfigurationFunctionLogGroup
Environment:
Variables:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
OIDC_API_BASE_URL: !Sub
- https://oidc.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
ENVIRONMENT: !Sub ${Environment}
FRONTEND_BASE_URL: !Sub
- https://signin.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
Tags:
CheckovRulesToSkip: CKV_AWS_116.CKV_AWS_117.CKV_AWS_173
OpenIdConfigurationFunctionCrossAccountPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref OpenIdConfigurationFunction.Alias
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn: !Sub
- 'arn:aws:execute-api:eu-west-2:${AccountId}:${ApiId}/*/GET/.well-known/openid-configuration'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
ApiId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authApiId ]
OpenIdConfigurationFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${Environment}-openid-configuration-lambda
KmsKeyId: !GetAtt MainKmsKey.Arn
RetentionInDays: 14
OpenIdConfigurationSubscriptionFilter:
Condition: IsNotDevEnvironment
Type: AWS::Logs::SubscriptionFilter
Properties:
DestinationArn: !Ref LoggingSubscriptionEndpointArn
FilterPattern: ""
LogGroupName: !Ref OpenIdConfigurationFunctionLogGroup
OpenIdConfigurationFunctionErrorMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
FilterName: !Sub ${Environment}-openid-configuration-errors
FilterPattern: "{($.level = \"ERROR\")}"
LogGroupName: !Ref OpenIdConfigurationFunctionLogGroup
MetricTransformations:
- MetricName: !Sub ${Environment}-openid-configuration-error-count
MetricNamespace: LambdaErrorsNamespace
MetricValue: 1
OpenIdConfigurationFunctionErrorCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
AlarmDescription: !Sub "10 or more errors have occurred in the ${Environment} openid-configuration lambda.ACCOUNT: di-orchestration-${Environment}"
AlarmName: !Sub ${Environment}-openid-configuration-alarm
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
MetricName: OpenIdConfigurationFunctionErrorMetricFilter.MetricTransformations[0].MetricName
Namespace: OpenIdConfigurationFunctionErrorMetricFilter.MetricTransformations[0].MetricNamespace
Period: 3600
Statistic: Sum
Threshold: 10
OpenIdConfigurationFunctionErrorRateCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}-openid-configuration-error-rate-alarm
AlarmDescription: !Sub "Lambda error rate of 10 has been reached in the ${Environment} openid-configuration lambda.ACCOUNT: di-orchestration-${Environment}"
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
Threshold: 10
Metrics:
- Id: e1
ReturnData: true
Expression: m2/m1*100
Label: Error Rate
- Id: m1
ReturnData: false
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Invocations
Dimensions:
- Name: FunctionName
Value: !Ref OpenIdConfigurationFunction.Alias
Period: 60
Stat: Sum
Unit: Count
- Id: m2
ReturnData: false
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref OpenIdConfigurationFunction.Alias
Period: 60
Stat: Sum
Unit: Count
#endregion
#region Trustmark Lambda
TrustmarkFunction:
Type: AWS::Serverless::Function
# checkov:skip=CKV_AWS_116: DLQ is not appropriate for a Lambda invoked by an API
# checkov:skip=CKV_AWS_117: Lambdas will migrate to our own VPC in future work
Properties:
FunctionName: !Sub ${Environment}-TrustmarkFunction
AutoPublishAlias: latest
CodeUri: ./oidc-api
Handler: uk.gov.di.authentication.oidc.lambda.TrustMarkHandler::handleRequest
ReservedConcurrentExecutions: 1
LoggingConfig:
LogGroup: !Ref TrustmarkFunctionLogGroup
Environment:
Variables:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
OIDC_API_BASE_URL: !Sub
- https://oidc.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
ENVIRONMENT: !Sub ${Environment}
FRONTEND_BASE_URL: !Sub
- https://signin.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
Tags:
CheckovRulesToSkip: CKV_AWS_116.CKV_AWS_117.CKV_AWS_173
TrustmarkFunctionCrossAccountPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref TrustmarkFunction.Alias
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn: !Sub
- 'arn:aws:execute-api:eu-west-2:${AccountId}:${ApiId}/*/GET/trustmark'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
ApiId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authApiId ]
TrustmarkFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${Environment}-trustmark-lambda
KmsKeyId: !GetAtt MainKmsKey.Arn
RetentionInDays: 14
TrustmarkSubscriptionFilter:
Condition: IsNotDevEnvironment
Type: AWS::Logs::SubscriptionFilter
Properties:
DestinationArn: !Ref LoggingSubscriptionEndpointArn
FilterPattern: ""
LogGroupName: !Ref TrustmarkFunctionLogGroup
TrustmarkFunctionErrorMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
FilterName: !Sub ${Environment}-trustmark-errors
FilterPattern: "{($.level = \"ERROR\")}"
LogGroupName: !Ref TrustmarkFunctionLogGroup
MetricTransformations:
- MetricName: !Sub ${Environment}-trustmark-error-count
MetricNamespace: LambdaErrorsNamespace
MetricValue: 1
TrustmarkFunctionErrorCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
AlarmDescription: !Sub "10 or more errors have occurred in the ${Environment} trustmark lambda.ACCOUNT: di-orchestration-${Environment}"
AlarmName: !Sub ${Environment}-trustmark-alarm
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
MetricName: TrustmarkFunctionErrorMetricFilter.MetricTransformations[0].MetricName
Namespace: TrustmarkFunctionErrorMetricFilter.MetricTransformations[0].MetricNamespace
Period: 3600
Statistic: Sum
Threshold: 10
TrustmarkFunctionErrorRateCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}-trustmark-error-rate-alarm
AlarmDescription: !Sub "Lambda error rate of 10 has been reached in the ${Environment} trustmark lambda.ACCOUNT: di-orchestration-${Environment}"
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
Threshold: 10
Metrics:
- Id: e1
ReturnData: true
Expression: m2/m1*100
Label: Error Rate
- Id: m1
ReturnData: false
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Invocations
Dimensions:
- Name: FunctionName
Value: !Ref TrustmarkFunction.Alias
Period: 60
Stat: Sum
Unit: Count
- Id: m2
ReturnData: false
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref TrustmarkFunction.Alias
Period: 60
Stat: Sum
Unit: Count
#endregion
#region Back Channel Logout Request Lambda
BackChannelLogoutRequestFunction:
Type: AWS::Serverless::Function
# checkov:skip=CKV_AWS_116: DLQ is not appropriate for a Lambda invoked by an API
# checkov:skip=CKV_AWS_117: Lambda needs open egress so isn't in VPC
IgnoreGlobals: [VpcConfig]
Properties:
FunctionName: !Sub ${Environment}-BackChannelLogoutRequestFunction
AutoPublishAlias: latest
CodeUri: ./oidc-api
Handler: uk.gov.di.authentication.oidc.lambda.BackChannelLogoutRequestHandler::handleRequest
ReservedConcurrentExecutions: 1
LoggingConfig:
LogGroup: !Ref BackChannelLogoutRequestFunctionLogGroup
Events:
BackChannelLogoutQueue:
Type: SQS
Properties:
Queue: !GetAtt BackChannelLogoutQueue.Arn
Environment:
Variables:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
ENVIRONMENT: !Sub ${Environment}
EXTERNAL_TOKEN_SIGNING_KEY_ALIAS: !FindInMap [ EnvironmentConfiguration, !Ref Environment, idTokenKeyArn ]
OIDC_API_BASE_URL: !Sub
- https://oidc.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
Policies:
Statement:
- Sid: AllowIdTokenSigningKms
Effect: Allow
Action:
- kms:Sign
- kms:GetPublicKey
Resource:
- !FindInMap [ EnvironmentConfiguration, !Ref Environment, idTokenKeyArn ]
- Sid: AllowConsumeFromBackChannelLogoutQueue
Effect: Allow
Action:
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:GetQueueAttributes
Resource: !GetAtt BackChannelLogoutQueue.Arn
- Sid: AllowDecryptBackChannelLogoutQueue
Effect: Allow
Action:
- kms:Decrypt
Resource: !GetAtt BackChannelLogoutQueueEncryptionKey.Arn
Tags:
CheckovRulesToSkip: CKV_AWS_116.CKV_AWS_117.CKV_AWS_173
BackChannelLogoutRequestFunctionCrossAccountPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref BackChannelLogoutRequestFunction.Alias
Action: lambda:InvokeFunction
Principal: sqs.amazonaws.com
SourceArn: !FindInMap [ EnvironmentConfiguration, !Ref Environment, backchannelLogoutQueueArn ]
BackChannelLogoutRequestFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${Environment}-backchannel-logout-request-lambda
KmsKeyId: !GetAtt MainKmsKey.Arn
RetentionInDays: 14
BackChannelLogoutRequestSubscriptionFilter:
Condition: IsNotDevEnvironment
Type: AWS::Logs::SubscriptionFilter
Properties:
DestinationArn: !Ref LoggingSubscriptionEndpointArn
FilterPattern: ""
LogGroupName: !Ref BackChannelLogoutRequestFunctionLogGroup
BackChannelLogoutRequestFunctionErrorMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
FilterName: !Sub ${Environment}-backchannel-logout-request-errors
FilterPattern: "{($.level = \"ERROR\")}"
LogGroupName: !Ref BackChannelLogoutRequestFunctionLogGroup
MetricTransformations:
- MetricName: !Sub ${Environment}-backchannel-logout-request-count
MetricNamespace: LambdaErrorsNamespace
MetricValue: 1
BackChannelLogoutRequestFunctionErrorCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
AlarmDescription: !Sub "10 or more errors have occurred in the ${Environment} backchannel logout request lambda.ACCOUNT: di-orchestration-${Environment}"
AlarmName: !Sub ${Environment}-backchannel-logout-request-alarm
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
MetricName: BackChannelLogoutRequestFunctionErrorMetricFilter.MetricTransformations[0].MetricName
Namespace: BackChannelLogoutRequestFunctionErrorMetricFilter.MetricTransformations[0].MetricNamespace
Period: 3600
Statistic: Sum
Threshold: 10
BackChannelLogoutRequestFunctionErrorRateCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}-backchannel-logout-request-error-rate-alarm
AlarmDescription: !Sub "Lambda error rate of 10 has been reached in the ${Environment} backchannel logout request lambda.ACCOUNT: di-orchestration-${Environment}"
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
Threshold: 10
Metrics:
- Id: e1
ReturnData: true
Expression: m2/m1*100
Label: Error Rate
- Id: m1
ReturnData: false
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Invocations
Dimensions:
- Name: FunctionName
Value: !Ref BackChannelLogoutRequestFunction.Alias
Period: 60
Stat: Sum
Unit: Count
- Id: m2
ReturnData: false
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref BackChannelLogoutRequestFunction.Alias
Period: 60
Stat: Sum
Unit: Count
#endregion
#region Doc App Callback Lambda
DocAppCallbackFunction:
Type: AWS::Serverless::Function
IgnoreGlobals: [ VpcConfig ]
# checkov:skip=CKV_AWS_116: DLQ is not appropriate for a Lambda invoked by an API
Properties:
FunctionName: !Sub ${Environment}-DocAppCallbackFunction
AutoPublishAlias: latest
CodeUri: ./doc-checking-app-api
Handler: uk.gov.di.authentication.app.lambda.DocAppCallbackHandler::handleRequest
ReservedConcurrentExecutions: 1
LoggingConfig:
LogGroup: !Ref DocAppCallbackFunctionLogGroup
VpcConfig:
SecurityGroupIds:
- !Ref LambdaSecurityGroup
- !Ref HttpsEgressSecurityGroup
SubnetIds:
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdA
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdB
- Fn::ImportValue: !Sub ${VpcStackName}-ProtectedSubnetIdC
Environment:
Variables:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
CUSTOM_DOC_APP_CLAIM_ENABLED: true
DOC_APP_AUTHORISATION_CALLBACK_URI: !Sub
- https://oidc.${ServiceDomain}/doc-app-callback
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
DOC_APP_AUTHORISATION_CLIENT_ID: authOrchestratorDocApp
DOC_APP_TOKEN_SIGNING_KEY_ALIAS: !Sub
- "alias/${AuthEnvironment}-doc-app-auth-kms-key-alias"
- AuthEnvironment: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authEnvironment ]
DOC_APP_BACKEND_URI: !FindInMap [ EnvironmentConfiguration, !Ref Environment, docAppBackendUri ]
DOC_APP_CRI_DATA_V2_ENDPOINT: !FindInMap [ EnvironmentConfiguration, !Ref Environment, docAppCriDataV2Endpoint ]
DOC_APP_CRI_DATA_ENDPOINT: unused
DOC_APP_V2_DATA_ENDPOINT_ENABLED: true
DOC_APP_JWKS_URL: !Sub
- ${DocAppBackendUri}/.well-known/jwks.json
- DocAppBackendUri: !FindInMap [ EnvironmentConfiguration, !Ref Environment, docAppBackendUri ]
DOC_APP_AUD: !FindInMap [ EnvironmentConfiguration, !Ref Environment, docAppAud ]
DOC_APP_NEW_AUD_CLAIM_ENABLED: true
INTERNAl_SECTOR_URI: !Sub
- https://identity.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
LOGIN_URI: !Sub
- https://signin.${ServiceDomain}/doc-app-callback
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
REDIS_KEY: session
TXMA_AUDIT_QUEUE_URL:
Fn::ImportValue: !Sub orchestration-${Environment}-txma-QueueURL
ENVIRONMENT: !Sub ${Environment}
EXTERNAL_TOKEN_SIGNING_KEY_ALIAS: !FindInMap [ EnvironmentConfiguration, !Ref Environment, idTokenKeyArn ]
OIDC_API_BASE_URL: !Sub
- https://oidc.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
DYNAMO_ARN_PREFIX: !Sub
- 'arn:aws:dynamodb:eu-west-2:${AccountId}:table/${AuthEnvironment}-'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
AuthEnvironment: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authEnvironment ]
Policies:
Statement:
- Sid: AllowGetParameters
Effect: "Allow"
Action:
- "ssm:GetParameter"
- "ssm:GetParameters"
Resource:
- !Sub "arn:aws:ssm:eu-west-2:${AWS::AccountId}:parameter/${Environment}-session-redis-master-host"
- !Sub "arn:aws:ssm:eu-west-2:${AWS::AccountId}:parameter/${Environment}-session-redis-tls"
- !Sub "arn:aws:ssm:eu-west-2:${AWS::AccountId}:parameter/${Environment}-session-redis-port"
- !Sub "arn:aws:ssm:eu-west-2:${AWS::AccountId}:parameter/${Environment}-session-redis-password"
- Sid: AllowDecryptOfParameters
Effect: "Allow"
Action: "kms:Decrypt"
Resource: !GetAtt MainKmsKey.Arn
- Sid: AllowDocAppCredentialTableAccess
Effect: "Allow"
Action:
- dynamodb:BatchGetItem
- dynamodb:DescribeTable
- dynamodb:Get*
- dynamodb:Query
- dynamodb:Scan
- dynamodb:UpdateItem
- dynamodb:PutItem
Resource: !Sub
- 'arn:aws:dynamodb:eu-west-2:${AccountId}:table/${AuthEnvironment}-doc-app-credential'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
AuthEnvironment: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authEnvironment ]
- Sid: AllowDocAppCredentialTableKms
Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:CreateGrant
- kms:DescribeKey
Resource: !FindInMap [ EnvironmentConfiguration, !Ref Environment, docAppCredentialTableKeyArn ]
- Sid: AllowDocAppSigningKey
Effect: Allow
Action:
- kms:Sign
- kms:GetPublicKey
Resource: !FindInMap [ EnvironmentConfiguration, !Ref Environment, docAppSigningKeyArn ]
- Sid: AllowTxMAEventKms
Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:CreateGrant
- kms:DescribeKey
Resource: !FindInMap [ EnvironmentConfiguration, !Ref Environment, txmaEventEncryptionKeyArn ]
- Sid: AllowSQSTxMA
Effect: Allow
Action:
- sqs:SendMessage
Resource:
- !Sub arn:aws:sqs:eu-west-2:${AWS::AccountId}:orchestration-${Environment}-txma-AuditEventQueue
Tags:
CheckovRulesToSkip: CKV_AWS_116.CKV_AWS_173
DocAppCallbackFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${Environment}-doc-app-callback-lambda
KmsKeyId: !GetAtt MainKmsKey.Arn
RetentionInDays: 14
DocAppSubscriptionFilter:
Condition: IsNotDevEnvironment
Type: AWS::Logs::SubscriptionFilter
Properties:
DestinationArn: !Ref LoggingSubscriptionEndpointArn
FilterPattern: ""
LogGroupName: !Ref DocAppCallbackFunctionLogGroup
DocAppCallbackFunctionCrossAccountPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref DocAppCallbackFunction.Alias
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn: !Sub
- 'arn:aws:execute-api:eu-west-2:${AccountId}:${ApiId}/*/GET/doc-app-callback'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
ApiId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authApiId ]
#endregion
#region Token Lambda
TokenFunction:
Type: AWS::Serverless::Function
# checkov:skip=CKV_AWS_116: DLQ is not appropriate for a Lambda invoked by an API
# checkov:skip=CKV_AWS_117: VPC settings are global
Properties:
FunctionName: !Sub ${Environment}-TokenFunction
AutoPublishAlias: latest
CodeUri: ./oidc-api
Handler: uk.gov.di.authentication.oidc.lambda.TokenHandler::handleRequest
ReservedConcurrentExecutions: 1
LoggingConfig:
LogGroup: !Ref TokenFunctionLogGroup
Environment:
Variables:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
ENVIRONMENT: !Sub ${Environment}
EXTERNAL_TOKEN_SIGNING_KEY_ALIAS: !FindInMap [ EnvironmentConfiguration, !Ref Environment, idTokenKeyArn ]
EXTERNAL_TOKEN_SIGNING_KEY_RSA_ALIAS: !FindInMap [ EnvironmentConfiguration, !Ref Environment, idTokenKeyRsaArn ]
OIDC_API_BASE_URL: !Sub
- https://oidc.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
TXMA_AUDIT_QUEUE_URL:
Fn::ImportValue: !Sub orchestration-${Environment}-txma-QueueURL
REDIS_KEY: session
INTERNAl_SECTOR_URI: !Sub
- https://identity.${ServiceDomain}/
- ServiceDomain: !FindInMap [ EnvironmentConfiguration, !Ref Environment, serviceDomain ]
DYNAMO_ARN_PREFIX: !Sub
- 'arn:aws:dynamodb:eu-west-2:${AccountId}:table/${AuthEnvironment}-'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
AuthEnvironment: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authEnvironment ]
Policies:
Statement:
- Sid: AllowIdTokenSigningKms
Effect: Allow
Action:
- kms:Sign
- kms:GetPublicKey
Resource:
- !FindInMap [ EnvironmentConfiguration, !Ref Environment, idTokenKeyArn ]
- Sid: AllowIdTokenSigningKmsRsa
Effect: Allow
Action:
- kms:Sign
- kms:GetPublicKey
Resource:
- !FindInMap [ EnvironmentConfiguration, !Ref Environment, idTokenKeyRsaArn ]
- Sid: AllowGetParameters
Effect: "Allow"
Action:
- "ssm:GetParameter"
- "ssm:GetParameters"
Resource:
- !Sub "arn:aws:ssm:eu-west-2:816047645251:parameter/${Environment}-session-redis-master-host"
- !Sub "arn:aws:ssm:eu-west-2:816047645251:parameter/${Environment}-session-redis-tls"
- !Sub "arn:aws:ssm:eu-west-2:816047645251:parameter/${Environment}-session-redis-port"
- !Sub "arn:aws:ssm:eu-west-2:816047645251:parameter/${Environment}-session-redis-password"
- Sid: AllowDecryptOfParameters
Effect: "Allow"
Action: "kms:Decrypt"
Resource: !GetAtt MainKmsKey.Arn
- Sid: AllowClientRegistryTableReadAccess
Effect: "Allow"
Action:
- dynamodb:BatchGetItem
- dynamodb:DescribeTable
- dynamodb:Get*
- dynamodb:Query
- dynamodb:Scan
Resource: !Sub
- 'arn:aws:dynamodb:eu-west-2:${AccountId}:table/${AuthEnvironment}-client-registry'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
AuthEnvironment: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authEnvironment ]
- Sid: AllowClientRegistryTableKms
Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:CreateGrant
- kms:DescribeKey
Resource: !FindInMap [ EnvironmentConfiguration, !Ref Environment, clientRegistryTableKeyArn ]
- Sid: AllowUserProfileTableReadAndWriteAccess
Effect: "Allow"
Action:
- dynamodb:DescribeTable
- dynamodb:Get*
- dynamodb:Query
- dynamodb:Scan
- dynamodb:UpdateItem
- dynamodb:PutItem
Resource:
- !Sub
- arn:aws:dynamodb:eu-west-2:${AccountId}:table/${AuthEnvironment}-user-profile
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
AuthEnvironment: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authEnvironment ]
- !Sub
- arn:aws:dynamodb:eu-west-2:${AccountId}:table/${AuthEnvironment}-user-profile/index/*
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
AuthEnvironment: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authEnvironment ]
- Sid: AllowUserProfileTableKms
Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:CreateGrant
- kms:DescribeKey
Resource: !FindInMap [ EnvironmentConfiguration, !Ref Environment, userProfileTableKeyArn ]
- Sid: AllowTxMAEventKms
Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:CreateGrant
- kms:DescribeKey
Resource: !FindInMap [ EnvironmentConfiguration, !Ref Environment, txmaEventEncryptionKeyArn ]
- Sid: AllowSQSTxMA
Effect: Allow
Action:
- sqs:SendMessage
Resource:
- !Sub arn:aws:sqs:eu-west-2:${AWS::AccountId}:orchestration-${Environment}-txma-AuditEventQueue
Tags:
CheckovRulesToSkip: CKV_AWS_116.CKV_AWS_117.CKV_AWS_173
TokenFunctionCrossAccountPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref TokenFunction.Alias
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn: !Sub
- 'arn:aws:execute-api:eu-west-2:${AccountId}:${ApiId}/*/POST/token'
- AccountId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authAccountId ]
ApiId: !FindInMap [ EnvironmentConfiguration, !Ref Environment, authApiId ]
TokenFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${Environment}-token-lambda
KmsKeyId: !GetAtt MainKmsKey.Arn
RetentionInDays: 14
TokenSubscriptionFilter:
Condition: IsNotDevEnvironment
Type: AWS::Logs::SubscriptionFilter
Properties:
DestinationArn: !Ref LoggingSubscriptionEndpointArn
FilterPattern: ""
LogGroupName: !Ref TokenFunctionLogGroup
TokenFunctionErrorMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
FilterName: !Sub ${Environment}-token-request-errors
FilterPattern: "{($.level = \"ERROR\")}"
LogGroupName: !Ref TokenFunctionLogGroup
MetricTransformations:
- MetricName: !Sub ${Environment}-token-count
MetricNamespace: LambdaErrorsNamespace
MetricValue: 1
TokenFunctionErrorCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
AlarmDescription: !Sub "10 or more errors have occurred in the ${Environment} token lambda.ACCOUNT: di-orchestration-${Environment}"
AlarmName: !Sub ${Environment}-token-alarm
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
MetricName: TokenFunctionErrorMetricFilter.MetricTransformations[0].MetricName
Namespace: TokenFunctionErrorMetricFilter.MetricTransformations[0].MetricNamespace
Period: 3600
Statistic: Sum
Threshold: 10
TokenFunctionErrorRateCloudwatchAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub ${Environment}-token-error-rate-alarm
AlarmDescription: !Sub "Lambda error rate of 10 has been reached in the ${Environment} token lambda.ACCOUNT: di-orchestration-${Environment}"
ActionsEnabled: true
AlarmActions:
- !Ref SlackEvents
ComparisonOperator: GreaterThanOrEqualToThreshold