-
Notifications
You must be signed in to change notification settings - Fork 0
/
privateWebsiteStackTemplate.json
373 lines (370 loc) · 13.8 KB
/
privateWebsiteStackTemplate.json
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
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Identity Aware Proxy + S3 Private Website",
"Transform": "AWS::Serverless-2016-10-31",
"Parameters": {
"accessTokenIssuer": {
"Type": "String",
"Description": "The authentication token issuer url used to verify incoming tokens. Get one by creating an account at https://authress.io",
"Default": "acc-0001.login.authress.io"
},
"applicationIdentifier": {
"Type": "String",
"Description": "The application identifier used to securely log users in via the hosted login page. Use the default application or create on at: https://authress.io/app/#/settings?focus=applications",
"Default": "app_default"
},
"bucketWebsiteS3Name": {
"Type": "String",
"Description": "Your S3 Bucket that contains your private static website. This is necessary to configure the CloudFront to proxy your S3 bucket."
},
"identityAwareProxyCustomName": {
"Type": "String",
"Description": "Provide a custom name of the proxy microservice, is used in the naming of various created resources.",
"Default": "IdentityAwareProxy"
},
"identityAwareProxyVersion": {
"Type": "String",
"Description": "The version of the proxy to deploy. Released version numbers are listed: https://github.com/Authress/identity-aware-proxy/tags",
"Default": "1.0"
},
"proxyCustomDomain": {
"Type": "String",
"Description": "[Optional] Specify a domain to host the proxy on. This is where your users will connect to, and will forward the requests to your bucket.",
"Default": ""
},
"proxyRoute53HostedZoneId": {
"Type": "String",
"Description": "[Optional] Specify the Route53 hosted zone that will be used to connect your custom domain to the CloudFront. This will also be used to request a Certificate for that domain.",
"Default": ""
}
},
"Conditions": {
"DeployCustomDomain": { "Fn::Not": [{ "Fn::Equals": [{ "Ref": "proxyCustomDomain" }, ""] }] }
},
"Resources": {
"LambdaFunctionAutoVersion": {
"Type": "AWS::Serverless::Function",
"Properties": {
"FunctionName": { "Ref": "identityAwareProxyCustomName" },
"Description": "Identity Aware Proxy",
"Handler": "index.handler",
"Runtime": "nodejs18.x",
"AutoPublishAlias": "production",
"AutoPublishAliasAllProperties": true,
"CodeUri": {
"Bucket": "authress-identity-aware-proxy-public-artifacts",
"Key": { "Fn::Sub": "IdentityAwareProxy/${identityAwareProxyVersion}/lambda.zip" }
},
"MemorySize": 1769,
"Timeout": 30,
"Role": { "Fn::GetAtt": ["LambdaRole", "Arn"] }
}
},
"LambdaRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": {
"Fn::Sub": "${identityAwareProxyCustomName}LambdaRole-${AWS::Region}"
},
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess"
],
"Path": "/"
}
},
"CloudFrontOriginAccessIdentity": {
"Type": "AWS::CloudFront::CloudFrontOriginAccessIdentity",
"Properties": {
"CloudFrontOriginAccessIdentityConfig": {
"Comment": "Identity Aware Proxy"
}
}
},
"S3BucketPolicy": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "bucketWebsiteS3Name"
},
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Grant a CloudFront Origin Identity access to support private content",
"Effect": "Allow",
"Principal": {
"CanonicalUser": {
"Fn::GetAtt": [
"CloudFrontOriginAccessIdentity",
"S3CanonicalUserId"
]
}
},
"Action": "s3:GetObject",
"Resource": {
"Fn::Sub": "arn:aws:s3:::${bucketWebsiteS3Name}/*"
}
}
]
}
}
},
"HostVaryFrontCachingPolicy": {
"Type": "AWS::CloudFront::CachePolicy",
"Properties": {
"CachePolicyConfig": {
"Comment": "Authentication Login Vary response on Host",
"DefaultTTL": 0,
"MaxTTL": 864000,
"MinTTL": 0,
"Name": { "Fn::Sub": "${identityAwareProxyCustomName}-HostVaryFrontCachingPolicy" },
"ParametersInCacheKeyAndForwardedToOrigin": {
"CookiesConfig": {
"CookieBehavior": "whitelist",
"Cookies": ["authorization", "iap-redirectUrl", "iap-codeVerifier"]
},
"EnableAcceptEncodingBrotli": true,
"EnableAcceptEncodingGzip": true,
"HeadersConfig": {
"HeaderBehavior": "whitelist",
"Headers": ["Host", "Origin", "Sec-Fetch-Dest", "Sec-Fetch-Mode", "Sec-Fetch-Site"]
},
"QueryStringsConfig": {
"QueryStringBehavior": "none"
}
}
}
}
},
"ProtectedRouteCachingPolicy": {
"Type": "AWS::CloudFront::CachePolicy",
"Properties": {
"CachePolicyConfig": {
"Comment": "Authentication Login Vary response on Host",
"DefaultTTL": 86400,
"MaxTTL": 864000,
"MinTTL": 1,
"Name": { "Fn::Sub": "${identityAwareProxyCustomName}-ProtectedRouteCachingPolicy" },
"ParametersInCacheKeyAndForwardedToOrigin": {
"CookiesConfig": {
"CookieBehavior": "whitelist",
"Cookies": ["authorization"]
},
"EnableAcceptEncodingBrotli": true,
"EnableAcceptEncodingGzip": true,
"HeadersConfig": {
"HeaderBehavior": "whitelist",
"Headers": ["Host", "Origin"]
},
"QueryStringsConfig": {
"QueryStringBehavior": "none"
}
}
}
}
},
"LoginUIHostVaryFrontOriginRequestPolicy": {
"Type": "AWS::CloudFront::OriginRequestPolicy",
"Properties": {
"OriginRequestPolicyConfig": {
"Name": { "Fn::Sub": "${identityAwareProxyCustomName}-Login-UI" },
"Comment": "Login UI send additional headers, cookies, and query to origin",
"CookiesConfig": {
"CookieBehavior": "all"
},
"HeadersConfig": {
"HeaderBehavior": "allViewer"
},
"QueryStringsConfig": {
"QueryStringBehavior": "all"
}
}
}
},
"TLSCertificate": {
"Type": "AWS::CertificateManager::Certificate",
"Condition": "DeployCustomDomain",
"DeletionPolicy": "Retain",
"Properties": {
"DomainName": { "Fn::Sub": "${proxyCustomDomain}" },
"ValidationMethod": "DNS",
"DomainValidationOptions": [{
"DomainName": { "Fn::Sub": "${proxyCustomDomain}" },
"HostedZoneId": { "Ref": "proxyRoute53HostedZoneId" }
}]
}
},
"CloudFrontDistribution": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"Comment": "Identity Aware Proxy",
"Enabled": true,
"DefaultRootObject": "index.html",
"HttpVersion": "http2and3",
"PriceClass": "PriceClass_All",
"Aliases": { "Fn::If": ["DeployCustomDomain", [{ "Fn::Sub": "${proxyCustomDomain}" }], { "Ref": "AWS::NoValue" }] },
"Origins": [
{
"DomainName": {
"Fn::Sub": "${bucketWebsiteS3Name}.s3.amazonaws.com"
},
"Id": "S3",
"OriginCustomHeaders": [
{ "HeaderName": "X-SERVICE-NAME", "HeaderValue": { "Ref": "identityAwareProxyCustomName" } },
{ "HeaderName": "X-ISSUER", "HeaderValue": { "Ref": "accessTokenIssuer" } },
{ "HeaderName": "X-AUTHRESS-APPLICATION-ID", "HeaderValue": { "Ref": "applicationIdentifier" } }
],
"S3OriginConfig": {
"OriginAccessIdentity": {
"Fn::Sub": "origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}"
}
}
}
],
"CacheBehaviors": [
{
"PathPattern": "/favicon.ico",
"AllowedMethods": ["GET", "HEAD", "OPTIONS"],
"Compress": true,
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"OriginRequestPolicyId": "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf",
"ResponseHeadersPolicyId": "67f7725c-6f97-4210-82d7-5512b31e9d03",
"TargetOriginId": "S3",
"ViewerProtocolPolicy": "redirect-to-https"
},
{
"PathPattern": "/",
"AllowedMethods": ["GET", "HEAD", "OPTIONS"],
"Compress": true,
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"OriginRequestPolicyId": "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf",
"ResponseHeadersPolicyId": "67f7725c-6f97-4210-82d7-5512b31e9d03",
"TargetOriginId": "S3",
"ViewerProtocolPolicy": "redirect-to-https"
},
{
"PathPattern": "/index.html",
"AllowedMethods": ["GET", "HEAD", "OPTIONS"],
"Compress": true,
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"OriginRequestPolicyId": "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf",
"ResponseHeadersPolicyId": "67f7725c-6f97-4210-82d7-5512b31e9d03",
"TargetOriginId": "S3",
"ViewerProtocolPolicy": "redirect-to-https"
},
{
"PathPattern": "public/*",
"AllowedMethods": ["GET", "HEAD", "OPTIONS"],
"Compress": true,
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"OriginRequestPolicyId": "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf",
"ResponseHeadersPolicyId": "67f7725c-6f97-4210-82d7-5512b31e9d03",
"TargetOriginId": "S3",
"ViewerProtocolPolicy": "redirect-to-https"
},
{
"PathPattern": "login/*",
"AllowedMethods": ["GET", "HEAD", "OPTIONS"],
"Compress": true,
"CachePolicyId": { "Ref": "HostVaryFrontCachingPolicy" },
"OriginRequestPolicyId": { "Ref": "LoginUIHostVaryFrontOriginRequestPolicy" },
"ResponseHeadersPolicyId": "67f7725c-6f97-4210-82d7-5512b31e9d03",
"TargetOriginId": "S3",
"ViewerProtocolPolicy": "redirect-to-https",
"LambdaFunctionAssociations": [
{
"EventType": "origin-request",
"IncludeBody": true,
"LambdaFunctionARN": {
"Fn::Sub": "${LambdaFunctionAutoVersion.Version}"
}
}
]
},
],
"DefaultCacheBehavior": {
"AllowedMethods": ["GET", "HEAD", "OPTIONS"],
"Compress": true,
"CachePolicyId": { "Ref": "ProtectedRouteCachingPolicy" },
"OriginRequestPolicyId": "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf",
"ResponseHeadersPolicyId": "67f7725c-6f97-4210-82d7-5512b31e9d03",
"TargetOriginId": "S3",
"ViewerProtocolPolicy": "redirect-to-https",
"LambdaFunctionAssociations": [
{
"EventType": "origin-request",
"IncludeBody": true,
"LambdaFunctionARN": {
"Fn::Sub": "${LambdaFunctionAutoVersion.Version}"
}
}
]
},
"ViewerCertificate": { "Fn::If": ["DeployCustomDomain",
{
"AcmCertificateArn": { "Ref": "TLSCertificate"},
"MinimumProtocolVersion": "TLSv1.2_2021",
"SslSupportMethod": "sni-only"
}, { "Ref": "AWS::NoValue" }]
}
}
}
},
"ProdRoute53": {
"Type": "AWS::Route53::RecordSet",
"Condition": "DeployCustomDomain",
"Properties": {
"AliasTarget": {
"DNSName": { "Fn::GetAtt": ["CloudFrontDistribution", "DomainName"] },
"HostedZoneId": "Z2FDTNDATAQYW2"
},
"HostedZoneId": { "Ref": "proxyRoute53HostedZoneId" },
"Name": { "Fn::Sub": "${proxyCustomDomain}" },
"Type": "A"
}
},
"ProdRoute53Ipv6": {
"Type": "AWS::Route53::RecordSet",
"Condition": "DeployCustomDomain",
"Properties": {
"AliasTarget": {
"DNSName": { "Fn::GetAtt": ["CloudFrontDistribution", "DomainName"] },
"HostedZoneId": "Z2FDTNDATAQYW2"
},
"HostedZoneId": { "Ref": "proxyRoute53HostedZoneId" },
"Name": { "Fn::Sub": "${proxyCustomDomain}" },
"Type": "AAAA"
}
}
},
"Outputs": {
"IdentityAwareProxyDomain": {
"Description": "The domain generated for the Identity Aware Proxy.",
"Value": {
"Fn::If": ["DeployCustomDomain", { "Fn::Sub": "${proxyCustomDomain}" }, { "Fn::GetAtt": ["CloudFrontDistribution", "DomainName"] }]
},
"Export": {
"Name": "IdentityAwareProxyDomain"
}
}
}
}