forked from acantril/learn-cantrill-labs-1clickrepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADVS2SVPN-ONPREM.yaml
387 lines (387 loc) · 11.8 KB
/
ADVS2SVPN-ONPREM.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
Description: Advanced Demo - Highly-Available Dynamic Accelerated Site-to-Site VPN - MUST be applied in us-east-1 // ONPREMISES SIMULATED ENVIRONMENT
Parameters:
LatestAmiId:
Description: AMI for Bastion Host (default is latest AmaLinux2)
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 192.168.8.0/21
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: ONPREM
InternetGateway:
Type: 'AWS::EC2::InternetGateway'
Properties:
Tags:
- Key: Name
Value: IGW-ONPREM
InternetGatewayAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
Pub:
Type: AWS::EC2::Subnet
Properties:
MapPublicIpOnLaunch: true
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: 192.168.12.0/24
Tags:
- Key: Name
Value: ONPREM-PUBLIC
Priv1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: 192.168.10.0/24
Tags:
- Key: Name
Value: ONPREM-PRIVATE-1
Priv2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: 192.168.11.0/24
Tags:
- Key: Name
Value: ONPREM-PRIVATE-2
PrivateRT1:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: ONPREM-PRIVATE-RT1
PrivateRT2:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: ONPREM-PRIVATE-RT2
PublicRT:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: ONPREM-PUBLIC-RT
RouteDefaultIPV4Pub:
Type: 'AWS::EC2::Route'
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId:
Ref: PublicRT
DestinationCidrBlock: '0.0.0.0/0'
GatewayId:
Ref: InternetGateway
Route1AWSIPv4:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId:
Ref: PrivateRT1
DestinationCidrBlock: '10.16.0.0/16'
NetworkInterfaceId: !Ref ENIR1PRIVATE
Route2AWSIPv4:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId:
Ref: PrivateRT2
DestinationCidrBlock: '10.16.0.0/16'
NetworkInterfaceId: !Ref ENIR2PRIVATE
RTOnPremPriv1:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref Priv1
RouteTableId:
Ref: PrivateRT1
RTOnPremPriv2:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref Priv2
RouteTableId:
Ref: PrivateRT2
RTOnPremPub:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref Pub
RouteTableId:
Ref: PublicRT
Router1:
Type: AWS::EC2::Instance
DependsOn:
- ssmVPCe
- ssmec2messagesVPCe
- ssmmessagesVPCe
Properties:
InstanceType: "t3.small"
ImageId: "ami-0ac80df6eff0e70b5"
SubnetId: !Ref Pub
SecurityGroupIds:
- !Ref InstanceSG
IamInstanceProfile: !Ref EC2InstanceProfile
SourceDestCheck: "false"
Tags:
- Key: Name
Value: ONPREM-ROUTER1
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
apt-get update && apt-get install -y strongswan wget
mkdir /home/ubuntu/demo_assets
cd /home/ubuntu/demo_assets
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter1/ipsec-vti.sh
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter1/ipsec.conf
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter1/ipsec.secrets
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter1/51-eth1.yaml
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter1/ffrouting-install.sh
chown ubuntu:ubuntu /home/ubuntu/demo_assets -R
cp /home/ubuntu/demo_assets/51-eth1.yaml /etc/netplan
netplan --debug apply
ENIR1PRIVATE:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref Priv1
Description: Router1 PRIVATE INTERFACE
GroupSet:
- !Ref InstanceSG
SourceDestCheck: false
Tags:
-
Key: Name
Value: ONPREM-R1-PRIVATE
ENIAttachmentRouter11:
Type: AWS::EC2::NetworkInterfaceAttachment
Properties:
InstanceId:
Ref: Router1
NetworkInterfaceId:
Ref: ENIR1PRIVATE
DeviceIndex: 1
Router2:
Type: AWS::EC2::Instance
DependsOn:
- ssmVPCe
- ssmec2messagesVPCe
- ssmmessagesVPCe
Properties:
InstanceType: "t3.small"
ImageId: "ami-0ac80df6eff0e70b5"
SubnetId: !Ref Pub
SecurityGroupIds:
- !Ref InstanceSG
IamInstanceProfile: !Ref EC2InstanceProfile
SourceDestCheck: "false"
Tags:
- Key: Name
Value: ONPREM-ROUTER2
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
apt-get update && apt-get install -y strongswan wget
mkdir /home/ubuntu/demo_assets
cd /home/ubuntu/demo_assets
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter2/ipsec-vti.sh
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter2/ipsec.conf
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter2/ipsec.secrets
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter2/51-eth1.yaml
wget https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/AWS_HYBRID_AdvancedVPN/OnPremRouter2/ffrouting-install.sh
chown ubuntu:ubuntu /home/ubuntu/demo_assets -R
cp /home/ubuntu/demo_assets/51-eth1.yaml /etc/netplan
netplan --debug apply
ENIR2PRIVATE:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref Priv2
Description: Router2 PRIVATE INTERFACE
GroupSet:
- !Ref InstanceSG
SourceDestCheck: false
Tags:
-
Key: Name
Value: ONPREM-R2-PRIVATE
ENIAttachmentRouter21:
Type: AWS::EC2::NetworkInterfaceAttachment
Properties:
InstanceId:
Ref: Router2
NetworkInterfaceId:
Ref: ENIR2PRIVATE
DeviceIndex: 1
ONPREMSERVER1:
Type: AWS::EC2::Instance
DependsOn:
- ssmVPCe
- ssmec2messagesVPCe
- ssmmessagesVPCe
Properties:
InstanceType: "t2.micro"
ImageId: !Ref LatestAmiId
IamInstanceProfile: !Ref EC2InstanceProfile
SubnetId: !Ref Priv1
SecurityGroupIds:
- !Ref InstanceSG
Tags:
- Key: Name
Value: ONPREM-SERVER1
ONPREMSERVER2:
Type: AWS::EC2::Instance
DependsOn:
- ssmVPCe
- ssmec2messagesVPCe
- ssmmessagesVPCe
Properties:
InstanceType: "t2.micro"
ImageId: !Ref LatestAmiId
IamInstanceProfile: !Ref EC2InstanceProfile
SubnetId: !Ref Priv2
SecurityGroupIds:
- !Ref InstanceSG
Tags:
- Key: Name
Value: ONPREM-SERVER2
EC2Role:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: root
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'ssm:DescribeAssociation'
- 'ssm:GetDeployablePatchSnapshotForInstance'
- 'ssm:GetDocument'
- 'ssm:DescribeDocument'
- 'ssm:GetManifest'
- 'ssm:GetParameter'
- 'ssm:GetParameters'
- 'ssm:ListAssociations'
- 'ssm:ListInstanceAssociations'
- 'ssm:PutInventory'
- 'ssm:PutComplianceItems'
- 'ssm:PutConfigurePackageResult'
- 'ssm:UpdateAssociationStatus'
- 'ssm:UpdateInstanceAssociationStatus'
- 'ssm:UpdateInstanceInformation'
Resource: '*'
- Effect: Allow
Action:
- 'ssmmessages:CreateControlChannel'
- 'ssmmessages:CreateDataChannel'
- 'ssmmessages:OpenControlChannel'
- 'ssmmessages:OpenDataChannel'
Resource: '*'
- Effect: Allow
Action:
- 'ec2messages:AcknowledgeMessage'
- 'ec2messages:DeleteMessage'
- 'ec2messages:FailMessage'
- 'ec2messages:GetEndpoint'
- 'ec2messages:GetMessages'
- 'ec2messages:SendReply'
Resource: '*'
- Effect: Allow
Action:
- 's3:*'
Resource: '*'
- Effect: Allow
Action:
- 'sns:*'
Resource: '*'
EC2InstanceProfile:
Type: 'AWS::IAM::InstanceProfile'
Properties:
Path: /
Roles:
- !Ref EC2Role
InstanceSG:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref VPC
GroupDescription: Default ONPREM SG
SecurityGroupIngress:
- Description: 'Allow All from AWS Environment'
IpProtocol: '-1'
CidrIp: '10.16.0.0/16'
InstanceSGSelfReferenceRule:
Type: "AWS::EC2::SecurityGroupIngress"
Properties:
GroupId: !Ref InstanceSG
IpProtocol: '-1'
SourceSecurityGroupId: !Ref InstanceSG
ssmVPCe:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcEndpointType: "Interface"
PrivateDnsEnabled: "True"
SubnetIds:
- !Ref Pub
SecurityGroupIds:
- !Ref InstanceSG
ServiceName: !Sub com.amazonaws.${AWS::Region}.ssm
VpcId: !Ref VPC
ssmec2messagesVPCe:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcEndpointType: "Interface"
PrivateDnsEnabled: "True"
SubnetIds:
- !Ref Pub
SecurityGroupIds:
- !Ref InstanceSG
ServiceName: !Sub com.amazonaws.${AWS::Region}.ec2messages
VpcId: !Ref VPC
ssmmessagesVPCe:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcEndpointType: "Interface"
PrivateDnsEnabled: "True"
SubnetIds:
- !Ref Pub
SecurityGroupIds:
- !Ref InstanceSG
ServiceName: !Sub com.amazonaws.${AWS::Region}.ssmmessages
VpcId: !Ref VPC
s3VPCe:
Type: AWS::EC2::VPCEndpoint
Properties:
RouteTableIds:
- !Ref PublicRT
- !Ref PrivateRT1
- !Ref PrivateRT2
ServiceName: !Sub com.amazonaws.${AWS::Region}.s3
VpcId: !Ref VPC
Outputs:
Router1Public:
Description: Public IP of Router1
Value: !GetAtt Router1.PublicIp
Router2Public:
Description: Public IP of Router2
Value: !GetAtt Router2.PublicIp
Router1Private:
Description: Private IP of Router1
Value: !GetAtt Router1.PrivateIp
Router2Private:
Description: Private IP of Router2
Value: !GetAtt Router2.PrivateIp