-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcloudformation.template
306 lines (303 loc) · 8.66 KB
/
cloudformation.template
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
AWSTemplateFormatVersion: 2010-09-09
Description: Launch openvpn access
Parameters:
VPCId:
Type: String
Description: vpc-id of the vpc where to deploy the vpn access server
SubnetId1:
Type: String
Description: first subnet-id of the vpc subnet where to deploy the vpn access server
SubnetId2:
Type: String
Description: second subnet-id of the vpc subnet where to deploy the vpn access server
AssignPublicIp:
Type: String
Description: "If the supplied subnets are in a public subnet, assign public IP to the container (otherwise there will be no outgoing network connectivity)?"
AllowedValues:
- ENABLED
- DISABLED
OAUTH2ClientId:
Type: String
Description: oauth2 client id
OAUTH2ClientSecret:
Type: String
Description: oauth2 client secret
ClientCertOrg:
Type: String
Description: client organization
CSRFKey:
Type: String
Description: "32 bytes long random key (for example: LUMY9Zd2QgHLrZXPkn790k4nrUoeXqwP)"
AuthType:
Type: String
Description: The authentication Type (github / oidc)
AllowedValues:
- github
- oidc
OIDCRedirectURL:
Type: String
Description: If auth type is OIDC, enter the OIDC autodiscovery url here
Resources:
ExecutionRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "ecs-tasks.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
-
PolicyName: "root"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- logs:CreateLogStream
- logs:PutLogEvents
- ssm:GetParameters
- ssm:GetParameter
Resource: "*"
TaskRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "ecs-tasks.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
OpenVPNAccessCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: openvpn-access
OpenVPNAccessTaskDef:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Essential: true
Image: in4it/openvpn-access:latest
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: openvpn-access
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: openvpn-access
Name: openvpn-access
PortMappings:
- ContainerPort: 8080
HostPort: 8080
Protocol: tcp
Environment:
- Name: OAUTH2_CLIENT_ID
Value: !Ref OAUTH2ClientId
- Name: OAUTH2_CLIENT_SECRET
Value: !Ref OAUTH2ClientSecret
- Name: OAUTH2_URL
Value: !Ref OIDCRedirectURL
- Name: OAUTH2_REDIRECT_URL
Value:
Fn::Join:
- ""
- - "http://"
- !GetAtt OpenVPNAccessLB.DNSName
- "/callback"
- Name: CSRF_KEY
Value: !Ref CSRFKey
- Name: CLIENT_CERT_ORG
Value: !Ref ClientCertOrg
- Name: S3_BUCKET
Value: !Ref OpenVPNAccessBucket
- Name: S3_PREFIX
Value: config
- Name: S3_KMS_ARN
Value: !GetAtt OpenVPNAccessKey.Arn
- Name: AWS_REGION
Value: !Ref AWS::Region
- Name: AUTH_TYPE
Value: !Ref AuthType
Cpu: 256
ExecutionRoleArn: !Ref ExecutionRole
Family: OpenVPNAccess
Memory: 1024
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
TaskRoleArn: !Ref TaskRole
OpenVPNAccessLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: openvpn-access
RetentionInDays: 30
OpenVPNAccessService:
Type: AWS::ECS::Service
Properties:
Cluster: !Ref OpenVPNAccessCluster
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 100
DesiredCount: 1
LaunchType: FARGATE
TaskDefinition: !Ref OpenVPNAccessTaskDef
ServiceName: openvpn-access
LoadBalancers:
- TargetGroupArn: !Ref OpenVPNAccessLBTargetGroup
ContainerPort: 8080
ContainerName: openvpn-access
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: !Ref AssignPublicIp
SecurityGroups:
- !Ref OpenVPNAccessSecurityGroup
Subnets:
- !Ref SubnetId1
- !Ref SubnetId2
OpenVPNAccessBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName:
Fn::Join:
- ""
- - 'openvpn-access-'
- !Ref AWS::Region
- '-'
- !Ref AWS::AccountId
S3AccessIAMManagedRolePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: "openvpn-access-s3-rw-access"
Roles:
- !Ref TaskRole
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "s3:Put*"
- "s3:Get*"
Resource:
Fn::Join:
- ""
- - !GetAtt OpenVPNAccessBucket.Arn
- "/*"
-
Effect: "Allow"
Action:
- "s3:ListBucket"
Resource: !GetAtt OpenVPNAccessBucket.Arn
KMSAccessIAMManagedRolePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: "openvpn-access-kms-access"
Roles:
- !Ref TaskRole
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "kms:Encrypt"
- "kms:Decrypt"
- "kms:ReEncrypt*"
- "kms:GenerateDataKey*"
- "kms:DescribeKey"
Resource: !GetAtt OpenVPNAccessKey.Arn
OpenVPNAccessKey:
Type: AWS::KMS::Key
Properties:
KeyPolicy:
Version: 2012-10-17
Id: key-default-1
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Join
- ''
- - 'arn:aws:iam::'
- !Ref 'AWS::AccountId'
- ':root'
Action: 'kms:*'
Resource: '*'
OpenVPNAccessLB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Name: openvpn-access
Scheme: internet-facing
SecurityGroups:
- !Ref OpenVPNAccessLBSecurityGroup
Subnets:
- !Ref SubnetId1
- !Ref SubnetId2
Type: application
OpenVPNAccessLBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: loadbalancer sg
VpcId: !Ref VPCId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: "-1"
FromPort: 0
ToPort: 0
CidrIp: 0.0.0.0/0
OpenVPNAccessSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http for proxy
VpcId: !Ref VPCId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
SourceSecurityGroupId: !Ref OpenVPNAccessLBSecurityGroup
SecurityGroupEgress:
- IpProtocol: "-1"
FromPort: 0
ToPort: 0
CidrIp: 0.0.0.0/0
OpenVPNAccessLBListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: "forward"
TargetGroupArn: !Ref OpenVPNAccessLBTargetGroup
LoadBalancerArn: !Ref OpenVPNAccessLB
Port: 80
Protocol: "HTTP"
OpenVPNAccessLBTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 30
HealthCheckPath: /
HealthCheckPort: 8080
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 2
Name: openvpn-access
TargetType: ip
Port: 8080
Protocol: HTTP
VpcId: !Ref VPCId