-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathazion.config.mjs
385 lines (374 loc) · 11 KB
/
azion.config.mjs
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
import { defineConfig } from 'azion'
import process from 'node:process'
const { CROSS_EDGE_SECRET, VITE_ENVIRONMENT } = process.env
const environment = VITE_ENVIRONMENT || 'production'
const addStagePrefix = (origin) => {
if (environment === 'stage') {
return origin?.map(({ hostHeader, addresses, ...rest }) => {
const isCitiesDomain = hostHeader === 'cities.azion.com'
const transform = (addr) => `stage-${isCitiesDomain ? addr.replace('.com', '.net') : addr}`
return {
...rest,
hostHeader: transform(hostHeader),
addresses: addresses?.map(transform)
}
})
}
return origin
}
const addStageSuffixToCookies = (cookieName) => {
return environment === 'stage' ? `${cookieName}_stg` : cookieName
}
const createCookieRewriteRule = (cookieName, description, prefix = '') => {
const formattedCookieName = prefix + addStageSuffixToCookies(cookieName)
const domains = [
{ domain: 'azion.com', regex: '.*(azion\\.com)' },
{ domain: 'azionedge.net', regex: '.*(map\\.azionedge\\.net)' }
]
return domains.map(({ domain, regex }) => ({
name: `Rewrite ${cookieName} Cookie in ${domain}`,
description,
criteria: [
{
variable: `\${upstream_cookie_${formattedCookieName}}`,
conditional: 'if',
operator: 'matches',
inputValue: '.*'
},
{
variable: '${host}',
conditional: 'and',
operator: 'matches',
inputValue: regex
}
],
behavior: {
capture: {
match: '(.*)',
captured: `${cookieName}_arr`,
subject: `upstream_cookie_${formattedCookieName}`
},
setCookie: `${formattedCookieName}=%{${cookieName}_arr[0]}; Max-Age=1209600; Path=/; SameSite=Lax; Secure; Domain=${domain}`,
filterCookie: formattedCookieName
}
}))
}
const cookieRewriteRules = [
...createCookieRewriteRule(
'azrt',
'Captures and rewrites the _azrt cookie from upstream responses, setting it with specific domain, path, and security settings.',
'_'
),
...createCookieRewriteRule(
'azsid',
'Captures and rewrites the azsid cookie from upstream responses, applying new domain, expiration, and secure attributes.'
),
...createCookieRewriteRule(
'azat',
'Captures and rewrites the _azat cookie from upstream responses, setting secure, domain-specific settings for enhanced security.',
'_'
)
]
const config = {
build: {
preset: {
name: 'vue'
}
},
origin: [
...addStagePrefix([
{
name: 'origin-storage-default',
type: 'object_storage'
},
{
name: 'origin-manager',
type: 'single_origin',
hostHeader: `manager.azion.com`,
addresses: [`manager.azion.com`]
},
{
name: 'origin-marketplace',
type: 'single_origin',
hostHeader: `marketplace.azion.com`,
addresses: [`marketplace.azion.com`]
},
{
name: 'origin-cities',
type: 'single_origin',
hostHeader: `cities.azion.com`,
addresses: [`cities.azion.com`]
},
{
name: 'origin-sso',
type: 'single_origin',
hostHeader: `sso.azion.com`,
addresses: [`sso.azion.com`]
},
{
name: 'origin-api',
type: 'single_origin',
hostHeader: `api.azion.com`,
addresses: [`api.azion.com`]
}
]),
{
name: 'origin-console-feedback',
type: 'single_origin',
hostHeader: `automate.azion.net`,
addresses: [`automate.azion.net`]
}
],
cache: [
{
name: 'Statics - Cache',
stale: false,
queryStringSort: false,
cacheByQueryString: {
option: 'ignore'
},
methods: {
post: false,
options: false
},
browser: {
maxAgeSeconds: 1000 * 5 // 5000 seconds
},
edge: {
maxAgeSeconds: 60 * 60 * 24 * 5 // 5 days
}
},
{
name: 'Cities - Cache',
stale: false,
queryStringSort: false,
cacheByQueryString: {
option: 'varies'
},
methods: {
post: false,
options: false
},
browser: {
maxAgeSeconds: 1000 * 10 // 10000 seconds
},
edge: {
maxAgeSeconds: 60 * 60 * 24 * 7 // 7 days
}
}
],
rules: {
request: [
{
name: 'Apply Common Configuration for All Requests',
description:
'Applies common settings for all requests, including standard headers and HTTP to HTTPS redirection.',
match: '^\\/',
behavior: {
setHeaders: [
'Accept: application/json; version=3;',
'X-Cross-Edge-Secret: ' + CROSS_EDGE_SECRET || 'secret',
'X-User-Real-IP: ${remote_addr}'
],
bypassCache: true,
forwardCookies: true,
httpToHttps: true
}
},
{
name: 'Set Storage Origin for All Requests',
description: 'Sets the default object storage as the origin for all requests.',
match: '^\\/',
behavior: {
setOrigin: {
name: 'origin-storage-default',
type: 'object_storage'
}
}
},
{
name: 'Deliver Static Assets from Storage',
description:
'Sets the storage origin and deliver for all requests using the default object storage.',
match: '.(css|js|ttf|woff|woff2|pdf|svg|jpg|jpeg|gif|bmp|png|ico|mp4|json|xml|html)$',
behavior: {
setOrigin: {
name: 'origin-storage-default',
type: 'object_storage'
},
setCache: 'Statics - Cache',
deliver: true
}
},
{
name: 'Redirect All Non-Asset Requests to to index.html',
description:
'Delivers static assets such as CSS, JS, images, and other files directly from object storage.',
match: '^\\/',
behavior: {
rewrite: `/index.html`
}
},
{
name: 'Route API Default Requests to API Origin',
description: 'Routes all default API requests to the specific API origin.',
match: '^/api',
behavior: {
setOrigin: {
name: 'origin-api',
type: 'single_origin'
}
}
},
{
name: 'Route Specific API Services to Marketplace Origin',
description:
'Routes marketplace API services to the manager origin, forwarding cookies and bypassing cache.',
match: '^/api/marketplace',
behavior: {
setOrigin: {
name: 'origin-marketplace',
type: 'single_origin'
},
forwardCookies: true,
capture: {
match: '/api/marketplace/(.*)',
captured: 'captured',
subject: 'request_uri'
},
rewrite: `/marketplace/api/%{captured[1]}`
}
},
{
name: 'Route Specific API Services to Template Engine Origin',
description:
'Routes template-engine API services to the manager origin, forwarding cookies and bypassing cache.',
match: '^/api/template-engine',
behavior: {
setOrigin: {
name: 'origin-manager',
type: 'single_origin'
},
forwardCookies: true,
capture: {
match: '/api/template-engine/(.*)',
captured: 'captured',
subject: 'request_uri'
},
rewrite: `/template-engine/api/%{captured[1]}`,
bypassCache: true
}
},
{
name: 'Route Specific API Services to Script Runner Origin',
description:
'Routes script-runner API services to the script runner origin, forwarding cookies and bypassing cache.',
match: '^/api/script-runner',
behavior: {
setOrigin: {
name: 'origin-manager',
type: 'single_origin'
},
forwardCookies: true,
capture: {
match: '/api/script-runner/(.*)',
captured: 'captured',
subject: 'request_uri'
},
rewrite: `/script-runner/api/%{captured[1]}`,
bypassCache: true
}
},
{
name: 'Route User Authentication and Account Management to SSO Origin',
description:
'Routes user authentication and account management requests to the SSO origin, with cookie forwarding and cache bypass.',
match: '^/api/(account|user|token|switch-account|auth|password|totp)|^/logout',
behavior: {
setOrigin: {
name: 'origin-sso',
type: 'single_origin'
},
forwardCookies: true,
bypassCache: true
}
},
{
name: 'Route GraphQL City Queries to Cities Origin',
description: 'Routes GraphQL queries for cities to the specific cities origin.',
match: '^/graphql/cities/',
behavior: {
forwardCookies: true,
setOrigin: {
name: 'origin-cities',
type: 'single_origin'
},
rewrite: '/graphql/',
setCache: 'Cities - Cache'
}
},
{
name: 'API Version 4 Routing',
description: 'Directs API version 4 requests to the designated API origin for handling.',
match: '^/v4',
behavior: {
setOrigin: {
name: 'origin-api',
type: 'single_origin'
}
}
},
{
name: 'Route Send Feedback',
description: 'this route will send user feedback to jira',
match: '^/api/webhook/console_feedback',
behavior: {
forwardCookies: true,
setOrigin: {
name: 'origin-console-feedback',
type: 'single_origin'
},
rewrite: '/webhook/console_feedback'
}
},
{
name: 'Route API Identity Providers',
description: 'Routes API requests for identity providers',
match: '^/api/iam',
behavior: {
forwardCookies: true,
setOrigin: {
name: 'origin-manager',
type: 'single_origin'
},
capture: {
match: '/api/iam/(.*)',
captured: 'captured',
subject: 'request_uri'
},
rewrite: `/iam/api/%{captured[1]}`
}
}
],
response: [
...cookieRewriteRules,
{
name: 'Secure Headers',
description:
'Sets various security headers to enhance the security posture of responses, including protections against clickjacking, XSS, and other web vulnerabilities.',
match: '^\\/',
behavior: {
setHeaders: [
'X-Frame-Options: SAMEORIGIN',
'X-Content-Type-Options: nosniff',
'Strict-Transport-Security: max-age=2592000; includeSubDomains',
'Referrer-Policy: strict-origin-when-cross-origin',
'X-XSS-Protection: 1; mode=block',
'Cross-Origin-Opener-Policy: unsafe-none'
]
}
}
]
}
}
export default defineConfig(config)