-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinfra.yml
519 lines (483 loc) · 15.4 KB
/
infra.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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
---
AWSTemplateFormatVersion: 2010-09-09
Description: |-
Infrastructure required for the deployment of Open OnDemand on AWS including:
- VPC
- Private and Public subnets
- NAT Gateway
- Active Directory
- S3 Gateway
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Active Directory
Parameters:
- DomainName
- TopLevelDomain
- Label:
default: Networking
Parameters:
- VPCCidrBlock
- PublicSubnet1CidrBlock
- PublicSubnet2CidrBlock
- PrivateSubnet1CidrBlock
- PrivateSubnet2CidrBlock
ParameterLabels:
DomainName:
default: Domain Name
TopLevelDomain:
default: Top level domain
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]+'
VPCCidrBlock:
Description: CIDR block for the VPC
Type: String
Default: 10.0.0.0/16
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
PublicSubnet1CidrBlock:
Description: CIDR block for the public subnet located in Availability Zone 1
Type: String
Default: 10.0.0.0/26
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
PublicSubnet2CidrBlock:
Description: CIDR block for the public subnet located in Availability Zone 2
Type: String
Default: 10.0.0.128/26
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
PrivateSubnet1CidrBlock:
Description: CIDR block for the private subnet located in Availability Zone 1
Type: String
Default: 10.0.2.0/24
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
PrivateSubnet2CidrBlock:
Description: CIDR block for the private subnet located in Availability Zone 2
Type: String
Default: 10.0.3.0/24
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
# List of region specific elb account id - https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-access-logging.html
Mappings:
RegionMap:
us-east-1:
ALBLogAccount: 127311923021
us-east-2:
ALBLogAccount: 033677994240
us-west-1:
ALBLogAccount: 027434742980
us-west-2:
ALBLogAccount: 797873946194
ap-northeast-1:
ALBLogAccount: 582318560864
ap-northeast-2:
ALBLogAccount: 600734575887
ap-south-1:
ALBLogAccount: 718504428378
ap-southeast-1:
ALBLogAccount: 114774131450
ap-southeast-2:
ALBLogAccount: 783225319266
ca-central-1:
ALBLogAccount: 985666609251
eu-central-1:
ALBLogAccount: 054676820928
eu-north-1:
ALBLogAccount: 027434742980
eu-west-1:
ALBLogAccount: 156460612806
eu-west-2:
ALBLogAccount: 652711504416
eu-west-3:
ALBLogAccount: 009996457667
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VPCCidrBlock
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - VPC'
FlowLogLogGroup:
Type: AWS::Logs::LogGroup
Properties: {}
FlowLogDeliveryRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: 'vpc-flow-logs.amazonaws.com'
Action: 'sts:AssumeRole'
Policies:
- PolicyName: flowlog-policy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
- logs:DescribeLogGroups
- logs:DescribeLogStreams
Resource: !GetAtt FlowLogLogGroup.Arn
VPCFlowLogs:
Type: AWS::EC2::FlowLog
Properties:
ResourceId: !Ref VPC
ResourceType: VPC
TrafficType: ALL
DeliverLogsPermissionArn: !GetAtt FlowLogDeliveryRole.Arn
LogGroupName: !Ref FlowLogLogGroup
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - InternetGateway'
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
NATGW1:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt EIP1.AllocationId
SubnetId: !Ref PublicSubnet1
EIP1:
DependsOn: AttachGateway
Type: AWS::EC2::EIP
Properties:
Domain: vpc
NATGW2:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt EIP2.AllocationId
SubnetId: !Ref PublicSubnet2
EIP2:
DependsOn: AttachGateway
Type: AWS::EC2::EIP
Properties:
Domain: vpc
PublicRouteTable1:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - PublicRouteTable1'
DefaultPublicRoute1:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref PublicRouteTable1
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicRouteTable2:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - PublicRouteTable2'
DefaultPublicRoute2:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref PublicRouteTable2
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref 'AWS::Region'
CidrBlock: !Ref PublicSubnet1CidrBlock
VpcId: !Ref VPC
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} - Public Subnet1
PublicSubnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select
- 1
- Fn::GetAZs: !Ref 'AWS::Region'
CidrBlock: !Ref PublicSubnet2CidrBlock
VpcId: !Ref VPC
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - Public Subnet2'
PrivateSubnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref 'AWS::Region'
CidrBlock: !Ref PrivateSubnet1CidrBlock
VpcId: !Ref VPC
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - Private Subnet1'
PrivateRouteTable1:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - PrivateRouteTable1'
DefaultPrivateRoute1:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable1
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NATGW1
PrivateSubnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select
- 1
- Fn::GetAZs: !Ref 'AWS::Region'
CidrBlock: !Ref PrivateSubnet2CidrBlock
VpcId: !Ref VPC
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - Private Subnet2'
PrivateRouteTable2:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${AWS::StackName} - PrivateRouteTable2'
DefaultPrivateRoute2:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable2
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NATGW2
PublicSubnetRouteTableAssociation1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable1
SubnetId: !Ref PublicSubnet1
PublicSubnetRouteTableAssociation2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable2
SubnetId: !Ref PublicSubnet2
PrivateSubnetRouteTableAssociation1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable1
SubnetId: !Ref PrivateSubnet1
PrivateSubnetRouteTableAssociation2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable2
SubnetId: !Ref PrivateSubnet2
S3Endpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
RouteTableIds:
- !Ref PublicRouteTable1
- !Ref PublicRouteTable2
- !Ref PrivateRouteTable1
- !Ref PrivateRouteTable2
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3'
VpcId: !Ref VPC
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow # Allows access to buckets owned by current account
Principal: "*"
Action: "s3:*"
Resource: "*"
Condition:
StringEquals:
"s3:ResourceAccount": !Ref "AWS::AccountId"
- Effect: Allow # Allows access to buckets that contains various components of the solution
Principal: "*"
Action: "s3:*"
Resource:
- !Sub arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::cloudformation-examples/*
- !Sub arn:${AWS::Partition}:s3:::amazoncloudwatch-agent/*
- !Sub arn:${AWS::Partition}:s3:::amazonlinux-2-repos-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-aws-parallelcluster/*
- !Sub arn:${AWS::Partition}:s3:::dcv-license.${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::cloudformation-waitcondition-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::al2023-repos-${AWS::Region}-de612dc2/*
- Effect: Allow # Allows access to buckets required for systems manager
Principal: "*"
Action: "s3:GetObject"
Resource:
- !Sub arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/*
- !Sub arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::aws-patchmanager-macos-${AWS::Region}/*
- !Sub arn:${AWS::Partition}:s3:::al2023-repos-${AWS::Region}-de612dc2/*
ADAdministratorSecret:
Type: AWS::SecretsManager::Secret
Properties:
Description: !Sub AD Secrets for Open On Demand Stack ${AWS::StackName}
GenerateSecretString:
PasswordLength: 12
ExcludeCharacters: '"@/\''$`,;!%<>#&'
ActiveDirectory:
Type: AWS::DirectoryService::MicrosoftAD
Properties:
Edition: Standard
Name: !Sub ${DomainName}.${TopLevelDomain}
Password: !Sub '{{resolve:secretsmanager:${ADAdministratorSecret}:SecretString}}'
VpcSettings:
SubnetIds:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
VpcId: !Ref VPC
LoadBalancerLogBucket:
Type: AWS::S3::Bucket
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- BucketKeyEnabled: true
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
LoadBalancerLogBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref LoadBalancerLogBucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: "AWSLogDeliveryWriteNLB"
Effect: Allow
Principal:
Service: 'delivery.logs.amazonaws.com'
Action: "s3:PutObject"
Resource: !Sub arn:${AWS::Partition}:s3:::${LoadBalancerLogBucket}/*
Condition:
StringEquals:
's3:x-amz-acl': 'bucket-owner-full-control'
- Sid: "AWSLogDeliveryAclCheck"
Effect: Allow
Principal:
Service: 'delivery.logs.amazonaws.com'
Action: "s3:GetBucketAcl"
Resource: !Sub arn:${AWS::Partition}:s3:::${LoadBalancerLogBucket}
- Sid: "AWSLogDeliveryWriteALB"
Effect: Allow
Principal:
AWS: !Sub
- arn:aws:iam::${LogAccount}:root
- LogAccount: !FindInMap [RegionMap, !Ref 'AWS::Region', ALBLogAccount]
Action: "s3:PutObject"
Resource: !Sub arn:${AWS::Partition}:s3:::${LoadBalancerLogBucket}/*
Condition:
StringEquals:
's3:x-amz-acl': 'bucket-owner-full-control'
- Sid: ForceSSLRequests
Action:
- 's3:*'
Effect: Deny
Resource:
- !Sub arn:${AWS::Partition}:s3:::${LoadBalancerLogBucket}
- !Sub arn:${AWS::Partition}:s3:::${LoadBalancerLogBucket}/*
Principal: '*'
Condition:
Bool:
'aws:SecureTransport': "false"
NLB:
DependsOn: LoadBalancerLogBucketPolicy
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
LoadBalancerAttributes:
- Key: access_logs.s3.enabled
Value: true
- Key: access_logs.s3.bucket
Value: !Ref LoadBalancerLogBucket
- Key: access_logs.s3.prefix
Value: ldap-nlb
Scheme: internal
Subnets:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
Type: network
LDAPlistener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref ADTargetGroup
LoadBalancerArn: !Ref NLB
Port: 389
Protocol: "TCP"
ADTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckEnabled: true
TargetType: ip
Protocol: TCP
Port: 389
VpcId: !Ref VPC
Targets:
- Id: !Select [0, !GetAtt ActiveDirectory.DnsIpAddresses]
- Id: !Select [1, !GetAtt ActiveDirectory.DnsIpAddresses]
Outputs:
VPCId:
Description: VPC ID
Value: !Ref VPC
PrivateSubnets:
Description: Private Subnet IDs
Value: !Join [",", [!Ref PrivateSubnet1, !Ref PrivateSubnet2]]
PublicSubnets:
Description: Private Subnet IDs
Value: !Join [",", [!Ref PublicSubnet1, !Ref PublicSubnet2]]
TopLevelDomain:
Description: Top Level Domain for AD
Value: !Ref TopLevelDomain
DomainName:
Description: DomainName for AD
Value: !Ref DomainName
DirectoryId:
Description: Directory ID
Value: !Ref ActiveDirectory
ADAdministratorSecretARN:
Description: AD Admin Secret ARN
Value: !Ref ADAdministratorSecret
LDAPNLBEndPoint:
Description: LDAP NLB End Point
Value: !Sub ${NLB.DNSName}
LoadBalancerLogBucket:
Description: Load Balancer Log Bucket
Value: !Ref LoadBalancerLogBucket