zuplo 7.15.53 → 7.15.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/articles/monorepo-deployment.mdx +101 -47
- package/docs/articles/securing-backend-mtls.mdx +75 -17
- package/docs/articles/sharing-code-across-projects.mdx +47 -30
- package/docs/cli/archive.mdx +60 -0
- package/docs/concepts/project-structure.mdx +286 -102
- package/docs/dev-portal/migration.mdx +41 -20
- package/docs/policies/_index.md +1 -1
- package/docs/policies/upstream-aws-federated-auth-inbound/doc.md +78 -7
- package/docs/policies/upstream-aws-federated-auth-inbound/intro.md +3 -3
- package/docs/policies/upstream-aws-federated-auth-inbound/schema.json +2 -2
- package/package.json +5 -5
|
@@ -23,57 +23,111 @@ development, and common troubleshooting steps for monorepo setups.
|
|
|
23
23
|
|
|
24
24
|
## Project structure
|
|
25
25
|
|
|
26
|
-
A monorepo with a Zuplo project in a subdirectory typically looks like this
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
my-monorepo/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
A monorepo with a Zuplo project in a subdirectory typically looks like this.
|
|
27
|
+
Select the Zuplo project and its files to see what each one needs.
|
|
28
|
+
|
|
29
|
+
<FileTree root="my-monorepo" defaultSelected="packages/api-gateway">
|
|
30
|
+
<FileTreeFolder name="apps">
|
|
31
|
+
<FileTreeFolder name="web" description="Frontend application" open={false} />
|
|
32
|
+
<FileTreeFolder name="backend" description="Backend service" open={false} />
|
|
33
|
+
</FileTreeFolder>
|
|
34
|
+
<FileTreeFolder name="packages">
|
|
35
|
+
<FileTreeFolder name="api-gateway" description="Zuplo project" highlight usage="Where the Zuplo CLI runs: set it as the working directory in CI and locally">
|
|
36
|
+
|
|
37
|
+
A complete Zuplo project in its own folder. The Zuplo CLI treats this
|
|
38
|
+
folder as the project root, so every `zuplo` command, locally and in CI,
|
|
39
|
+
runs from here.
|
|
40
|
+
|
|
41
|
+
It must contain these files at minimum:
|
|
42
|
+
|
|
43
|
+
- **`zuplo.jsonc`**: project configuration
|
|
44
|
+
- **`package.json`**: dependencies, including `zuplo`
|
|
45
|
+
- **`config/routes.oas.json`**: route definitions
|
|
46
|
+
- **`config/policies.json`**: policy configuration
|
|
47
|
+
|
|
48
|
+
<FileTreeTips>
|
|
49
|
+
|
|
50
|
+
- Set `working-directory: packages/api-gateway` on your CI job so
|
|
51
|
+
`npx zuplo deploy` finds the project.
|
|
52
|
+
- Filter CI triggers with `paths: ["packages/api-gateway/**"]` so
|
|
53
|
+
changes elsewhere in the monorepo don't redeploy the gateway.
|
|
54
|
+
|
|
55
|
+
</FileTreeTips>
|
|
56
|
+
|
|
57
|
+
<FileTreeFolder name="config" description="Routes and policies">
|
|
58
|
+
<FileTreeFile name="routes.oas.json" description="Route definitions in OpenAPI format" status="committed" usage="Read when the project builds and deploys">
|
|
59
|
+
|
|
60
|
+
An OpenAPI document that defines the gateway's routes. Each operation
|
|
61
|
+
sets its handler and policies through the `x-zuplo-route` extension.
|
|
62
|
+
|
|
63
|
+
See [Routing](./routing.mdx) for details.
|
|
64
|
+
|
|
65
|
+
</FileTreeFile>
|
|
66
|
+
<FileTreeFile name="policies.json" description="Policy configuration" status="committed" usage="Read when the project builds and deploys">
|
|
67
|
+
|
|
68
|
+
Must be valid JSON with a `policies` array. Each policy entry requires
|
|
69
|
+
a `name`, `policyType`, and a `handler` object with `export`,
|
|
70
|
+
`module`, and `options` fields.
|
|
71
|
+
|
|
72
|
+
```json title="config/policies.json"
|
|
73
|
+
{
|
|
74
|
+
"policies": [
|
|
75
|
+
{
|
|
76
|
+
"name": "my-rate-limit-inbound-policy",
|
|
77
|
+
"policyType": "rate-limit-inbound",
|
|
78
|
+
"handler": {
|
|
79
|
+
"export": "RateLimitInboundPolicy",
|
|
80
|
+
"module": "$import(@zuplo/runtime)",
|
|
81
|
+
"options": {
|
|
82
|
+
"rateLimitBy": "ip",
|
|
83
|
+
"requestsAllowed": 100,
|
|
84
|
+
"timeWindowMinutes": 1
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
<FileTreeTips>
|
|
93
|
+
|
|
94
|
+
- Include the `handler` block with `export`, `module`, and `options`
|
|
95
|
+
on every policy. Without it, `zuplo deploy` fails schema
|
|
96
|
+
validation.
|
|
97
|
+
|
|
98
|
+
</FileTreeTips>
|
|
99
|
+
|
|
100
|
+
</FileTreeFile>
|
|
101
|
+
</FileTreeFolder>
|
|
102
|
+
<FileTreeFolder name="modules" description="Custom TypeScript handlers and policies" />
|
|
103
|
+
<FileTreeFolder name="tests" description="API tests" />
|
|
104
|
+
<FileTreeFile name="zuplo.jsonc" description="Project configuration" status="committed" usage="Read by every zuplo command run from this folder">
|
|
105
|
+
|
|
106
|
+
Project configuration, including `version`, `compatibilityDate`, and
|
|
107
|
+
`projectType`.
|
|
108
|
+
|
|
109
|
+
```jsonc title="zuplo.jsonc"
|
|
110
|
+
{
|
|
111
|
+
"version": 1,
|
|
112
|
+
"compatibilityDate": "2026-11-06",
|
|
113
|
+
"projectType": "managed-edge",
|
|
114
|
+
}
|
|
115
|
+
```
|
|
45
116
|
|
|
46
|
-
|
|
117
|
+
See [Project Configuration](../programmable-api/zuplo-json.mdx).
|
|
47
118
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- **`package.json`** — Dependencies (must include `zuplo` as a dependency)
|
|
51
|
-
- **`config/routes.oas.json`** — Route definitions in OpenAPI format
|
|
52
|
-
- **`config/policies.json`** — Policy configuration
|
|
119
|
+
</FileTreeFile>
|
|
120
|
+
<FileTreeFile name="package.json" description="The Zuplo project's dependencies" status="committed" usage="Read when you install dependencies for the gateway">
|
|
53
121
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`export`, `module`, and `options` fields. Here's an example:
|
|
122
|
+
Lists the gateway's dependencies. It must include `zuplo` as a
|
|
123
|
+
dependency.
|
|
57
124
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"handler": {
|
|
65
|
-
"export": "RateLimitInboundPolicy",
|
|
66
|
-
"module": "$import(@zuplo/runtime)",
|
|
67
|
-
"options": {
|
|
68
|
-
"rateLimitBy": "ip",
|
|
69
|
-
"requestsAllowed": 100,
|
|
70
|
-
"timeWindowMinutes": 1
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
```
|
|
125
|
+
</FileTreeFile>
|
|
126
|
+
</FileTreeFolder>
|
|
127
|
+
|
|
128
|
+
</FileTreeFolder>
|
|
129
|
+
<FileTreeFile name="package.json" description="Root package.json (workspaces)" />
|
|
130
|
+
</FileTree>
|
|
77
131
|
|
|
78
132
|
:::caution
|
|
79
133
|
|
|
@@ -308,25 +308,83 @@ certificates you uploaded with `zuplo mtls-certificate create`.
|
|
|
308
308
|
Place each certificate in its own subdirectory of `.zuplo-local/mtls`, named
|
|
309
309
|
after the certificate. The layout matches the one used for deployments:
|
|
310
310
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
311
|
+
<FileTree root="my-project" defaultSelected=".zuplo-local/mtls/my_backend_cert">
|
|
312
|
+
<FileTreeFolder name=".zuplo-local" description="Local-only files" status="gitignored" usage="Read by zuplo dev at startup">
|
|
313
|
+
|
|
314
|
+
Holds files that exist only on your machine, including the unencrypted
|
|
315
|
+
private keys for local mTLS. Projects created with `create-zuplo-api`
|
|
316
|
+
gitignore it already.
|
|
317
|
+
|
|
318
|
+
<FileTreeTips>
|
|
319
|
+
|
|
320
|
+
- On older projects, add `.zuplo-local/` to your `.gitignore`. `zuplo dev`
|
|
321
|
+
prints a warning at startup when it isn't covered.
|
|
322
|
+
|
|
323
|
+
</FileTreeTips>
|
|
324
|
+
|
|
325
|
+
<FileTreeFolder name="mtls" description="One subdirectory per certificate">
|
|
326
|
+
|
|
327
|
+
Each subdirectory is one client certificate, named after the certificate.
|
|
328
|
+
The layout matches the one used for deployments.
|
|
329
|
+
|
|
330
|
+
<FileTreeFolder name="my_backend_cert" description="Same name as the uploaded certificate" highlight usage="Loaded by zuplo dev; referenced by name in your code">
|
|
331
|
+
|
|
332
|
+
The subdirectory name is the name your code references, so use the same
|
|
333
|
+
name as the certificate you uploaded to Zuplo. Then this call resolves
|
|
334
|
+
locally and in deployed environments without a code change:
|
|
335
|
+
|
|
336
|
+
```ts title="modules/call-backend.ts"
|
|
337
|
+
fetch(url, { zuplo: { mtlsCertificate: "my_backend_cert" } });
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
<FileTreeTips>
|
|
341
|
+
|
|
342
|
+
- Add one subdirectory per certificate. `zuplo dev` lists every
|
|
343
|
+
certificate it loaded at startup.
|
|
344
|
+
- Keep certificates outside the project with
|
|
345
|
+
`zuplo dev --mtls-certs <dir>`, using the same layout.
|
|
346
|
+
|
|
347
|
+
</FileTreeTips>
|
|
348
|
+
|
|
349
|
+
<FileTreeFile name="tls.crt" description="PEM-encoded certificate" status="gitignored">
|
|
350
|
+
|
|
351
|
+
The client certificate `zuplo dev` presents to your backend. It must
|
|
352
|
+
be PEM-encoded, the same requirement as an uploaded certificate.
|
|
353
|
+
|
|
354
|
+
</FileTreeFile>
|
|
355
|
+
<FileTreeFile name="tls.key" description="Unencrypted PEM private key" status="gitignored">
|
|
356
|
+
|
|
357
|
+
The certificate's private key. It must be PEM-encoded and
|
|
358
|
+
unencrypted, the same requirements as an uploaded certificate.
|
|
359
|
+
|
|
360
|
+
<FileTreeTips>
|
|
361
|
+
|
|
362
|
+
- Never commit this file. It's an unencrypted private key.
|
|
363
|
+
|
|
364
|
+
</FileTreeTips>
|
|
365
|
+
|
|
366
|
+
</FileTreeFile>
|
|
367
|
+
</FileTreeFolder>
|
|
368
|
+
</FileTreeFolder>
|
|
369
|
+
|
|
370
|
+
</FileTreeFolder>
|
|
371
|
+
<FileTreeFolder name="config" open={false} />
|
|
372
|
+
<FileTreeFolder name="modules" open={false} />
|
|
373
|
+
<FileTreeFile name="zuplo.jsonc" description="Project configuration" status="committed" usage="Read by zuplo dev to decide whether local mTLS is available">
|
|
374
|
+
|
|
375
|
+
Local mTLS works when `projectType` is `managed-dedicated` or
|
|
376
|
+
`self-hosted`. On `managed-edge`, or when the field is missing, `zuplo dev`
|
|
377
|
+
skips mTLS.
|
|
378
|
+
|
|
379
|
+
<FileTreeTips>
|
|
380
|
+
|
|
381
|
+
- Run [`zuplo link`](../cli/link.mdx) to write the linked project's
|
|
382
|
+
`projectType` into the file when it's missing.
|
|
322
383
|
|
|
323
|
-
|
|
324
|
-
the certificate you uploaded to Zuplo. Then
|
|
325
|
-
`fetch(url, { zuplo: { mtlsCertificate: "my_backend_cert" } })` resolves locally
|
|
326
|
-
and in deployed environments without a code change.
|
|
384
|
+
</FileTreeTips>
|
|
327
385
|
|
|
328
|
-
|
|
329
|
-
|
|
386
|
+
</FileTreeFile>
|
|
387
|
+
</FileTree>
|
|
330
388
|
|
|
331
389
|
:::caution{title="Keep private keys out of Git"}
|
|
332
390
|
|
|
@@ -42,20 +42,24 @@ integrates seamlessly with Zuplo's build process.
|
|
|
42
42
|
|
|
43
43
|
Create a new npm package with the following structure:
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
<FileTree root="my-shared-zuplo-modules">
|
|
46
|
+
<FileTreeFile name="package.json" />
|
|
47
|
+
<FileTreeFolder name="scripts">
|
|
48
|
+
<FileTreeFile name="copy-to-modules.mjs" />
|
|
49
|
+
</FileTreeFolder>
|
|
50
|
+
<FileTreeFolder name="src">
|
|
51
|
+
<FileTreeFolder name="policies">
|
|
52
|
+
<FileTreeFile name="custom-auth-policy.ts" />
|
|
53
|
+
</FileTreeFolder>
|
|
54
|
+
<FileTreeFolder name="handlers">
|
|
55
|
+
<FileTreeFile name="custom-handler.ts" />
|
|
56
|
+
</FileTreeFolder>
|
|
57
|
+
<FileTreeFolder name="utils">
|
|
58
|
+
<FileTreeFile name="helpers.ts" />
|
|
59
|
+
</FileTreeFolder>
|
|
60
|
+
</FileTreeFolder>
|
|
61
|
+
<FileTreeFile name="README.md" />
|
|
62
|
+
</FileTree>
|
|
59
63
|
|
|
60
64
|
### Package Configuration
|
|
61
65
|
|
|
@@ -263,22 +267,35 @@ The package's `postinstall` script automatically copies the TypeScript files to
|
|
|
263
267
|
your `modules/shared` folder. After installation, your project structure looks
|
|
264
268
|
like this:
|
|
265
269
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
270
|
+
<FileTree root="your-zuplo-project">
|
|
271
|
+
<FileTreeFolder name="modules">
|
|
272
|
+
<FileTreeFolder
|
|
273
|
+
name="shared"
|
|
274
|
+
description="Automatically copied from the shared package"
|
|
275
|
+
status="generated"
|
|
276
|
+
highlight
|
|
277
|
+
>
|
|
278
|
+
<FileTreeFolder name="policies">
|
|
279
|
+
<FileTreeFile name="custom-auth-policy.ts" />
|
|
280
|
+
</FileTreeFolder>
|
|
281
|
+
<FileTreeFolder name="handlers">
|
|
282
|
+
<FileTreeFile name="custom-handler.ts" />
|
|
283
|
+
</FileTreeFolder>
|
|
284
|
+
<FileTreeFolder name="utils">
|
|
285
|
+
<FileTreeFile name="helpers.ts" />
|
|
286
|
+
</FileTreeFolder>
|
|
287
|
+
</FileTreeFolder>
|
|
288
|
+
<FileTreeFile
|
|
289
|
+
name="my-handler.ts"
|
|
290
|
+
description="Your project-specific modules"
|
|
291
|
+
/>
|
|
292
|
+
</FileTreeFolder>
|
|
293
|
+
<FileTreeFolder name="config">
|
|
294
|
+
<FileTreeFile name="routes.oas.json" />
|
|
295
|
+
<FileTreeFile name="policies.json" />
|
|
296
|
+
</FileTreeFolder>
|
|
297
|
+
<FileTreeFile name="package.json" />
|
|
298
|
+
</FileTree>
|
|
282
299
|
|
|
283
300
|
### Import and Use the Shared Code
|
|
284
301
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Zuplo CLI: Archive"
|
|
3
|
+
sidebar_label: archive
|
|
4
|
+
applies_to:
|
|
5
|
+
product: gateway
|
|
6
|
+
hosting: all
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<CliCommand
|
|
10
|
+
command="archive"
|
|
11
|
+
description="Creates the source archive that `zuplo deploy` uploads, without deploying it"
|
|
12
|
+
options={[
|
|
13
|
+
{
|
|
14
|
+
"name": "dir",
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "The directory containing your Zuplo API",
|
|
17
|
+
"default": ".",
|
|
18
|
+
"required": false,
|
|
19
|
+
"deprecated": false,
|
|
20
|
+
"hidden": true,
|
|
21
|
+
"normalize": true
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "branch",
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "The branch name to record as the environment, instead of the current git branch",
|
|
27
|
+
"required": false,
|
|
28
|
+
"deprecated": false,
|
|
29
|
+
"hidden": false
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "output-file",
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Where to write the .tar.gz archive. Defaults to a new temporary file",
|
|
35
|
+
"required": false,
|
|
36
|
+
"deprecated": false,
|
|
37
|
+
"hidden": false
|
|
38
|
+
}
|
|
39
|
+
]}
|
|
40
|
+
examples={[
|
|
41
|
+
[
|
|
42
|
+
"$0 archive",
|
|
43
|
+
"Archive the project and print its path, environment, repository URL and commit SHA as JSON"
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
"$0 archive --branch my-feature --output-file ./my-api.tar.gz",
|
|
47
|
+
"Archive as the my-feature branch and write the archive to ./my-api.tar.gz"
|
|
48
|
+
]
|
|
49
|
+
]}
|
|
50
|
+
usage="$0 archive [options]"
|
|
51
|
+
>
|
|
52
|
+
|
|
53
|
+
</CliCommand>
|
|
54
|
+
|
|
55
|
+
## Global options
|
|
56
|
+
|
|
57
|
+
The following global options are available for all commands:
|
|
58
|
+
|
|
59
|
+
- [`--help`](./global-options.mdx#help)
|
|
60
|
+
- [`--api-key`](./global-options.mdx#api-key)
|
|
@@ -6,136 +6,320 @@ applies_to:
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
A Zuplo project is a standard Node.js-style project managed via Git. Here is the
|
|
9
|
-
typical layout
|
|
9
|
+
typical layout. Select a file to see what it does.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
├── config/
|
|
14
|
-
│ ├── routes.oas.json # Route definitions (OpenAPI format)
|
|
15
|
-
│ └── policies.json # Policy configuration
|
|
16
|
-
├── modules/
|
|
17
|
-
│ └── my-handler.ts # Custom handlers and policies
|
|
18
|
-
├── docs/ # Developer portal (optional)
|
|
19
|
-
│ └── zudoku.config.ts
|
|
20
|
-
├── zuplo.jsonc # Project configuration
|
|
21
|
-
├── package.json
|
|
22
|
-
├── .env # Local environment variables (do not commit)
|
|
23
|
-
└── .env.zuplo # Generated by `zuplo link` (do not commit)
|
|
24
|
-
```
|
|
11
|
+
<FileTree root="my-api" defaultSelected="config/routes.oas.json">
|
|
12
|
+
<FileTreeFolder name="config" description="Routes and policy configuration" status="committed" usage="Read every time the project builds and deploys">
|
|
25
13
|
|
|
26
|
-
|
|
14
|
+
Holds the JSON files that define your gateway: which routes it serves, what
|
|
15
|
+
handles each request, and which policies run along the way. The Zuplo Portal
|
|
16
|
+
route designer and policy editor read and write these files, so changes you
|
|
17
|
+
make in the Portal and changes you push from Git end up in the same place.
|
|
27
18
|
|
|
28
|
-
|
|
19
|
+
<FileTreeTips>
|
|
29
20
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
- Keep everything that describes the API's shape here, and put code in
|
|
22
|
+
`modules/`.
|
|
23
|
+
- Split a large API into several `*.oas.json` files, for example one per
|
|
24
|
+
resource or team.
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
</FileTreeTips>
|
|
27
|
+
|
|
28
|
+
<FileTreeFile name="routes.oas.json" description="Route definitions in OpenAPI format" status="committed" usage="Read at build time to create the gateway's routes">
|
|
29
|
+
|
|
30
|
+
An OpenAPI 3.1 document that defines your API routes. Each operation
|
|
31
|
+
specifies the HTTP method, path, handler, and policies to apply. Zuplo
|
|
32
|
+
extends the OpenAPI spec with `x-zuplo-route` to attach a handler and
|
|
33
|
+
policies to each operation.
|
|
34
|
+
|
|
35
|
+
<FileTreeTips>
|
|
36
|
+
|
|
37
|
+
- Routes match in the order they appear in the file, so put specific paths
|
|
38
|
+
such as `/users/admin` before `/users/{userId}`.
|
|
39
|
+
- With several OpenAPI files, Zuplo checks them in alphabetical order.
|
|
40
|
+
- The same document powers the API reference in your Developer Portal, so
|
|
41
|
+
add summaries and descriptions as you go.
|
|
42
|
+
|
|
43
|
+
</FileTreeTips>
|
|
44
|
+
|
|
45
|
+
This route forwards `GET /users/{userId}` to a backend and runs two
|
|
46
|
+
policies first:
|
|
47
|
+
|
|
48
|
+
```json title="config/routes.oas.json"
|
|
49
|
+
{
|
|
50
|
+
"paths": {
|
|
51
|
+
"/users/{userId}": {
|
|
52
|
+
"get": {
|
|
53
|
+
"operationId": "get-user",
|
|
54
|
+
"x-zuplo-route": {
|
|
55
|
+
"corsPolicy": "anything-goes",
|
|
56
|
+
"handler": {
|
|
57
|
+
"export": "urlForwardHandler",
|
|
58
|
+
"module": "$import(@zuplo/runtime)",
|
|
59
|
+
"options": {
|
|
60
|
+
"baseUrl": "https://api.example.com"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"policies": {
|
|
64
|
+
"inbound": ["api-key-inbound", "rate-limit-inbound"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
48
67
|
}
|
|
49
|
-
},
|
|
50
|
-
"policies": {
|
|
51
|
-
"inbound": ["api-key-inbound", "rate-limit-inbound"]
|
|
52
68
|
}
|
|
53
69
|
}
|
|
54
70
|
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
71
|
+
```
|
|
59
72
|
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
See [OpenAPI](../articles/openapi.mdx) and
|
|
74
|
+
[Routing](../articles/routing.mdx) for details.
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
</FileTreeFile>
|
|
77
|
+
<FileTreeFile name="policies.json" description="Named policy instances" status="committed" usage="Read at build time; routes reference its policies by name">
|
|
65
78
|
|
|
66
|
-
|
|
79
|
+
Defines each policy instance by name, type, and configuration. Routes list
|
|
80
|
+
these names in their `policies.inbound` and `policies.outbound` arrays, so
|
|
81
|
+
one definition can protect any number of routes.
|
|
67
82
|
|
|
68
|
-
|
|
69
|
-
reference policies by name in their `policies.inbound` and `policies.outbound`
|
|
70
|
-
arrays.
|
|
83
|
+
<FileTreeTips>
|
|
71
84
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
- Give each instance a descriptive name, such as `rate-limit-free-tier`,
|
|
86
|
+
and reuse it across routes instead of copying options.
|
|
87
|
+
- Read secrets in `options` from environment variables with
|
|
88
|
+
`$env(VARIABLE_NAME)` rather than writing them into the file.
|
|
89
|
+
- Point `module` at `$import(./modules/...)` to run your own code as a
|
|
90
|
+
policy.
|
|
91
|
+
|
|
92
|
+
</FileTreeTips>
|
|
93
|
+
|
|
94
|
+
This file defines an API key check and a rate limit of 100 requests per
|
|
95
|
+
minute per IP address:
|
|
96
|
+
|
|
97
|
+
```json title="config/policies.json"
|
|
98
|
+
{
|
|
99
|
+
"policies": [
|
|
100
|
+
{
|
|
101
|
+
"name": "api-key-inbound",
|
|
102
|
+
"policyType": "api-key-inbound",
|
|
103
|
+
"handler": {
|
|
104
|
+
"export": "ApiKeyInboundPolicy",
|
|
105
|
+
"module": "$import(@zuplo/runtime)"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "rate-limit-inbound",
|
|
110
|
+
"policyType": "rate-limit-inbound",
|
|
111
|
+
"handler": {
|
|
112
|
+
"export": "RateLimitInboundPolicy",
|
|
113
|
+
"module": "$import(@zuplo/runtime)",
|
|
114
|
+
"options": {
|
|
115
|
+
"rateLimitBy": "ip",
|
|
116
|
+
"requestsAllowed": 100,
|
|
117
|
+
"timeWindowMinutes": 1
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
]
|
|
81
122
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
See [Policies](../articles/policies.mdx) for the full list of built-in
|
|
126
|
+
policies.
|
|
127
|
+
|
|
128
|
+
</FileTreeFile>
|
|
129
|
+
|
|
130
|
+
</FileTreeFolder>
|
|
131
|
+
<FileTreeFolder name="modules" description="Custom TypeScript code" status="committed" usage="Bundled at build time; runs on each request that uses it">
|
|
132
|
+
|
|
133
|
+
Contains your custom TypeScript code: request handlers, custom policies, and
|
|
134
|
+
shared helpers. Routes and policies point to these modules with
|
|
135
|
+
`$import(./modules/...)`.
|
|
136
|
+
|
|
137
|
+
<FileTreeTips>
|
|
138
|
+
|
|
139
|
+
- Import from `@zuplo/runtime` for request, context, and environment
|
|
140
|
+
types.
|
|
141
|
+
- Put shared helpers in their own files and import them with relative
|
|
142
|
+
paths.
|
|
143
|
+
- Add a `zuplo.runtime.ts` file here to run code once when the gateway
|
|
144
|
+
starts, for example to register plugins.
|
|
145
|
+
|
|
146
|
+
</FileTreeTips>
|
|
147
|
+
|
|
148
|
+
<FileTreeFile name="my-handler.ts" description="A custom request handler" status="committed" usage="Runs on every request to a route that uses it as its handler">
|
|
149
|
+
|
|
150
|
+
A request handler receives the incoming request and returns a response.
|
|
151
|
+
Return a `Response` for full control, or any other value and Zuplo
|
|
152
|
+
serializes it to JSON with an `application/json` content type.
|
|
153
|
+
|
|
154
|
+
```ts title="modules/my-handler.ts"
|
|
155
|
+
import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
|
|
156
|
+
|
|
157
|
+
export default async function (
|
|
158
|
+
request: ZuploRequest,
|
|
159
|
+
context: ZuploContext,
|
|
160
|
+
) {
|
|
161
|
+
return { userId: request.params.userId };
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Wire it to a route by pointing the route's handler at the module and
|
|
166
|
+
export:
|
|
167
|
+
|
|
168
|
+
```json title="config/routes.oas.json"
|
|
169
|
+
{
|
|
170
|
+
"handler": {
|
|
171
|
+
"export": "default",
|
|
172
|
+
"module": "$import(./modules/my-handler)"
|
|
93
173
|
}
|
|
94
174
|
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
<FileTreeTips>
|
|
178
|
+
|
|
179
|
+
- Read path parameters from `request.params` and query strings from
|
|
180
|
+
`request.query`.
|
|
181
|
+
- Log with `context.log` so messages appear in your gateway logs.
|
|
182
|
+
|
|
183
|
+
</FileTreeTips>
|
|
184
|
+
|
|
185
|
+
See [Function Handler](../handlers/custom-handler.mdx) for details.
|
|
186
|
+
|
|
187
|
+
</FileTreeFile>
|
|
188
|
+
|
|
189
|
+
</FileTreeFolder>
|
|
190
|
+
<FileTreeFolder name="docs" description="Developer Portal" status="optional" usage="Built and deployed alongside the gateway when present">
|
|
191
|
+
|
|
192
|
+
Present when your project includes a Developer Portal. It holds the portal
|
|
193
|
+
configuration and any custom pages, and has its own `package.json`. The
|
|
194
|
+
portal generates its API reference from your `config/*.oas.json` files, so
|
|
195
|
+
route changes show up in the docs automatically.
|
|
196
|
+
|
|
197
|
+
<FileTreeTips>
|
|
198
|
+
|
|
199
|
+
- Put Markdown and MDX pages here to add guides next to the API reference.
|
|
200
|
+
- The portal reads its own `docs/.env` for local development, not the
|
|
201
|
+
gateway's `.env`.
|
|
202
|
+
- Delete the portal's configuration file and redeploy to turn the
|
|
203
|
+
Developer Portal off.
|
|
204
|
+
|
|
205
|
+
</FileTreeTips>
|
|
206
|
+
|
|
207
|
+
See [Developer Portal](../dev-portal/overview.mdx) for details.
|
|
208
|
+
|
|
209
|
+
<FileTreeFile name="zudoku.config.tsx" description="Developer Portal configuration" status="committed" usage="Read when the Developer Portal builds">
|
|
210
|
+
|
|
211
|
+
Configures the Developer Portal: navigation, theme, authentication, and
|
|
212
|
+
which OpenAPI files become the API reference.
|
|
213
|
+
|
|
214
|
+
<FileTreeTips>
|
|
215
|
+
|
|
216
|
+
- Only environment variables that start with `ZUPLO_PUBLIC_` or
|
|
217
|
+
`ZUDOKU_PUBLIC_` are available to the portal.
|
|
218
|
+
- Start with navigation and branding, then add authentication when you're
|
|
219
|
+
ready to issue API keys.
|
|
220
|
+
|
|
221
|
+
</FileTreeTips>
|
|
222
|
+
|
|
223
|
+
See the
|
|
224
|
+
[configuration file reference](../dev-portal/zudoku/configuration/overview.md)
|
|
225
|
+
for every option.
|
|
226
|
+
|
|
227
|
+
</FileTreeFile>
|
|
228
|
+
|
|
229
|
+
</FileTreeFolder>
|
|
230
|
+
<FileTreeFile name="zuplo.jsonc" description="Project configuration" status="committed" usage="Read at build time and by zuplo dev">
|
|
231
|
+
|
|
232
|
+
Project-level settings, such as the runtime compatibility date and the
|
|
233
|
+
hosting type. New projects get this file by default.
|
|
234
|
+
|
|
235
|
+
```jsonc title="zuplo.jsonc"
|
|
236
|
+
{
|
|
237
|
+
"version": 1,
|
|
238
|
+
"compatibilityDate": "2026-11-06",
|
|
239
|
+
"projectType": "managed-edge",
|
|
95
240
|
}
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
```
|
|
241
|
+
```
|
|
99
242
|
|
|
100
|
-
|
|
243
|
+
- **`compatibilityDate`** locks runtime behavior, so platform updates don't
|
|
244
|
+
change how your project works until you move the date forward.
|
|
245
|
+
- **`projectType`** is `managed-edge` (the default), `managed-dedicated`, or
|
|
246
|
+
`self-hosted`, matching where the project deploys.
|
|
101
247
|
|
|
102
|
-
|
|
103
|
-
deployment type.
|
|
248
|
+
<FileTreeTips>
|
|
104
249
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"projectType": "managed-edge"
|
|
110
|
-
}
|
|
111
|
-
```
|
|
250
|
+
- Read the [compatibility dates](../programmable-api/compatibility-dates.mdx)
|
|
251
|
+
changes before you move the date forward.
|
|
252
|
+
- The Zuplo Portal doesn't show this file. Edit it in your repository and
|
|
253
|
+
push the change.
|
|
112
254
|
|
|
113
|
-
|
|
114
|
-
The `compatibilityDate` locks runtime behavior so updates don't break your
|
|
115
|
-
project unexpectedly.
|
|
255
|
+
</FileTreeTips>
|
|
116
256
|
|
|
117
|
-
See [Project Configuration](../programmable-api/zuplo-json.mdx) for all
|
|
257
|
+
See [Project Configuration](../programmable-api/zuplo-json.mdx) for all
|
|
258
|
+
options.
|
|
118
259
|
|
|
119
|
-
|
|
260
|
+
</FileTreeFile>
|
|
261
|
+
<FileTreeFile name="package.json" description="Dependencies and scripts" status="committed" usage="Read when you install dependencies and run scripts">
|
|
120
262
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
`$import(./modules/...)`.
|
|
263
|
+
A standard Node.js `package.json`. It lists the `zuplo` package, any npm
|
|
264
|
+
packages your modules import, and the scripts you use day to day.
|
|
124
265
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
266
|
+
<FileTreeTips>
|
|
267
|
+
|
|
268
|
+
- Run `npm run dev` to start the gateway locally.
|
|
269
|
+
- Add npm packages your modules need here. See
|
|
270
|
+
[Installing packages](../articles/local-development-installing-packages.mdx).
|
|
271
|
+
- Commit the lockfile so local runs and deployments use the same versions.
|
|
272
|
+
|
|
273
|
+
</FileTreeTips>
|
|
274
|
+
|
|
275
|
+
</FileTreeFile>
|
|
276
|
+
<FileTreeFile name=".env" description="Local environment variables" status="gitignored" usage="Loaded by zuplo dev when you run the gateway locally">
|
|
277
|
+
|
|
278
|
+
Local development can't read the environment variables you set in the Zuplo
|
|
279
|
+
Portal, so put the values your gateway needs locally here.
|
|
280
|
+
|
|
281
|
+
```txt title=".env"
|
|
282
|
+
API_KEY=my-local-key
|
|
283
|
+
API_BASE_URL=http://localhost:8080
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Your code reads them the same way in every environment:
|
|
287
|
+
|
|
288
|
+
```ts title="modules/my-handler.ts"
|
|
289
|
+
import { environment } from "@zuplo/runtime";
|
|
290
|
+
|
|
291
|
+
const apiUrl = environment.API_BASE_URL;
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
<FileTreeTips>
|
|
295
|
+
|
|
296
|
+
- Never commit this file. Add `.env` to your `.gitignore`.
|
|
297
|
+
- Set the same variable names in the Zuplo Portal for deployed
|
|
298
|
+
environments.
|
|
299
|
+
- When you run `zuplo dev`, `ZUPLO_ENVIRONMENT_STAGE` is `local`.
|
|
300
|
+
|
|
301
|
+
</FileTreeTips>
|
|
302
|
+
|
|
303
|
+
See
|
|
304
|
+
[Environment variables in local development](../articles/local-development-env-variables.mdx).
|
|
305
|
+
|
|
306
|
+
</FileTreeFile>
|
|
307
|
+
<FileTreeFile name=".env.zuplo" description="Linked environment details" status="gitignored" usage="Written by zuplo link; loaded by zuplo dev">
|
|
308
|
+
|
|
309
|
+
[`zuplo link`](../cli/link.mdx) writes this file with details about the
|
|
310
|
+
linked account, project, and environment. `zuplo dev` loads it along with
|
|
311
|
+
`.env`.
|
|
312
|
+
|
|
313
|
+
<FileTreeTips>
|
|
314
|
+
|
|
315
|
+
- Don't edit it: `zuplo link` replaces it each time it runs. Put your own
|
|
316
|
+
variables in `.env`.
|
|
317
|
+
- Don't commit it. Each developer links their own environment.
|
|
133
318
|
|
|
134
|
-
|
|
319
|
+
</FileTreeTips>
|
|
135
320
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
[Developer Portal](../dev-portal/overview.mdx) for details.
|
|
321
|
+
</FileTreeFile>
|
|
322
|
+
</FileTree>
|
|
139
323
|
|
|
140
324
|
## How the files relate
|
|
141
325
|
|
|
@@ -156,26 +156,47 @@ process, continue with the manual migration steps below.
|
|
|
156
156
|
Note, that the old dev portal files are still in place. You will delete them
|
|
157
157
|
later.
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
159
|
+
<FileTree root="my-api">
|
|
160
|
+
<FileTreeFolder name="config">
|
|
161
|
+
<FileTreeFile
|
|
162
|
+
name="dev-portal.json"
|
|
163
|
+
description="Your existing dev-portal.json"
|
|
164
|
+
highlight
|
|
165
|
+
/>
|
|
166
|
+
<FileTreeFile name="routes.oas.json" />
|
|
167
|
+
<FileTreeFile name="policies.json" />
|
|
168
|
+
</FileTreeFolder>
|
|
169
|
+
<FileTreeFolder name="docs">
|
|
170
|
+
<FileTreeFile
|
|
171
|
+
name="sidebar.json"
|
|
172
|
+
description="Your existing sidebar.json"
|
|
173
|
+
highlight
|
|
174
|
+
/>
|
|
175
|
+
<FileTreeFile
|
|
176
|
+
name="theme.css"
|
|
177
|
+
description="Your existing theme.css"
|
|
178
|
+
highlight
|
|
179
|
+
/>
|
|
180
|
+
<FileTreeFile name="zudoku.config.ts" />
|
|
181
|
+
<FileTreeFile name="package.json" />
|
|
182
|
+
<FileTreeFile name="tsconfig.json" />
|
|
183
|
+
<FileTreeFolder name="pages">
|
|
184
|
+
<FileTreeFile
|
|
185
|
+
name="doc.md"
|
|
186
|
+
description="Your existing Markdown files"
|
|
187
|
+
highlight
|
|
188
|
+
/>
|
|
189
|
+
</FileTreeFolder>
|
|
190
|
+
<FileTreeFolder
|
|
191
|
+
name="public"
|
|
192
|
+
description="Your images and other static assets"
|
|
193
|
+
/>
|
|
194
|
+
</FileTreeFolder>
|
|
195
|
+
<FileTreeFile name=".gitignore" />
|
|
196
|
+
<FileTreeFile name="package.json" />
|
|
197
|
+
<FileTreeFile name="tsconfig.json" />
|
|
198
|
+
<FileTreeFile name="README.md" />
|
|
199
|
+
</FileTree>
|
|
179
200
|
|
|
180
201
|
1. **Update TypeScript Configuration File**
|
|
181
202
|
|
package/docs/policies/_index.md
CHANGED
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
| stripe-webhook-verification-inbound | Stripe Webhook Auth | The Stripe Webhook policy validates the authenticity of an incoming Stripe webhook. | api-gateway |
|
|
107
107
|
| supabase-jwt-auth-inbound | Supabase JWT Auth | The Supabase JWT Authentication policy supports user JWT tokens created by Supabase. | api-gateway |
|
|
108
108
|
| traffic-splitting-inbound | Traffic Splitting | Splits traffic randomly across a set of weighted base paths. On each request one base path is selected (weighted by `weight`) and written to the request custom context at `customOutputProperty`. Reference it from a later URL Rewrite `rewritePattern` or URL Forward `baseUrl`, e.g. `${context.custom.trafficSplitting.basePath}`. | api-gateway |
|
|
109
|
-
| upstream-aws-federated-auth-inbound | Upstream AWS Federated Auth | Resolves AWS credentials with STS AssumeRoleWithWebIdentity using Zuplo's ambient OIDC identity — no AWS keys are stored anywhere. The role's trust policy must trust the Zuplo OIDC identity provider. Resolved credentials are registered on the request context for the AWS Lambda handler and custom code to sign upstream requests with `AwsClient.fromContext`. This policy does not itself sign or forward the request. | api-gateway |
|
|
109
|
+
| upstream-aws-federated-auth-inbound | Upstream AWS Federated Auth | Resolves AWS credentials with STS AssumeRoleWithWebIdentity using Zuplo's ambient OIDC identity — no AWS keys are stored anywhere. The role's trust policy must trust the Zuplo OIDC identity provider and require both the token's subject (`sub`) and audience (`aud`). Resolved credentials are registered on the request context for the AWS Lambda handler and custom code to sign upstream requests with `AwsClient.fromContext`. This policy does not itself sign or forward the request. | api-gateway |
|
|
110
110
|
| upstream-aws-service-auth-inbound | Upstream AWS Service Auth | Resolves AWS credentials from static access keys (optionally exchanged for an IAM role's temporary credentials via STS AssumeRole) and registers them on the request context. The AWS Lambda handler and custom code read them with `AwsClient.fromContext` to sign upstream requests. This policy does not itself sign or forward the request. | api-gateway |
|
|
111
111
|
| upstream-azure-ad-service-auth-inbound | Upstream Azure AD Service Auth | Uses Azure Active Directory to add an Authorization header to the request in order to authenticate requests using Azure identity. | api-gateway |
|
|
112
112
|
| upstream-firebase-admin-auth-inbound | Upstream Firebase Admin Auth | Creates a Firebase Admin token and attaches it to the outgoing request. Useful when calling Firebase services as an administrator. | api-gateway |
|
|
@@ -12,15 +12,86 @@ own code read the resolved credentials and sign the requests they build.
|
|
|
12
12
|
|
|
13
13
|
## AWS setup
|
|
14
14
|
|
|
15
|
-
1. Create an **IAM OIDC identity provider**
|
|
16
|
-
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
3.
|
|
15
|
+
1. Create an **IAM OIDC identity provider** with the provider URL
|
|
16
|
+
`https://dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD`. Set the
|
|
17
|
+
audience (client ID) to the value you use for the `audience` option (default
|
|
18
|
+
`sts.amazonaws.com`).
|
|
19
|
+
2. Find the subject (`sub` claim) of each Zuplo environment that needs the role.
|
|
20
|
+
See [Find your environment's subject](#find-your-environments-subject).
|
|
21
|
+
3. Create an **IAM role** whose trust policy allows
|
|
22
|
+
`sts:AssumeRoleWithWebIdentity` for that provider, with conditions on both
|
|
23
|
+
the token's audience (`aud`) and subject (`sub`). See
|
|
24
|
+
[Trust policy](#trust-policy).
|
|
25
|
+
4. Grant the role only the permissions the gateway needs (for example
|
|
22
26
|
`execute-api:Invoke` or `lambda:InvokeFunction`).
|
|
23
27
|
|
|
28
|
+
### Trust policy
|
|
29
|
+
|
|
30
|
+
:::caution Important Security Step
|
|
31
|
+
|
|
32
|
+
Require both the `aud` and the `sub` condition in the role's trust policy. The
|
|
33
|
+
`sub` condition limits the role to the Zuplo environments you list.
|
|
34
|
+
|
|
35
|
+
:::
|
|
36
|
+
|
|
37
|
+
The condition keys are the provider URL without `https://`, followed by `:aud`
|
|
38
|
+
or `:sub`. Replace the account ID and the example subject with your own values.
|
|
39
|
+
If you set the policy's `audience` option, replace `sts.amazonaws.com` in the
|
|
40
|
+
`aud` condition with the same value.
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"Version": "2012-10-17",
|
|
45
|
+
"Statement": [
|
|
46
|
+
{
|
|
47
|
+
"Effect": "Allow",
|
|
48
|
+
"Principal": {
|
|
49
|
+
"Federated": "arn:aws:iam::123456789012:oidc-provider/dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD"
|
|
50
|
+
},
|
|
51
|
+
"Action": "sts:AssumeRoleWithWebIdentity",
|
|
52
|
+
"Condition": {
|
|
53
|
+
"StringEquals": {
|
|
54
|
+
"dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD:aud": "sts.amazonaws.com",
|
|
55
|
+
"dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD:sub": [
|
|
56
|
+
"atcl_ExampleSubject0000000000"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To let more than one environment assume the role (for example production and a
|
|
66
|
+
preview branch), list each environment's subject in the `sub` array.
|
|
67
|
+
|
|
68
|
+
### Find your environment's subject
|
|
69
|
+
|
|
70
|
+
The `sub` claim of the
|
|
71
|
+
[Zuplo Identity Token](https://zuplo.com/docs/articles/zuplo-id-token) is the
|
|
72
|
+
unique identity of one environment, for example `atcl_ExampleSubject0000000000`.
|
|
73
|
+
It stays the same across deployments of that environment. Each environment has
|
|
74
|
+
its own subject, so a new environment, such as a new preview branch, needs its
|
|
75
|
+
subject added to the trust policy.
|
|
76
|
+
|
|
77
|
+
To read the subject, deploy a handler like the following to the environment,
|
|
78
|
+
call it once, and copy the `sub` value from the logs. Remove the handler
|
|
79
|
+
afterwards.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { ZuploContext, ZuploRequest, ZuploServices } from "@zuplo/runtime";
|
|
83
|
+
|
|
84
|
+
export default async function (request: ZuploRequest, context: ZuploContext) {
|
|
85
|
+
const token = await ZuploServices.getIDToken(context, {
|
|
86
|
+
audience: "sts.amazonaws.com",
|
|
87
|
+
});
|
|
88
|
+
const payload = token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
89
|
+
const { sub, deployment } = JSON.parse(atob(payload));
|
|
90
|
+
context.log.info({ sub, deployment });
|
|
91
|
+
return new Response(null, { status: 204 });
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
24
95
|
## Using the credentials
|
|
25
96
|
|
|
26
97
|
### With the AWS Lambda handler
|
|
@@ -8,8 +8,8 @@ With this policy, you'll benefit from:
|
|
|
8
8
|
|
|
9
9
|
- **No Long-Lived Secrets**: No AWS access keys are stored anywhere — the
|
|
10
10
|
gateway proves its identity with a short-lived, audience-bound OIDC token
|
|
11
|
-
- **Least Privilege**: Assume a specific IAM role whose trust policy
|
|
12
|
-
the Zuplo
|
|
11
|
+
- **Least Privilege**: Assume a specific IAM role whose trust policy accepts
|
|
12
|
+
only the Zuplo environments you list, by their subject (`sub`) and audience
|
|
13
13
|
- **Automatic Token Management**: Temporary credentials are cached in memory and
|
|
14
14
|
refreshed before they expire
|
|
15
15
|
- **Reusable Credentials**: Resolve credentials once and use them from the AWS
|
|
@@ -17,4 +17,4 @@ With this policy, you'll benefit from:
|
|
|
17
17
|
|
|
18
18
|
To set this up you configure an IAM OIDC identity provider that trusts Zuplo's
|
|
19
19
|
issuer, and an IAM role whose trust policy permits AssumeRoleWithWebIdentity for
|
|
20
|
-
that provider.
|
|
20
|
+
that provider only when the token's subject and audience match your environment.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"requiresAI": false,
|
|
13
13
|
"policyType": "upstream-aws-federated-auth-inbound",
|
|
14
14
|
"products": ["api-gateway"],
|
|
15
|
-
"description": "Resolves AWS credentials with STS AssumeRoleWithWebIdentity using Zuplo's ambient OIDC identity — no AWS keys are stored anywhere. The role's trust policy must trust the Zuplo OIDC identity provider. Resolved credentials are registered on the request context for the AWS Lambda handler and custom code to sign upstream requests with `AwsClient.fromContext`. This policy does not itself sign or forward the request.",
|
|
15
|
+
"description": "Resolves AWS credentials with STS AssumeRoleWithWebIdentity using Zuplo's ambient OIDC identity — no AWS keys are stored anywhere. The role's trust policy must trust the Zuplo OIDC identity provider and require both the token's subject (`sub`) and audience (`aud`). Resolved credentials are registered on the request context for the AWS Lambda handler and custom code to sign upstream requests with `AwsClient.fromContext`. This policy does not itself sign or forward the request.",
|
|
16
16
|
"deprecatedMessage": "",
|
|
17
17
|
"required": ["handler"],
|
|
18
18
|
"properties": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"roleArn": {
|
|
40
40
|
"type": "string",
|
|
41
41
|
"examples": ["arn:aws:iam::123456789012:role/zuplo-gateway"],
|
|
42
|
-
"description": "The IAM role to assume with STS AssumeRoleWithWebIdentity. The role's trust policy must trust the Zuplo OIDC identity provider."
|
|
42
|
+
"description": "The IAM role to assume with STS AssumeRoleWithWebIdentity. The role's trust policy must trust the Zuplo OIDC identity provider and require both the token's subject ('sub' claim) and audience ('aud' claim)."
|
|
43
43
|
},
|
|
44
44
|
"region": {
|
|
45
45
|
"type": "string",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zuplo",
|
|
3
|
-
"version": "7.15.
|
|
3
|
+
"version": "7.15.55",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The official Zuplo CLI for local development and platform management",
|
|
6
6
|
"homepage": "https://zuplo.com/docs/cli/overview",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"zuplo": "zuplo.js"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@zuplo/cli": "7.15.
|
|
36
|
-
"@zuplo/core": "7.15.
|
|
37
|
-
"@zuplo/runtime": "7.15.
|
|
38
|
-
"@zuplo/test": "7.15.
|
|
35
|
+
"@zuplo/cli": "7.15.55",
|
|
36
|
+
"@zuplo/core": "7.15.55",
|
|
37
|
+
"@zuplo/runtime": "7.15.55",
|
|
38
|
+
"@zuplo/test": "7.15.55"
|
|
39
39
|
}
|
|
40
40
|
}
|