This repository has been archived by the owner on Jan 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cloudformation.template
329 lines (329 loc) · 9.33 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "aws auth proxy",
"Parameters": {
"DnsName": {
"Description": "DNS name",
"Type": "String",
"Default": "aws.example.com"
},
"KeyPair": {
"Description": "Keypair",
"Type": "String",
"Default": ""
},
"FrontendSSLCertificateARN": {
"Description": "Frontend SSL Certificate ARN",
"Type": "String",
"Default": ""
},
"GoogleDomain": {
"Description": "The name of your google apps domain. Only users from this domain are allowed to log in.",
"Type": "String",
"Default": ""
},
"GoogleClientID": {
"Description": "Your Google OAuth client ID. This is used to enable identity federation. Get yours from https://console.developers.google.com/",
"Type": "String",
"Default": ""
},
"GoogleClientSecret": {
"Description": "The secret that goes with GoogleClientId",
"Type": "String",
"Default": ""
},
"GoogleServiceEmail": {
"Description": "Your Google service account email address and private key. This is used to determine a users group membership",
"Type": "String",
"Default": ""
},
"GoogleServicePrivateKey": {
"Description": "The private kye that goes with GoogleServiceEmail",
"Type": "String",
"Default": ""
},
"GoogleServiceUser": {
"Description": "The Google service account requires a user to impersonate when checking the directory to see which groups a user is in. Specify this user here. This user is also used to test the directory service at startup.",
"Type": "String",
"Default": ""
},
"DockerImage": {
"Description": "Docker image for the auth proxy",
"Type": "String",
"Default": "crewjam/awsauthproxy:latest"
}
},
"Mappings": {
"RegionMap": {
"us-east-1": {
"AMI": "ami-76e27e1e"
}
}
},
"Resources": {
"FederationUser": {
"Type": "AWS::IAM::User",
"Properties" : {
"Policies": [{
"PolicyName" : "AllowGetFederationToken",
"PolicyDocument" : {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:GetFederationToken",
"Resource": "*"
}
]
}
},
{
"PolicyName" : "MaxAllowedAccessOfFederatedUsers",
"PolicyDocument" : {
"Version": "2012-10-17",
"Statement": [
{
"Action": ["iam:List*","iam:Get*","iam:PassRole"],
"Resource": "*",
"Effect": "Allow"
},
{
"Effect": "Allow",
"NotAction": "iam:*",
"Resource": "*"
},
{
"Action": ["cloudformation:*"],
"Effect": "Deny",
"Resource": {"Fn::Join": ["", ["arn:aws:cloudformation:",
{"Ref": "AWS::Region"}, ":", {"Ref": "AWS::AccountId"}, ":stack/",
{"Ref": "AWS::StackName"}, "/*"]]}
}
]
}
}]
}
},
"FederationUserAccessKey": {
"Type": "AWS::IAM::AccessKey",
"Properties": {
"Serial": 4,
"UserName": {"Ref": "FederationUser"}
}
},
"LoadBalancer": {
"Type": "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties": {
"ConnectionDrainingPolicy": {
"Enabled": true,
"Timeout": 30
},
"CrossZone": true,
"HealthCheck": {
"HealthyThreshold": "2",
"Interval": "6",
"Target": "TCP:80",
"Timeout": "5",
"UnhealthyThreshold": "2"
},
"AvailabilityZones": [
{
"Fn::Select": [
"1",
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
},
{
"Fn::Select": [
"2",
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
},
{
"Fn::Select": [
"3",
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
}
],
"Listeners": [
{
"InstancePort": "80",
"InstanceProtocol": "HTTP",
"LoadBalancerPort": "443",
"Protocol": "HTTPS",
"SSLCertificateId": {"Ref": "FrontendSSLCertificateARN"}
}
],
"SecurityGroups": [
{"Fn::GetAtt": ["LoadBalancerSecurityGroup", "GroupId"]}
]
}
},
"LoadBalancerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable SSH access",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "443",
"ToPort": "443",
"CidrIp": "0.0.0.0/0"
}
]
}
},
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable SSH access",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "80",
"ToPort": "80",
"SourceSecurityGroupOwnerId": {
"Fn::GetAtt": [
"LoadBalancer",
"SourceSecurityGroup.OwnerAlias"
]
},
"SourceSecurityGroupName": {
"Fn::GetAtt": ["LoadBalancer", "SourceSecurityGroup.GroupName"]
}
}
]
}
},
"ASG": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": [
{
"Fn::Select": [
"1",
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
},
{
"Fn::Select": [
"2",
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
},
{
"Fn::Select": [
"3",
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
}
],
"MaxSize": "1",
"MinSize": "1",
"HealthCheckGracePeriod": "600",
"HealthCheckType": "ELB",
"LaunchConfigurationName": {
"Ref": "LaunchConfig"
},
"LoadBalancerNames": [
{"Ref": "LoadBalancer"}
],
"Tags": [
{
"PropagateAtLaunch": true,
"Key": "Name",
"Value": {
"Ref": "DnsName"
}
}
]
}
},
"LaunchConfig": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Metadata": {
"SecretAccessKey": {"Fn::GetAtt": ["FederationUserAccessKey", "SecretAccessKey"]},
"GoogleClientSecret": {"Ref": "GoogleClientSecret"},
"GoogleServicePrivateKey": {"Ref": "GoogleServicePrivateKey"}
},
"Properties": {
"ImageId": {
"Fn::FindInMap": [
"RegionMap",
{
"Ref": "AWS::Region"
},
"AMI"
]
},
"InstanceType": "t2.micro",
"KeyName": {
"Ref": "KeyPair"
},
"SecurityGroups": [
{
"Ref": "SecurityGroup"
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash\n",
"set -ex\n",
"curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar -xz --strip-components=1\n",
"python setup.py install\n",
"curl -sSL https://get.docker.com/ | sh\n",
"docker run -d",
" -e AWSAUTHD_TRUST_X_FORWARDED=true",
" -e AWSAUTHD_AWS_ACCESS_KEY_ID=", {"Ref": "FederationUserAccessKey"},
" -e AWSAUTHD_AWS_SECRET_ACCESS_KEY=$(cfn-get-metadata -v -s ", {"Ref": "AWS::StackName"}, " -r LaunchConfig -k SecretAccessKey)",
" -e AWSAUTHD_GOOGLE_DOMAIN=", {"Ref": "GoogleDomain"},
" -e AWSAUTHD_GOOGLE_CLIENT_ID=", {"Ref": "GoogleClientID"},
" -e AWSAUTHD_GOOGLE_CLIENT_SECRET=$(cfn-get-metadata -v -s ", {"Ref": "AWS::StackName"}, " -r LaunchConfig -k GoogleClientSecret)",
" -e AWSAUTHD_GOOGLE_SERVICE_EMAIL=", {"Ref": "GoogleServiceEmail"},
" -e AWSAUTHD_GOOGLE_SERVICE_PRIVATE_KEY=\"$(cfn-get-metadata -v -s ", {"Ref": "AWS::StackName"}, " -r LaunchConfig -k GoogleServicePrivateKey)\"",
" -e AWSAUTHD_GOOGLE_SERVICE_USER=", {"Ref": "GoogleServiceUser"},
" -p 80:80",
" ", {"Ref": "DockerImage"},
" awsauthd -listen=0.0.0.0:80\n"
]
]
}
}
}
}
}
}