-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
1020 lines (953 loc) · 29.1 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
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Deployment (Leave all fields blank to create a new VPC)
Parameters:
- Vpc
- PublicSubnetAz1
- PrivateSubnetAz1
- PublicSubnetAz2
- PrivateSubnetAz2
- PublicSubnetAz3
- PrivateSubnetAz3
- Label:
default: Deployment
Parameters:
- ClusterName
- DomainName
- EmailFrom
- CertificateArn
- PrivateAccessCidr
- BackupBucket
- BackupPrefix
ParameterLabels:
Vpc:
default: Vpc
PublicSubnetAz1:
default: Public Subnet - AZ1
PrivateSubnetAz1:
default: Private Subnet - AZ1
PublicSubnetAz2:
default: Public Subnet - AZ2
PrivateSubnetAz2:
default: Private Subnet - AZ2
PublicSubnetAz3:
default: Public Subnet - AZ3
PrivateSubnetAz3:
default: Private Subnet - AZ3
ClusterName:
default: ECS Cluster Name
DomainName:
default: Domain Name
EmailFrom:
default: Email From Address
CertificateArn:
default: SSL Certificate Arn
PrivateAccessCidr:
default: Private Access Cidr Range
BackupBucket:
default: Provide an existing S3 bucket target to enable EFS to S3 daily backups
BackupPrefix:
default: Provide a prefix to use for S3 daily backups
Parameters:
Vpc:
Type: String
Description: The VPC to use.
Default: ''
PublicSubnetAz1:
Type: String
Description: The AZ1 Public Subnet for the Load Balancer.
Default: ''
PrivateSubnetAz1:
Type: String
Description: The AZ1 Private Subnet for the ECS task and EFS
Default: ''
PublicSubnetAz2:
Type: String
Description: The AZ2 Public Subnet for the Load Balancer.
Default: ''
PrivateSubnetAz2:
Type: String
Description: The AZ2 Private Subnet for the ECS task and EFS
Default: ''
PublicSubnetAz3:
Type: String
Description: (Optional) The AZ3 Public Subnet for the Load Balancer.
Default: ''
PrivateSubnetAz3:
Type: String
Description: (Optional) The AZ3 Private Subnet for the ECS task and EFS
Default: ''
ClusterName:
Type: String
Description: (Optional) The name of an existing ECS cluster. (Leave blank to create a new cluster).
Default: ''
DomainName:
Type: String
Description: The domain url to be used to access VaultWarden.
AllowedPattern: '^[a-z0-9\-\.]+[^\.]$'
ConstraintDescription: 'Must be a valid domain name string and also must NOT end in a full stop.'
Default: vaultwarden.example.com
EmailFrom:
Type: String
Description: The email address for VaultWarden to send from.
AllowedPattern: '^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$'
ConstraintDescription: 'Must be a valid email address'
Default: [email protected]
CertificateArn:
Type: String
Description: The Arn for the ACM certificate for the supplied Dns Name.
PrivateAccessCidr:
Type: String
Description: (Optional) The CIDR to allow private HTTP access to ECS Tasks from.
Default: ''
BackupBucket:
Type: String
Description: (Optional) The name of a S3 bucket to enable daily backups of the secrets database from EFS to S3.
Default: ''
BackupPrefix:
Type: String
Description: The prefix to use when saving daily backups to S3.
Default: 'backups'
Conditions:
EnableBackup: !Not [!Equals [!Ref BackupBucket, '']]
CreateCluster: !Equals [!Ref ClusterName, '']
AddPrivateAccess: !Not [!Equals [!Ref PrivateAccessCidr, '']]
CreateVpc: !Or
- !Equals [!Ref Vpc, '']
- !Equals [!Ref PublicSubnetAz1, '']
- !Equals [!Ref PrivateSubnetAz1, '']
- !Equals [!Ref PublicSubnetAz2, '']
- !Equals [!Ref PrivateSubnetAz2, '']
PrivateAz3Supplied: !And
- !Not [!Equals [!Ref PrivateSubnetAz3, '']]
- !Not [!Condition CreateVpc]
PublicAz3Supplied: !And
- !Not [!Equals [!Ref PublicSubnetAz3, '']]
- !Not [!Condition CreateVpc]
LogDeliverySupported: !Not
- !Or
- !Or
- !Equals [!Ref 'AWS::Region', 'af-south-1']
- !Equals [!Ref 'AWS::Region', 'ap-east-1']
- !Equals [!Ref 'AWS::Region', 'ap-northeast-1']
- !Equals [!Ref 'AWS::Region', 'ap-northeast-2']
- !Equals [!Ref 'AWS::Region', 'ap-northeast-3']
- !Equals [!Ref 'AWS::Region', 'ap-south-1']
- !Equals [!Ref 'AWS::Region', 'ap-southeast-1']
- !Equals [!Ref 'AWS::Region', 'ap-southeast-2']
- !Equals [!Ref 'AWS::Region', 'ap-southeast-3']
- !Equals [!Ref 'AWS::Region', 'ca-central-1']
- !Or
- !Equals [!Ref 'AWS::Region', 'eu-central-1']
- !Equals [!Ref 'AWS::Region', 'eu-north-1']
- !Equals [!Ref 'AWS::Region', 'eu-south-1']
- !Equals [!Ref 'AWS::Region', 'eu-west-1']
- !Equals [!Ref 'AWS::Region', 'eu-west-2']
- !Equals [!Ref 'AWS::Region', 'eu-west-3']
- !Equals [!Ref 'AWS::Region', 'me-south-1']
- !Equals [!Ref 'AWS::Region', 'sa-east-1']
- !Equals [!Ref 'AWS::Region', 'us-east-1']
- !Equals [!Ref 'AWS::Region', 'us-east-2']
- !Or
- !Equals [!Ref 'AWS::Region', 'us-gov-east-1']
- !Equals [!Ref 'AWS::Region', 'us-gov-west-1']
- !Equals [!Ref 'AWS::Region', 'us-west-1']
- !Equals [!Ref 'AWS::Region', 'us-west-2']
Mappings:
LoggingAccount:
af-south-1:
id: '098369216593'
ap-east-1:
id: '754344448648'
ap-northeast-1:
id: '582318560864'
ap-northeast-2:
id: '600734575887'
ap-northeast-3:
id: '383597477331'
ap-south-1:
id: '718504428378'
ap-southeast-1:
id: '114774131450'
ap-southeast-2:
id: '783225319266'
ap-southeast-3:
id: '589379963580'
ca-central-1:
id: '985666609251'
eu-central-1:
id: '054676820928'
eu-north-1:
id: '897822967062'
eu-south-1:
id: '635631232127'
eu-west-1:
id: '156460612806'
eu-west-2:
id: '652711504416'
eu-west-3:
id: '009996457667'
me-south-1:
id: '076674570225'
sa-east-1:
id: '507241528517'
us-east-1:
id: '127311923021'
us-east-2:
id: '033677994240'
us-gov-east-1:
id: '190560391635'
us-gov-west-1:
id: '048591011584'
us-west-1:
id: '027434742980'
us-west-2:
id: '797873946194'
Resources:
VpcStack:
Condition: CreateVpc
Type: AWS::CloudFormation::Stack
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Properties:
TemplateURL: nested/vpc.yaml
AdminToken:
Type: AWS::SecretsManager::Secret
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Metadata:
cfn_nag:
rules_to_suppress:
- id: W77
reason: Custom KMS Key not required.
Properties:
Description: This is the Admin Token required to access the VaultWarden Admin page.
GenerateSecretString:
PasswordLength: 32
ExcludePunctuation: True
UtilityFunction:
Type: AWS::Serverless::Function
Metadata:
cfn_nag:
rules_to_suppress:
- id: W89
reason: VPC not required.
- id: W92
reason: ReservedConcurrentExecutions not required.
Properties:
Runtime: python3.11
Handler: app.handler
MemorySize: 128
Timeout: 3
CodeUri: functions/utility-function
Policies:
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource: !Ref AdminToken
SmtpUser:
Type: AWS::IAM::User
Metadata:
cfn_nag:
rules_to_suppress:
- id: F10
reason: Single user policy.
- id: F2000
reason: Single user no groups required.
Properties:
Policies:
- PolicyName: SesPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: ses:SendRawEmail
Resource: '*'
SmtpAccessKey:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref SmtpUser
Secrets:
Type: Custom::Utility
Properties:
ServiceToken: !GetAtt UtilityFunction.Arn
SecretAccessKey: !GetAtt SmtpAccessKey.SecretAccessKey
TokenSecretId: !Ref AdminToken
SmtpSecret:
Type: AWS::SecretsManager::Secret
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Metadata:
cfn_nag:
rules_to_suppress:
- id: W77
reason: Custom KMS Key not required.
Properties:
Description: This secret holds the SMTP credentials for SES.
SecretString: !Sub '{"username": "${SmtpAccessKey}", "password": "${Secrets.SmtpPassword}"}'
SecurityGroupEcs:
Type: AWS::EC2::SecurityGroup
Metadata:
cfn_nag:
rules_to_suppress:
- id: W5
reason: All protocols desired for outbound traffic.
- id: W40
reason: All protocols desired for outbound traffic.
Properties:
GroupDescription: Access to the containers
VpcId: !If
- CreateVpc
- !GetAtt VpcStack.Outputs.VpcId
- !Ref Vpc
SecurityGroupIngress: !If
- AddPrivateAccess
- - Description: Private Http Access
CidrIp: !Ref PrivateAccessCidr
FromPort: 80
ToPort: 80
IpProtocol: tcp
- !Ref AWS::NoValue
SecurityGroupEgress:
- Description: All outbound
CidrIp: 0.0.0.0/0
IpProtocol: '-1'
SecurityGroupLambdaBackup:
Type: AWS::EC2::SecurityGroup
Condition: EnableBackup
Metadata:
cfn_nag:
rules_to_suppress:
- id: W5
reason: All protocols desired for outbound traffic.
- id: W40
reason: All protocols desired for outbound traffic.
Properties:
GroupDescription: Lambda Security Group to be referenced in EFS Sec Group
VpcId: !If
- CreateVpc
- !GetAtt VpcStack.Outputs.VpcId
- !Ref Vpc
SecurityGroupEgress:
- Description: Access to EFS
DestinationSecurityGroupId: !Ref SecurityGroupEfs
IpProtocol: tcp
FromPort: 2049
ToPort: 2049
- Description: S3 write access
CidrIp: 0.0.0.0/0
IpProtocol: tcp
FromPort: 443
ToPort: 443
SecurityGroupAlb:
Type: AWS::EC2::SecurityGroup
Metadata:
cfn_nag:
rules_to_suppress:
- id: W2
reason: All https traffic allowed.
- id: W9
reason: All https traffic allowed.
Properties:
GroupDescription: Access to the load balancer
VpcId: !If
- CreateVpc
- !GetAtt VpcStack.Outputs.VpcId
- !Ref Vpc
SecurityGroupIngress:
- Description: https access
CidrIp: 0.0.0.0/0
FromPort: 443
ToPort: 443
IpProtocol: tcp
SecurityGroupEgress:
- Description: Outbound to ECS
DestinationSecurityGroupId: !Ref SecurityGroupEcs
IpProtocol: tcp
FromPort: 80
ToPort: 80
SecurityGroupEcsIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref SecurityGroupEcs
Description: Inbound from ALB
SourceSecurityGroupId: !Ref SecurityGroupAlb
IpProtocol: tcp
FromPort: 80
ToPort: 80
SecurityGroupEfs:
Type: AWS::EC2::SecurityGroup
Metadata:
cfn_nag:
rules_to_suppress:
- id: W5
reason: All protocols desired for outbound traffic.
- id: W40
reason: All protocols desired for outbound traffic.
Properties:
GroupDescription: Access to EFS
VpcId: !If
- CreateVpc
- !GetAtt VpcStack.Outputs.VpcId
- !Ref Vpc
SecurityGroupIngress:
- Description: ECS EFS access
SourceSecurityGroupId: !Ref SecurityGroupEcs
FromPort: 2049
ToPort: 2049
IpProtocol: tcp
SecurityGroupEgress:
- Description: All outbound
CidrIp: 0.0.0.0/0
IpProtocol: '-1'
SecurityGroupEFSIngressLambda:
Type: AWS::EC2::SecurityGroupIngress
Condition: EnableBackup
Properties:
GroupId: !Ref SecurityGroupEfs
Description: Lambda EFS Access
SourceSecurityGroupId: !Ref SecurityGroupLambdaBackup
IpProtocol: tcp
FromPort: 2049
ToPort: 2049
FileSystem:
Type: AWS::EFS::FileSystem
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Properties:
BackupPolicy:
Status: ENABLED
Encrypted: TRUE
LifecyclePolicies:
- TransitionToIA: AFTER_14_DAYS
PerformanceMode: generalPurpose
ThroughputMode: bursting
MountTarget0:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !If
- CreateVpc
- !GetAtt VpcStack.Outputs.PrivateSubnetIdAz1
- !Ref PrivateSubnetAz1
SecurityGroups:
- !Ref SecurityGroupEfs
MountTarget1:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !If
- CreateVpc
- !GetAtt VpcStack.Outputs.PrivateSubnetIdAz2
- !Ref PrivateSubnetAz2
SecurityGroups:
- !Ref SecurityGroupEfs
MountTarget2:
Condition: PrivateAz3Supplied
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !Ref PrivateSubnetAz3
SecurityGroups:
- !Ref SecurityGroupEfs
LambdaEFSAccessPoint:
Condition: EnableBackup
Type: AWS::EFS::AccessPoint
Properties:
FileSystemId: !Ref FileSystem
LogBucket:
Type: AWS::S3::Bucket
Metadata:
cfn_nag:
rules_to_suppress:
- id: W35
reason: Access logging not required.
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- BucketKeyEnabled: True
ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
LogBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref LogBucket
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: s3:PutObject
Principal: !If
- LogDeliverySupported
- Service: logdelivery.elasticloadbalancing.amazonaws.com
- AWS: !Sub
- 'arn:aws:iam::${LogAccountId}:root'
- LogAccountId: !FindInMap [LoggingAccount, !Ref 'AWS::Region', id]
Resource: !Sub '${LogBucket.Arn}/vaultwarden-alb/AWSLogs/${AWS::AccountId}/*'
LoadBalancer:
DependsOn: LogBucketPolicy
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Type: application
Scheme: internet-facing
IpAddressType: ipv4
Subnets:
- !If
- CreateVpc
- !GetAtt VpcStack.Outputs.PublicSubnetIdAz1
- !Ref PublicSubnetAz1
- !If
- CreateVpc
- !GetAtt VpcStack.Outputs.PublicSubnetIdAz2
- !Ref PublicSubnetAz2
- !If
- PublicAz3Supplied
- !Ref PublicSubnetAz3
- !Ref AWS::NoValue
SecurityGroups:
- !Ref SecurityGroupAlb
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: '30'
- Key: access_logs.s3.enabled
Value: True
- Key: access_logs.s3.bucket
Value: !Ref LogBucket
- Key: access_logs.s3.prefix
Value: vaultwarden-alb
Listener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Protocol: HTTPS
Port: 443
Certificates:
- CertificateArn: !Ref CertificateArn
SslPolicy: ELBSecurityPolicy-TLS13-1-0-2021-06
DefaultActions:
- Order: 10
Type: forward
TargetGroupArn: !Ref TargetGroup
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: LoadBalancer
Properties:
Protocol: HTTP
Port: 80
TargetType: ip
VpcId: !If
- CreateVpc
- !GetAtt VpcStack.Outputs.VpcId
- !Ref Vpc
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '5'
HealthCheckProtocol: HTTP
HealthCheckPath: /
HealthCheckPort: traffic-port
HealthyThresholdCount: 2
UnhealthyThresholdCount: 2
HealthCheckTimeoutSeconds: 2
HealthCheckIntervalSeconds: 5
Matcher:
HttpCode: '200'
EcsExecutionRole:
Type: AWS::IAM::Role
Properties:
Description: The ECS Execution IAM Role
AssumeRolePolicyDocument:
Version: '2008-10-17'
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
Policies:
- PolicyName: CreateLogGroup
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: logs:CreateLogGroup
Resource: !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:*'
- PolicyName: GetSecretValues
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource: !Ref SmtpSecret
EcsTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Cpu: '1024'
Memory: '2048'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: !GetAtt EcsExecutionRole.Arn
TaskRoleArn: !GetAtt EcsTaskRole.Arn
ContainerDefinitions:
- Name: vaultwarden
Image: vaultwarden/server:latest
Environment:
- Name: ADMIN_TOKEN
Value: !GetAtt Secrets.AdminToken
- Name: SMTP_HOST
Value: !Sub email-smtp.${AWS::Region}.amazonaws.com
- Name: SMTP_FROM
Value: !Ref EmailFrom
- Name: SMTP_PORT
Value: '587'
- Name: SMTP_SSL
Value: 'true'
- Name: DOMAIN
Value: !Sub https://${DomainName}
- Name: AWS_ACCOUNT_ID
Value: !Ref AWS::AccountId
- Name: AWS_REGION
Value: !Ref AWS::Region
Secrets:
- Name: SMTP_USERNAME
ValueFrom: !Sub '${SmtpSecret}:username::'
- Name: SMTP_PASSWORD
ValueFrom: !Sub '${SmtpSecret}:password::'
PortMappings:
- ContainerPort: 80
Protocol: tcp
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-create-group: true
awslogs-group: /ecs/vaultwarden
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: external
LinuxParameters:
InitProcessEnabled: True
Essential: True
MountPoints:
- SourceVolume: efs-vaultwarden
ContainerPath: /data
ReadOnly: False
Volumes:
- Name: efs-vaultwarden
EFSVolumeConfiguration:
FilesystemId: !Ref FileSystem
RootDirectory: /
TransitEncryption: ENABLED
AuthorizationConfig:
IAM: ENABLED
EcsCluster:
Condition: CreateCluster
Type: AWS::ECS::Cluster
EcsService:
Type: AWS::ECS::Service
DependsOn: Listener
Properties:
Cluster: !If
- CreateCluster
- !Ref EcsCluster
- !Ref ClusterName
TaskDefinition: !Ref EcsTaskDefinition
LoadBalancers:
- TargetGroupArn: !Ref TargetGroup
ContainerName: vaultwarden
ContainerPort: 80
DesiredCount: 1
EnableExecuteCommand: True
LaunchType: FARGATE
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: DISABLED
SecurityGroups:
- !Ref SecurityGroupEcs
Subnets:
- !If
- CreateVpc
- !GetAtt VpcStack.Outputs.PrivateSubnetIdAz1
- !Ref PrivateSubnetAz1
- !If
- CreateVpc
- !GetAtt VpcStack.Outputs.PrivateSubnetIdAz2
- !Ref PrivateSubnetAz3
- !If
- PrivateAz3Supplied
- !Ref PrivateSubnetAz3
- !Ref AWS::NoValue
DeploymentConfiguration:
MinimumHealthyPercent: 100
MaximumPercent: 200
DeploymentController:
Type: ECS
EnableECSManagedTags: True
Tags:
- Key: target-group-arn
Value: !Ref TargetGroup
EcsTaskRole:
Type: AWS::IAM::Role
Metadata:
cfn_nag:
rules_to_suppress:
- id: F3
reason: Specific permision not possible.
- id: W11
reason: Resource level policy not possible.
Properties:
Description: The ECS Execution IAM Role
AssumeRolePolicyDocument:
Version: '2008-10-17'
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
Policies:
- PolicyName: EFS
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'elasticfilesystem:*'
Resource: !Sub 'arn:${AWS::Partition}:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:file-system/${FileSystem}'
- PolicyName: SSM
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- ssmmessages:CreateControlChannel
- ssmmessages:CreateDataChannel
- ssmmessages:OpenControlChannel
- ssmmessages:OpenDataChannel
Resource: '*'
Waf:
Type: AWS::WAFv2::WebACL
Properties:
Scope: REGIONAL
Description: WAF for VaultWarden
DefaultAction:
Allow: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: VaultWardenWaf
Rules:
- Name: AWSManagedRulesAdminProtectionRuleSet
Priority: 0
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesAdminProtectionRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesAdminProtectionRuleSet
- Name: AWSManagedRulesAmazonIpReputationList
Priority: 1
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesAmazonIpReputationList
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesAmazonIpReputationList
- Name: AWSManagedRulesAnonymousIpList
Priority: 2
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesAnonymousIpList
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesAnonymousIpList
- Name: AWSManagedRulesCommonRuleSet
Priority: 3
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesCommonRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesCommonRuleSet
- Name: AWSManagedRulesKnownBadInputsRuleSet
Priority: 4
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesKnownBadInputsRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesKnownBadInputsRuleSet
- Name: AWSManagedRulesLinuxRuleSet
Priority: 5
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesLinuxRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesLinuxRuleSet
- Name: AWSManagedRulesPHPRuleSet
Priority: 6
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesPHPRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesPHPRuleSet
- Name: AWSManagedRulesSQLiRuleSet
Priority: 7
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesSQLiRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesSQLiRuleSet
- Name: AWSManagedRulesUnixRuleSet
Priority: 8
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesUnixRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesUnixRuleSet
- Name: AWSManagedRulesWordPressRuleSet
Priority: 9
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: True
CloudWatchMetricsEnabled: True
MetricName: AWSManagedRulesWordPressRuleSet
Statement:
ManagedRuleGroupStatement:
VendorName: AWS
Name: AWSManagedRulesWordPressRuleSet
WafAssociation:
Type: AWS::WAFv2::WebACLAssociation
Properties:
ResourceArn: !Ref LoadBalancer
WebACLArn: !GetAtt Waf.Arn
WafLogGroup:
Type: AWS::Logs::LogGroup
Metadata:
cfn_nag:
rules_to_suppress:
- id: W84
reason: Custom KMS Key not required.
Properties:
LogGroupName: aws-waf-logs-vaultwarden
RetentionInDays: 30
WafLoggingConfiguration:
Type: AWS::WAFv2::LoggingConfiguration
Properties:
ResourceArn: !GetAtt Waf.Arn
LogDestinationConfigs:
- !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${WafLogGroup}
LoggingFilter:
DefaultBehavior: DROP
Filters:
- Behavior: KEEP
Requirement: MEETS_ALL
Conditions:
- ActionCondition:
Action: BLOCK
BackupFunction:
Condition: EnableBackup
Type: AWS::Serverless::Function
Metadata:
cfn_nag:
rules_to_suppress:
- id: W89
reason: VPC not required.
- id: W92
reason: ReservedConcurrentExecutions not required.
Properties:
Runtime: python3.11
Handler: app.handler
MemorySize: 128
Timeout: 30
CodeUri: functions/backup-function
Events:
CWSchedule:
Type: ScheduleV2
Properties:
ScheduleExpression: 'rate(1 day)'
Policies:
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:PutObject
Resource: !Sub arn:${AWS::Partition}:s3:::${BackupBucket}/${BackupPrefix}/*
Environment:
Variables:
BACKUP_BUCKET: !Ref BackupBucket
BACKUP_PREFIX: !Ref BackupPrefix
FileSystemConfigs:
- Arn: !GetAtt LambdaEFSAccessPoint.Arn
LocalMountPath: /mnt/efs
VpcConfig:
SecurityGroupIds:
- !Ref SecurityGroupLambdaBackup
SubnetIds:
- !If
- CreateVpc
- !GetAtt VpcStack.Outputs.PrivateSubnetIdAz1
- !Ref PrivateSubnetAz1