-
Notifications
You must be signed in to change notification settings - Fork 12
/
ood.yml
1099 lines (1042 loc) · 35.2 KB
/
ood.yml
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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
---
AWSTemplateFormatVersion: 2010-09-09
Description: OpenOnDemand on AWS
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Portal
Parameters:
- WebsiteDomainName
- PortalAllowedIPCIDR
- Label:
default: Route53
Parameters:
- HostedZoneName
- HostedZoneId
- Label:
default: Networking
Parameters:
- VPC
- PublicSubnets
- PrivateSubnets
- Label:
default: Active Directory
Parameters:
- ADAdministratorSecret
- TopLevelDomain
- DomainName
- Label:
default: Storage
Parameters:
- LoadBalancerLogBucket
- Label:
default: Open OnDemand
Parameters:
- Branch
- SlurmVersion
ParameterLabels:
PortalAllowedIPCIDR:
default: Portal Allowed IP CIDR
WebsiteDomainName:
default: Website Domain Name
HostedZoneName:
default: Hosted Zone Name
HostedZoneId:
default: Hosted Zone Id
Parameters:
DomainName:
Description: Domain name not including the top level domain
Default: hpclab
Type: String
AllowedPattern: '[a-zA-Z0-9]+'
TopLevelDomain:
Description: TLD for your domain (i.e. local, com, etc)
Type: String
MinLength: '1'
MaxLength: '15'
Default: local
AllowedPattern: '[a-zA-Z0-9]+'
WebsiteDomainName:
Description: Domain name for world facing website
Type: String
HostedZoneName:
Description: Hosted zone for the domain
Type: String
AllowedPattern: '[A-Za-z\.]*\.$'
HostedZoneId:
Description: Hosted Zone Id for Route53 Domain
Type: String
PortalAllowedIPCIDR:
Description: IP CIDR for access to the Portal
Default: 0.0.0.0/0
Type: String
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
ConstraintDescription: must be a valid CIDR range of the form x.x.x.x/x.
VPC:
Description: VPC to deploy the portal
Type: AWS::EC2::VPC::Id
ConstraintDescription: must be a valid VPC Id
PublicSubnets:
Description: Public subnets
Type: List<AWS::EC2::Subnet::Id>
PrivateSubnets:
Description: Private subnets
Type: List<AWS::EC2::Subnet::Id>
ADAdministratorSecret:
Description: AD Admin Secret ARN
Type: String
AllowedPattern: 'arn:aws:secretsmanager:[a-z0-9-]+:[0-9]{12}:secret:[a-zA-Z0-9/-]*'
LDAPNLBEndPoint:
Description: LDAP NLB End Point
Type: String
LoadBalancerLogBucket:
Description: S3 Bucket to store LB logs
Type: String
AllowedPattern: '[a-z0-9.-]*'
Branch:
Description: Branch of the code to deploy. Only use this when testing changes to the solution
Default: main
Type: String
SlurmVersion:
Description: Verion of slurm to install
Default: 23.11.10
Type: String
Resources:
OODCertificate:
Type: AWS::CertificateManager::Certificate
Properties:
DomainName: !Ref WebsiteDomainName
ValidationMethod: DNS
DomainValidationOptions:
- HostedZoneId: !Ref HostedZoneId
DomainName: !Ref WebsiteDomainName
ALBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security Group for ALB
SecurityGroupIngress:
- CidrIp: !Ref PortalAllowedIPCIDR
FromPort: 443
ToPort: 443
IpProtocol: tcp
Description: HTTPS Access
SecurityGroupEgress:
- Description: Remove default rule for egress
CidrIp: 127.0.0.1/32
IpProtocol: "-1"
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - ALB SecurityGroup'
ALBSecurityGroupEgressHTTP:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 443
ToPort: 443
Description: HTTPS Outbound
GroupId: !GetAtt ALBSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt PortalSecurityGroup.GroupId
ALBSecurityGroupEgressHTTPS:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 80
ToPort: 80
Description: HTTP outbound
GroupId: !GetAtt ALBSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt PortalSecurityGroup.GroupId
PortalSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security Group for OOD Portal Cluster
VpcId: !Ref VPC
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref ALBSecurityGroup
FromPort: 80
ToPort: 80
IpProtocol: tcp
Description: HTTP Access
- SourceSecurityGroupId: !Ref ALBSecurityGroup
FromPort: 443
ToPort: 443
IpProtocol: tcp
Description: HTTPS Access
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
IpProtocol: tcp
FromPort: 443
ToPort: 443
Description: Allow outbound 443 traffic to download packages
- CidrIp: 0.0.0.0/0
IpProtocol: tcp
FromPort: 80
ToPort: 80
Description: Allow outbound 80 traffic to download packages
- CidrIp: 10.0.0.0/16
IpProtocol: tcp
FromPort: 22
ToPort: 22
Description: Allow outbound 22 traffic to Login Nodes
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - SecurityGroup'
PortalHeadNodeAccountingIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 6817
ToPort: 6820
Description: Allows inbound from Head Nodes for Slurm Accounting
GroupId: !GetAtt PortalSecurityGroup.GroupId
SourceSecurityGroupId: !GetAtt HeadNodeSecurityGroup.GroupId
PortalHeadNodeAccountingEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 6817
ToPort: 6820
Description: Allows outbound to Head Nodes for Slurm Accounting
GroupId: !GetAtt PortalSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt HeadNodeSecurityGroup.GroupId
PortalHeadNodeEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 389
ToPort: 389
Description: Allows outbound from portal to LDAP in VPC CIDR
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalHeadNodeLDAPUDPEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: udp
FromPort: 389
ToPort: 389
Description: Allows outbound from portal to LDAP
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalHeadNodeLDAPDNSEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 53
ToPort: 53
Description: Allows outbound from portal to LDAP
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalHeadNodeLDAP464Egress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 464
ToPort: 464
Description: Allows outbound from portal to LDAP
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalHeadNodeLDAPDNSUDPEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: udp
FromPort: 53
ToPort: 53
Description: Allows outbound from portal to LDAP
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalHeadNodeLDAPPingUDPEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: udp
FromPort: 88
ToPort: 88
Description: Allows outbound from portal to LDAP
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalHeadNodeLDAPKerberosTCPEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 88
ToPort: 88
Description: Allows outbound from portal to LDAP
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalHeadNodeSSHEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 22
ToPort: 22
Description: Allows outbound to Head Nodes for SSH
GroupId: !GetAtt PortalSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt HeadNodeSecurityGroup.GroupId
PortalHeadNodeLoginNodeNLBEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 22
ToPort: 22
Description: Allows outbound from portal to NLB for Login Nodes
GroupId: !GetAtt PortalSecurityGroup.GroupId
CidrIp: 10.0.0.0/16
PortalComputeNodeEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 0
ToPort: 65535
Description: Outbound to Compute Nodes for Interactive Apps
GroupId: !GetAtt PortalSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt ComputeNodeSecurityGroup.GroupId
HeadNodeSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security Group for PCluster HeadNode
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref PortalSecurityGroup
FromPort: 6819
ToPort: 6819
IpProtocol: tcp
Description: Slurm Accounting
- SourceSecurityGroupId: !Ref PortalSecurityGroup
FromPort: 6820
ToPort: 6820
IpProtocol: tcp
Description: Slurm Accounting
SecurityGroupEgress:
- Description: Remove default rule for egress
CidrIp: 127.0.0.1/32
IpProtocol: "-1"
VpcId: !Ref VPC
ComputeNodeSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security Group for PCluster ComputeNode
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref PortalSecurityGroup
FromPort: 0
ToPort: 65535
IpProtocol: tcp
Description: Portal rule for for Interactive Apps
SecurityGroupEgress:
- Description: Remove default rule for egress
CidrIp: 127.0.0.1/32
IpProtocol: "-1"
VpcId: !Ref VPC
OpenOnDemandSecrets:
Type: AWS::SecretsManager::Secret
Properties:
Description: !Sub Secrets for Open On Demand Stack ${AWS::StackName}
SecretString: !Join
- ''
- - '{'
- !Sub '"TopLevelDomain": "${TopLevelDomain}",'
- !Sub '"ClusterConfigBucket": "${ClusterConfigBucket}",'
- !Sub '"DomainName": "${DomainName}"'
- '}'
OODInstanceManagedPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: secretsmanager:GetSecretValue
Resource:
- !Ref ADAdministratorSecret
- !Ref OpenOnDemandSecrets
- !Ref AuroraMasterSecret
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
- secretsmanager:PutSecretValue
Resource:
- !Ref MungeKeySecret
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:ListBucket
- s3:DeleteObject
Resource:
- !GetAtt ClusterConfigBucket.Arn
- !Sub ${ClusterConfigBucket.Arn}/*
- Effect: Allow
Action:
- elasticfilesystem:ClientMount
- elasticfilesystem:ClientWrite
- elasticfilesystem:ClientRootAccess
Resource:
- !GetAtt SharedFileSystem.Arn
- Effect: Allow
Action:
- logs:DescribeLogGroups
- logs:DescribeLogStreams
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:*
- Effect: Allow
Action:
- ec2:DescribeTags
Resource: "*"
- Effect: Allow
Action:
- cloudformation:DescribeStacks
Resource: !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/*
OODInstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore
- !Ref OODInstanceManagedPolicy
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - OpenOnDemand IAM Role'
OpenOnDemandInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref OODInstanceRole
ALB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Scheme: internet-facing
SecurityGroups:
- !Ref ALBSecurityGroup
Subnets: !Ref PublicSubnets
Type: application
LoadBalancerAttributes:
- Key: access_logs.s3.enabled
Value: true
- Key: access_logs.s3.bucket
Value: !Ref LoadBalancerLogBucket
- Key: access_logs.s3.prefix
Value: portal-alb
- Key: idle_timeout.timeout_seconds # Required to address issue with OOD SSH timeout
Value: 600
AuroraDBCluster:
Type: AWS::RDS::DBCluster
DeletionPolicy: Snapshot
UpdateReplacePolicy: Snapshot
Properties:
BacktrackWindow: 86400 # Sets backtrack to 24 hours
BackupRetentionPeriod: 7 # Ensures daily snapshots are taken
Engine: aurora-mysql
EngineMode: global
DatabaseName: slurmaccounting
MasterUsername: !Sub '{{resolve:secretsmanager:${AuroraMasterSecret}:SecretString:username}}'
MasterUserPassword: !Sub '{{resolve:secretsmanager:${AuroraMasterSecret}:SecretString:password}}'
DBSubnetGroupName: !Ref DBSubnetGroup
VpcSecurityGroupIds:
- !Ref DatabaseSecurityGroup
StorageEncrypted: true
AuroraDBPrimaryInstance:
Type: AWS::RDS::DBInstance
Properties:
DBInstanceClass: db.t3.medium
DBClusterIdentifier: !Ref AuroraDBCluster
Engine: aurora-mysql
AutoMinorVersionUpgrade: true
DBSubnetGroupName: !Ref DBSubnetGroup
PubliclyAccessible: false
# Add a new secrets manager entry
MungeKeySecret:
Type: AWS::SecretsManager::Secret
Properties:
Description: Munge Key for Open OnDemand
Name: !Sub [ "MungeKey-${StackIdSuffix}", { StackIdSuffix: !Select [ 1, !Split [ '/', !Ref 'AWS::StackId' ] ] } ]
OpenOnDemandLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Metadata:
AWS::CloudFormation::Init:
configSets:
config:
- initsetup
- config
- setupInfrastructure
- slurm
- ood
initsetup:
commands:
initsetupcmd:
command: |
dnf update -y -q
#sed -i "/#\$nrconf{restart} = 'i';/s/.*/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf
touch /var/log/install.txt
config:
packages:
yum:
jq: []
realmd: []
sssd: []
amazon-cloudwatch-agent: []
commands:
initial_setup:
command: |
groupadd spack-users -g 4000
configure_cert:
command: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts/configure_instance_cert.sh
sources:
/etc/ood-install: !Sub https://github.com/aws-samples/open-on-demand-on-aws/archive/refs/heads/${Branch}.zip
files: # Creates a file with appropriate variables for use in scripts. No secrets in here
/etc/ood-install/set_variables.sh:
content: !Sub |
export AD_SECRET_ID=${OpenOnDemandSecrets}
export AD_PASSWORD=${ADAdministratorSecret}
export AWS_REGION=${AWS::Region}
export DOMAIN_NAME=${DomainName}
export TOP_LEVEL_DOMAIN=${TopLevelDomain}
export RDS_SECRET_ID=${AuroraMasterSecret}
export ALB_DNS_NAME=${ALB.DNSName}
export WEBSITE_DOMAIN=${WebsiteDomainName}
export LDAP_NLB=${LDAPNLBEndPoint}
export EFS_ID=${SharedFileSystem}
export CLUSTER_CONFIG_BUCKET=${ClusterConfigBucket}
export SLURM_VERSION=${SlurmVersion}
export MUNGEKEY_SECRET_ID=${MungeKeySecret}
mode: "000744"
owner: "root"
group: "root"
users:
slurm:
uid: 401
munge:
uid: 402
setupInfrastructure:
commands:
1_configure_cloudwatch:
command: ./configure_cloudwatch_metrics.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
2_mount_efs:
command: |
. /etc/ood-install/set_variables.sh
./mount_efs.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
3_configure_mkhomedir:
command: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts/configure_mkhomedir.sh
4_upload_pcluster_configs:
command: |
. /etc/ood-install/set_variables.sh
./upload_pcluster_configs.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
slurm:
commands:
1_install_munge:
command: |
. /etc/ood-install/set_variables.sh
./install_munge.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
2_install_slurm:
command: |
. /etc/ood-install/set_variables.sh
./install_slurm.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
3_configure_slurm_accounting:
command: |
. /etc/ood-install/set_variables.sh
./configure_slurm_accounting.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
spack:
commands:
install_spack:
command: ./install_spack.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
ood:
commands:
ood_install:
command: !Sub |
. /etc/ood-install/set_variables.sh
./install_ood.sh
aws s3 sync s3://${ClusterConfigBucket}/clusters /etc/ood/config/clusters.d/ --exact-timestamps
./configure_cluster_for_ood.sh
cwd: !Sub /etc/ood-install/open-on-demand-on-aws-${Branch}/scripts
Properties:
LaunchTemplateName: !Sub ${AWS::StackName}-launch-template-cfn-init
LaunchTemplateData:
ImageId: '{{resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64:75}}'
# ImageId: 'ami-04e5276ebb8451442'
InstanceType: m6i.large
IamInstanceProfile:
Name: !Ref OpenOnDemandInstanceProfile
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
DeleteOnTermination: true
Encrypted: true
VolumeSize: 60
VolumeType: gp3
SecurityGroupIds:
- !Ref PortalSecurityGroup
Monitoring:
Enabled: true
UserData:
Fn::Base64: !Sub |
#!/bin/bash
cd /opt
curl -O https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
tar -xvpf aws-cfn-bootstrap-py3-latest.tar.gz
cd aws-cfn-bootstrap-2.0
python3 setup.py build
python3 setup.py install
cd /opt
mkdir aws
cd aws
mkdir bin
INSTALL_PATH=/usr/local/bin
ln -s $INSTALL_PATH/cfn-hup /opt/aws/bin/cfn-hup
ln -s $INSTALL_PATH/cfn-init /opt/aws/bin/cfn-init
ln -s $INSTALL_PATH/cfn-signal /opt/aws/bin/cfn-signal
ln -s $INSTALL_PATH/cfn-elect-cmd-leader /opt/aws/bin/cfn-elect-cmd-leader
ln -s $INSTALL_PATH/cfn-get-metadata /opt/aws/bin/cfn-get-metadata
ln -s $INSTALL_PATH/cfn-send-cmd-event /opt/aws/bin/cfn-send-cmd-event
ln -s $INSTALL_PATH/cfn-send-cmd-result /opt/aws/bin/cfn-send-cmd-result
# Call cfn-init script to install files and packages
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource OpenOnDemandLaunchTemplate --region ${AWS::Region} --configset config
OODServerASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MinSize: "1"
MaxSize: "1"
DesiredCapacity: "1"
HealthCheckGracePeriod: 240
MetricsCollection:
- Granularity: 1Minute
LaunchTemplate:
LaunchTemplateId: !Ref OpenOnDemandLaunchTemplate
Version: !GetAtt OpenOnDemandLaunchTemplate.LatestVersionNumber
VPCZoneIdentifier: !Ref PrivateSubnets
TargetGroupARNs:
- !Ref OpenOnDemandTargetGroupHTTPS
Tags:
- Key: Name
Value: !Sub OpenOnDemand Portal - ${AWS::StackName}-cfn-init
PropagateAtLaunch: true
- Key: ood
Value: !Sub webportal-${AWS::StackName}
PropagateAtLaunch: true
UpdatePolicy:
AutoScalingRollingUpdate: {}
ComputeNodeMountTargetEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 2049
ToPort: 2049
Description: Allows outbound to EFS mount target
GroupId: !GetAtt ComputeNodeSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt MountTargetSecurityGroup.GroupId
HeadNodeMountTargetEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 2049
ToPort: 2049
Description: Allows outbound to EFS mount target
GroupId: !GetAtt HeadNodeSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt MountTargetSecurityGroup.GroupId
PortalMountTargetEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 2049
ToPort: 2049
Description: Allows outbound to EFS mount target
GroupId: !GetAtt PortalSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt MountTargetSecurityGroup.GroupId
MountTargetSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId:
Ref: VPC
GroupDescription: Security group for mount target
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
SourceSecurityGroupId: !GetAtt PortalSecurityGroup.GroupId
Description: Ingress Rule for OOD Portal
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
SourceSecurityGroupId: !GetAtt HeadNodeSecurityGroup.GroupId
Description: Ingress Rule for HeadNode
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
SourceSecurityGroupId: !GetAtt ComputeNodeSecurityGroup.GroupId
Description: Ingress Rule for ComputeNode
SecurityGroupEgress:
- Description: Remove default rule for egress
CidrIp: 127.0.0.1/32
IpProtocol: "-1"
SharedFileSystem:
Type: AWS::EFS::FileSystem
Properties:
Encrypted: true
PerformanceMode: generalPurpose
MountTargetResource1:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref SharedFileSystem
SubnetId: !Select [0, !Ref PrivateSubnets]
SecurityGroups:
- !Ref MountTargetSecurityGroup
MountTargetResource2:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref SharedFileSystem
SubnetId: !Select [1, !Ref PrivateSubnets]
SecurityGroups:
- !Ref MountTargetSecurityGroup
OpenOnDemandTargetGroupHTTPS:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 6
HealthCheckTimeoutSeconds: 5
TargetType: instance
Protocol: HTTPS
Port: 443
VpcId: !Ref VPC
Matcher:
HttpCode: 301
OpenOnDemandListenerHTTPS:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref OpenOnDemandTargetGroupHTTPS
LoadBalancerArn: !Ref ALB
Certificates:
- CertificateArn: !Ref OODCertificate
Port: 443
Protocol: "HTTPS"
SslPolicy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
ClusterConfigBucket:
Type: AWS::S3::Bucket
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- BucketKeyEnabled: true
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
NotificationConfiguration:
EventBridgeConfiguration:
EventBridgeEnabled: true
ClusterConfigBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref ClusterConfigBucket
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: ForceSSLRequests
Action:
- 's3:*'
Effect: Deny
Resource:
- !Sub arn:${AWS::Partition}:s3:::${ClusterConfigBucket}
- !Sub arn:${AWS::Partition}:s3:::${ClusterConfigBucket}/*
Principal: '*'
Condition:
Bool:
'aws:SecureTransport': "false"
EventBridgeRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- events.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- !Ref EventBridgeManagedPolicy
EventBridgeManagedPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow # Allows execution of RunShellScript doc
Action:
- ssm:SendCommand
Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}::document/AWS-RunShellScript
ClusterConfigUpload:
Type: AWS::Events::Rule
Properties:
Description: Copy config files to OOD instance when an object is uploaded
State: "ENABLED"
EventPattern:
source:
- "aws.s3"
detail-type:
- "Object Created"
detail:
bucket:
name:
- !Ref ClusterConfigBucket
object:
key:
- wildcard: "clusters/*"
Targets:
- Id: RunShell
Arn: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}::document/AWS-RunShellScript
RoleArn: !GetAtt EventBridgeRole.Arn
Input: !Sub |
{
"commands": [
"aws s3 sync s3://${ClusterConfigBucket}/clusters /etc/ood/config/clusters.d/ --exact-timestamps",
"/etc/ood-install/open-on-demand-on-aws-${Branch}/scripts/configure_cluster_for_ood.sh"
]
}
RunCommandParameters:
RunCommandTargets:
- Key: tag:ood
Values:
- !Sub webportal-${AWS::StackName}
PClusterCloudformationDeleted:
Type: AWS::Events::Rule
Properties:
Description: Remove config files from OOD instance when pcluster removes a stack
State: "ENABLED"
EventPattern:
detail:
eventName:
- "DeleteStack"
eventSource:
- "cloudformation.amazonaws.com"
Targets:
- Id: RunShell
Arn: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}::document/AWS-RunShellScript
RoleArn: !GetAtt EventBridgeRole.Arn
InputTransformer:
InputPathsMap:
stackName: $.detail.requestParameters.stackName
InputTemplate: !Sub |
{
"commands": [
"stackName=<stackName>",
"if [[ $stackName == *:cloudformation:* ]]; then",
" IFS='/ ' read -r -a array <<< $stackName",
" stackName=${!array[1]}",
"fi",
"tags=$(aws cloudformation describe-stacks --stack-name $stackName --region ${AWS::Region} --query \"Stacks[0].Tags[?Key=='parallelcluster:version']\" --output text)",
"if [ ! -z \"$tags\" ]; then",
" aws s3 rm s3://${ClusterConfigBucket}/clusters/$stackName.yml",
" rm /etc/ood/config/clusters.d/$stackName.yml",
" rm /etc/ood/config/apps/bc_desktop/$stackName.yml",
" rm /etc/ssh/ssh_config.d/ood_$stackName.conf",
" sacctmgr remove cluster $stackName -i",
"fi"
]
}
RunCommandParameters:
RunCommandTargets:
- Key: tag:ood
Values:
- !Sub webportal-${AWS::StackName}
DNSRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: !Ref HostedZoneName
Name: !Ref WebsiteDomainName
AliasTarget:
DNSName: !GetAtt ALB.DNSName
HostedZoneId: !GetAtt ALB.CanonicalHostedZoneID
Type: A
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: DB Subnet Group
SubnetIds: !Ref PrivateSubnets
AuroraMasterSecret:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Sub ${AWS::StackName}-rds-slurm-accounting-secret
GenerateSecretString:
SecretStringTemplate: !Join ['', ['{"username": "admin"}']]
GenerateStringKey: "password"
ExcludeCharacters: '"@/\#'
PasswordLength: 16
SecretRDSInstanceAttachment:
Type: AWS::SecretsManager::SecretTargetAttachment
Properties:
SecretId: !Ref AuroraMasterSecret
TargetId: !Ref AuroraDBCluster
TargetType: AWS::RDS::DBCluster
DatabaseSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for DB
VpcId: !Ref VPC
SecurityGroupEgress:
- Description: Remove default rule for egress
CidrIp: 127.0.0.1/32
IpProtocol: "-1"
DatabaseSecurityGroupIngressOOD:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
GroupId: !Ref DatabaseSecurityGroup
SourceSecurityGroupId: !Ref PortalSecurityGroup
FromPort: 3306
ToPort: 3306
Description: Allow database ingress from OOD instance
DatabaseSecurityGroupIngressHeadNode:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
GroupId: !Ref DatabaseSecurityGroup
SourceSecurityGroupId: !Ref HeadNodeSecurityGroup
FromPort: 3306
ToPort: 3306
Description: Allow database ingress from ParallelCluster HeadNode instance
HeadNodeDBEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 3306
ToPort: 3306
Description: Allows outbound to DB
GroupId: !GetAtt HeadNodeSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt DatabaseSecurityGroup.GroupId
PortalDBEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 3306
ToPort: 3306
Description: Allows outbound to DB
GroupId: !GetAtt PortalSecurityGroup.GroupId
DestinationSecurityGroupId: !GetAtt DatabaseSecurityGroup.GroupId
HeadNodeParallelClusterIAMPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement: