@cnc-tools/storm 0.17.0 → 0.18.0
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/dist/bin/storm.js +37 -39
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-4WAMTUWZ.js → chunk-24UYAK4R.js} +88 -67
- package/dist/chunks/{chunk-RNAS7JHE.js → chunk-2JMWUKH3.js} +710 -102
- package/dist/chunks/{chunk-YEPFSLQR.js → chunk-3VXZONGE.js} +2 -2
- package/dist/chunks/{chunk-D27KILIA.js → chunk-55O4FCN4.js} +1 -1
- package/dist/chunks/{chunk-JN3YY6ZH.js → chunk-AS37D43E.js} +27 -20
- package/dist/chunks/{chunk-2VP4GRJM.js → chunk-CQAY6GLP.js} +54 -13
- package/dist/chunks/{chunk-MR77L2GK.js → chunk-DZLU7BYK.js} +5 -5
- package/dist/chunks/{chunk-LKTZ5OXS.js → chunk-EI3XDCEI.js} +1 -1
- package/dist/chunks/{chunk-FNBB6V4R.js → chunk-FDUY3BNF.js} +1 -1
- package/dist/chunks/{chunk-RWIXDDCK.js → chunk-GUCCYCIO.js} +3 -3
- package/dist/chunks/{chunk-6UHIJXZG.js → chunk-HBI4LEMH.js} +2 -2
- package/dist/chunks/{chunk-CKGZA25H.js → chunk-K4MDQPLW.js} +1 -1
- package/dist/chunks/{chunk-F4MOYHRY.js → chunk-KK7PAWIZ.js} +1 -1
- package/dist/chunks/{chunk-GRT3UIBV.js → chunk-KQ5FXRUD.js} +1 -1
- package/dist/chunks/{chunk-WV3DP6NR.js → chunk-LKXHGGGX.js} +1 -1
- package/dist/chunks/{chunk-4O5C2XGJ.js → chunk-LOGHIUUB.js} +6 -6
- package/dist/chunks/{chunk-7DZE67QM.js → chunk-OEPFINFT.js} +2 -2
- package/dist/chunks/{chunk-HWIQ2S7K.js → chunk-OI4AP6Z7.js} +3 -3
- package/dist/chunks/{chunk-DADEYJDW.js → chunk-PMBQWVTW.js} +6 -6
- package/dist/chunks/{chunk-HP3CURSZ.js → chunk-SZMYIIG2.js} +2 -2
- package/dist/chunks/{chunk-2RNDPDTJ.js → chunk-TXCOFC7N.js} +2 -2
- package/dist/chunks/{chunk-BCBKYOHW.js → chunk-UXD3TVWM.js} +1 -1
- package/dist/chunks/{chunk-M7EKRGVD.js → chunk-WNW2QXQK.js} +1 -1
- package/dist/chunks/{live-app-R76JQXZL.js → live-app-UY7BEDUN.js} +9 -7
- package/dist/cli.d.ts +28 -0
- package/dist/cli.js +64 -0
- package/dist/commands/exec/across-sandboxes-outcomes.d.ts +1 -1
- package/dist/commands/exec/across-sandboxes-outcomes.js +1 -1
- package/dist/commands/exec/before-run.d.ts +1 -1
- package/dist/commands/exec/command.d.ts +36 -12
- package/dist/commands/exec/command.js +18 -18
- package/dist/commands/exec/execute-run.js +1 -1
- package/dist/commands/exec/outcomes.d.ts +71 -15
- package/dist/commands/exec/outcomes.js +46 -6
- package/dist/commands/exec/plan-run.d.ts +1 -1
- package/dist/commands/exec/plan-run.js +8 -3
- package/dist/commands/exec/run-metadata.js +1 -1
- package/dist/commands/exec/run-summary.js +1 -1
- package/dist/commands/runs/facts.d.ts +1 -1
- package/dist/commands/runs/facts.js +2 -2
- package/dist/commands/runs/list/command.d.ts +2 -2
- package/dist/commands/runs/list/command.js +9 -9
- package/dist/commands/runs/list/outcomes.d.ts +1 -1
- package/dist/commands/runs/logs/command.js +9 -9
- package/dist/commands/runs/show/command.d.ts +2 -2
- package/dist/commands/runs/show/command.js +16 -16
- package/dist/commands/runs/show/metadata.js +1 -1
- package/dist/commands/runs/show/outcomes.d.ts +1 -1
- package/dist/commands/runs/show/outcomes.js +1 -1
- package/dist/commands/snapshots/build/command.d.ts +22 -14
- package/dist/commands/snapshots/build/command.js +32 -30
- package/dist/commands/snapshots/build/metadata.js +1 -1
- package/dist/commands/snapshots/build/outcomes.d.ts +14 -10
- package/dist/commands/snapshots/build/outcomes.js +1 -1
- package/dist/commands/snapshots/list/command.d.ts +2 -2
- package/dist/commands/snapshots/list/command.js +19 -19
- package/dist/commands/snapshots/list/outcomes.d.ts +2 -2
- package/dist/commands/snapshots/list/outcomes.js +3 -3
- package/dist/commands/snapshots/prune/command.js +14 -14
- package/dist/commands/suites/list/command.js +10 -10
- package/dist/commands/test/command.d.ts +36 -12
- package/dist/commands/test/command.js +20 -20
- package/dist/commands/test/outcomes.d.ts +18 -6
- package/dist/config-file/define.d.ts +1 -1
- package/dist/config-file/toolchain.d.ts +13 -3
- package/dist/config-file/toolchain.js +41 -5
- package/dist/context.d.ts +3 -1
- package/dist/context.js +2 -1
- package/dist/core/outcomes.d.ts +1 -1
- package/dist/core/run.js +1 -1
- package/dist/extension-commands.d.ts +2 -7
- package/dist/extension-commands.js +3 -17
- package/dist/extensions/testserver/commands/pool/create/command.js +3 -3
- package/dist/extensions/testserver/commands/pool/list/command.js +2 -2
- package/dist/run-directory/recording.js +1 -1
- package/dist/run-directory/run-record.d.ts +5 -5
- package/dist/run-directory/run-record.js +5 -5
- package/dist/runner/build-snapshots.d.ts +5 -0
- package/dist/runner/build-snapshots.js +11 -5
- package/dist/runner/gateways.d.ts +37 -4
- package/dist/runner/gh.d.ts +42 -0
- package/dist/runner/gh.js +58 -0
- package/dist/runner/index.d.ts +5 -4
- package/dist/runner/index.js +3 -2
- package/dist/runner/live/checkout-gateway.js +7 -0
- package/dist/runner/live/gh-output.d.ts +17 -0
- package/dist/runner/live/gh-output.js +37 -0
- package/dist/runner/live/gh-token-gateway.d.ts +13 -0
- package/dist/runner/live/gh-token-gateway.js +51 -0
- package/dist/runner/live/sandbox-gateway.js +12 -2
- package/dist/runner/live/snapshot-records.js +10 -9
- package/dist/runner/local-snapshot-index.d.ts +11 -5
- package/dist/runner/local-snapshot-index.js +13 -14
- package/dist/runner/ready.d.ts +1 -1
- package/dist/runner/ready.js +1 -1
- package/dist/runner/scope.d.ts +5 -2
- package/dist/runner/scope.js +6 -2
- package/dist/runner/secrets.d.ts +37 -14
- package/dist/runner/secrets.js +218 -25
- package/dist/runner/session.js +3 -0
- package/dist/runner/shared-snapshot-entry.d.ts +3 -3
- package/dist/runner/shared-snapshot-entry.js +4 -4
- package/dist/runner/shared-snapshot-list.d.ts +1 -1
- package/dist/runner/shared-snapshot-list.js +1 -1
- package/dist/runner/shared-snapshot-lookup.d.ts +1 -1
- package/dist/runner/shared-snapshot-lookup.js +1 -1
- package/dist/runner/snapshot-build.js +54 -25
- package/dist/runner/snapshot-choice.js +1 -0
- package/dist/runner/snapshot-inspect.js +2 -5
- package/dist/runner/snapshot-key.d.ts +21 -7
- package/dist/runner/snapshot-key.js +31 -7
- package/dist/runner/snapshot-source.d.ts +31 -0
- package/dist/runner/snapshot-source.js +122 -0
- package/dist/runner/vercel-sandbox-check.d.ts +2 -0
- package/dist/runner/vercel-sandbox-check.js +6 -2
- package/dist/runner/vercel-sandbox-options.d.ts +36 -6
- package/dist/runner/vercel-sandbox-options.js +62 -19
- package/dist/runner/vercel-sandbox-secrets.d.ts +55 -6
- package/dist/runner/vercel-sandbox-secrets.js +142 -9
- package/dist/sdk/extension/commands.d.ts +3 -8
- package/dist/sdk/extension/commands.js +1 -3
- package/package.json +4 -3
- package/skills/overview.md +1 -1
- package/dist/application.d.ts +0 -30
- package/dist/application.js +0 -41
- package/dist/bin/run.d.ts +0 -18
- package/dist/bin/run.js +0 -31
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// commits, and for the checkout's runner which one a run here starts from and why not from each other one. It reads
|
|
3
3
|
// the local snapshot index and Git, and changes nothing: no file is removed, nothing is minted, and no sandbox starts.
|
|
4
4
|
import { resolveBase } from "./base.js";
|
|
5
|
-
import { classifySnapshotEntries, isExpiredEntry, pickSnapshot, resolveAncestorDistances, } from "./local-snapshot-index.js";
|
|
5
|
+
import { classifySnapshotEntries, isExpiredEntry, matchesRunnerTarget, pickSnapshot, resolveAncestorDistances, } from "./local-snapshot-index.js";
|
|
6
6
|
import { snapshotInputsAt } from "./snapshot-key.js";
|
|
7
7
|
export async function inspectLocalSnapshotIndex(context, request) {
|
|
8
8
|
const { checkout, runnerSnapshots } = context;
|
|
@@ -12,10 +12,7 @@ export async function inspectLocalSnapshotIndex(context, request) {
|
|
|
12
12
|
return { kind: "local-index-unreadable", ...listed.failure };
|
|
13
13
|
const { directory, entries, unreadable } = listed.value;
|
|
14
14
|
const now = context.clock.now();
|
|
15
|
-
const ofRunner = (entry) => options !== undefined &&
|
|
16
|
-
entry.runnerName === options.name &&
|
|
17
|
-
entry.region === options.region &&
|
|
18
|
-
entry.runtime === options.runtime;
|
|
15
|
+
const ofRunner = (entry) => options !== undefined && matchesRunnerTarget(entry, options);
|
|
19
16
|
const shows = (entry) => request.all || options === undefined || ofRunner(entry);
|
|
20
17
|
const shown = entries.filter(shows);
|
|
21
18
|
const root = await checkout.repositoryRoot({ cwd: request.cwd });
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { CheckoutGateway } from "./gateways.ts";
|
|
2
|
+
import type { SnapshotSource } from "./snapshot-source.ts";
|
|
2
3
|
import { type CheckedVercelSandboxOptions, type RunnerStep } from "./vercel-sandbox-options.ts";
|
|
3
4
|
/**
|
|
4
5
|
* Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
|
|
5
6
|
* uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
|
|
6
7
|
* runner secret names. 3 dropped dev snapshots. 4 replaced per-step runner secret names with the runner's credential
|
|
7
|
-
* source identities (`credentials=`). 5 added declared base files' paths and contents (`baseFiles=`).
|
|
8
|
+
* source identities (`credentials=`). 5 added declared base files' paths and contents (`baseFiles=`). 6 switched
|
|
9
|
+
* Vercel Sandbox runners from legacy runtimes to VCR images (`image`).
|
|
8
10
|
*/
|
|
9
|
-
export declare const SNAPSHOT_FORMAT =
|
|
11
|
+
export declare const SNAPSHOT_FORMAT = 6;
|
|
10
12
|
/** One declared base file read from the base commit, to stage into `/vercel/sandbox/<path>` before toolchain steps. */
|
|
11
13
|
export interface DeclaredBaseFile {
|
|
12
14
|
readonly path: string;
|
|
@@ -29,10 +31,18 @@ export declare function bashScript(lines: readonly string[], root?: string): str
|
|
|
29
31
|
* (`<staging>/base-files`), before the prebuild steps. `git add -A` would drop tracked files `.gitignore` matches.
|
|
30
32
|
*/
|
|
31
33
|
export declare function baseIndexScript(base: string, staging: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Fetches `base` alone from `url` (`normalizeGitFetchUrl`, `snapshot-source.ts`) into the repository at `root` and checks
|
|
36
|
+
* it out, for `snapshot.source: { kind: "git-fetch" }`, before the prebuild steps. The checkout's `--force` overwrites
|
|
37
|
+
* the declared base files already placed there, which hold the same text. `--depth 1` makes `base` the root commit, so
|
|
38
|
+
* `applyScript` resets to it as it resets to an archive snapshot's root commit. No credential helper or terminal prompt
|
|
39
|
+
* runs: a credential reaches the fetch's requests only through the firewall.
|
|
40
|
+
*/
|
|
41
|
+
export declare function gitFetchBaseIndexScript(url: string, base: string, root?: string): string;
|
|
32
42
|
/**
|
|
33
43
|
* Applies and commits a run's patch and untracked files, uploaded to `staging`, in a runner sandbox. It first resets
|
|
34
|
-
* the repository to its root commit, which holds the base's tracked files (`baseIndexScript
|
|
35
|
-
*
|
|
44
|
+
* the repository to its root commit, which holds the base's tracked files (`baseIndexScript`, or the base itself after
|
|
45
|
+
* `gitFetchBaseIndexScript`), since the base's history isn't in a sandbox's repository, and removes untracked files and nested Git repositories `.gitignore`
|
|
36
46
|
* doesn't match, keeping ignored ones such as `node_modules` and build outputs. `root` is the repository, which an
|
|
37
47
|
* integration test points at a temporary checkout.
|
|
38
48
|
*/
|
|
@@ -40,8 +50,10 @@ export declare function applyScript(staging: string, root?: string): string;
|
|
|
40
50
|
/**
|
|
41
51
|
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, `credentials=<the secret source identities the runner's
|
|
42
52
|
* credentials read, sorted, once each, joined with ",">`, `baseFiles=<count>` followed by each sorted declared base
|
|
43
|
-
* file's path and text, each toolchain step's label and script, the base-index script
|
|
44
|
-
*
|
|
53
|
+
* file's path and text, each toolchain step's label and script, the base-index script the build runs (`baseIndexScript`
|
|
54
|
+
* with the placeholders `<base>` and `<staging>`, or for `snapshot.source: { kind: "git-fetch" }`
|
|
55
|
+
* `gitFetchBaseIndexScript` with `<url>` and `<base>`, so the remote's URL and name stay out of the key and machines
|
|
56
|
+
* with SSH and HTTPS remotes share one), and each prebuild step's label and script, joined with NUL. A runner without credentials gives
|
|
45
57
|
* `credentials=`, and one without declared base files gives `baseFiles=0`. Every snapshot step gets every credential,
|
|
46
58
|
* so the source identities are in the key once, never the values, domains, or headers: a runner that reads another
|
|
47
59
|
* source builds another snapshot, and every machine with the same runner options shares one. The base isn't in the
|
|
@@ -53,6 +65,7 @@ export declare function snapshotKey(steps: {
|
|
|
53
65
|
readonly baseFiles: readonly DeclaredBaseFile[];
|
|
54
66
|
readonly toolchains: readonly RunnerStep[];
|
|
55
67
|
readonly prebuild: readonly RunnerStep[];
|
|
68
|
+
readonly source?: SnapshotSource | undefined;
|
|
56
69
|
}): string;
|
|
57
70
|
/** A runner's snapshot inputs at one base and their key, or why a declared base file couldn't be read there. */
|
|
58
71
|
export type SnapshotInputsAt = {
|
|
@@ -73,7 +86,8 @@ export declare function snapshotInputsAt(checkout: CheckoutGateway, request: {
|
|
|
73
86
|
readonly repoRoot: string;
|
|
74
87
|
readonly base: string;
|
|
75
88
|
readonly options: {
|
|
76
|
-
readonly snapshot: Pick<CheckedVercelSandboxOptions["snapshot"], "toolchains" | "prebuild">;
|
|
89
|
+
readonly snapshot: Pick<CheckedVercelSandboxOptions["snapshot"], "toolchains" | "prebuild" | "source">;
|
|
77
90
|
readonly credentials: CheckedVercelSandboxOptions["credentials"];
|
|
91
|
+
readonly managedCredentials?: CheckedVercelSandboxOptions["managedCredentials"];
|
|
78
92
|
};
|
|
79
93
|
}): Promise<SnapshotInputsAt>;
|
|
@@ -8,9 +8,10 @@ import { credentialSourceIds, declaredBaseFilePaths, } from "./vercel-sandbox-op
|
|
|
8
8
|
* Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
|
|
9
9
|
* uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
|
|
10
10
|
* runner secret names. 3 dropped dev snapshots. 4 replaced per-step runner secret names with the runner's credential
|
|
11
|
-
* source identities (`credentials=`). 5 added declared base files' paths and contents (`baseFiles=`).
|
|
11
|
+
* source identities (`credentials=`). 5 added declared base files' paths and contents (`baseFiles=`). 6 switched
|
|
12
|
+
* Vercel Sandbox runners from legacy runtimes to VCR images (`image`).
|
|
12
13
|
*/
|
|
13
|
-
export const SNAPSHOT_FORMAT =
|
|
14
|
+
export const SNAPSHOT_FORMAT = 6;
|
|
14
15
|
/** Where the repository lives in every runner and build sandbox. */
|
|
15
16
|
export const SANDBOX_ROOT = "/vercel/sandbox";
|
|
16
17
|
/** The names of the files uploaded to a sandbox's staging directory. */
|
|
@@ -23,6 +24,10 @@ export const STAGED_FILES = {
|
|
|
23
24
|
};
|
|
24
25
|
/** The identity of the commits the scripts make, with no hook or signing in the way. */
|
|
25
26
|
const GIT_IDENTITY = "-c user.email=storm-runner@vercel.invalid -c user.name='storm runner' -c commit.gpgsign=false";
|
|
27
|
+
/** POSIX single-quotes `value` so it passes literally through bash without expansion. */
|
|
28
|
+
function shellQuote(value) {
|
|
29
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
30
|
+
}
|
|
26
31
|
/** A bash script that stops at the first failure and runs in the repository's root, `/vercel/sandbox` by default. */
|
|
27
32
|
export function bashScript(lines, root = SANDBOX_ROOT) {
|
|
28
33
|
return ["set -euo pipefail", `cd ${root}`, ...lines].join("\n");
|
|
@@ -43,10 +48,24 @@ export function baseIndexScript(base, staging) {
|
|
|
43
48
|
`git ${GIT_IDENTITY} commit -q --no-verify -m 'base ${base}'`,
|
|
44
49
|
]);
|
|
45
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetches `base` alone from `url` (`normalizeGitFetchUrl`, `snapshot-source.ts`) into the repository at `root` and checks
|
|
53
|
+
* it out, for `snapshot.source: { kind: "git-fetch" }`, before the prebuild steps. The checkout's `--force` overwrites
|
|
54
|
+
* the declared base files already placed there, which hold the same text. `--depth 1` makes `base` the root commit, so
|
|
55
|
+
* `applyScript` resets to it as it resets to an archive snapshot's root commit. No credential helper or terminal prompt
|
|
56
|
+
* runs: a credential reaches the fetch's requests only through the firewall.
|
|
57
|
+
*/
|
|
58
|
+
export function gitFetchBaseIndexScript(url, base, root = SANDBOX_ROOT) {
|
|
59
|
+
return bashScript([
|
|
60
|
+
"git -c init.defaultBranch=main init -q",
|
|
61
|
+
`GIT_TERMINAL_PROMPT=0 git -c credential.helper= -c core.autocrlf=false -c core.eol=lf fetch --depth 1 --no-tags -- ${shellQuote(url)} ${shellQuote(base)}`,
|
|
62
|
+
"git -c core.autocrlf=false -c core.eol=lf checkout --detach --force FETCH_HEAD",
|
|
63
|
+
], root);
|
|
64
|
+
}
|
|
46
65
|
/**
|
|
47
66
|
* Applies and commits a run's patch and untracked files, uploaded to `staging`, in a runner sandbox. It first resets
|
|
48
|
-
* the repository to its root commit, which holds the base's tracked files (`baseIndexScript
|
|
49
|
-
*
|
|
67
|
+
* the repository to its root commit, which holds the base's tracked files (`baseIndexScript`, or the base itself after
|
|
68
|
+
* `gitFetchBaseIndexScript`), since the base's history isn't in a sandbox's repository, and removes untracked files and nested Git repositories `.gitignore`
|
|
50
69
|
* doesn't match, keeping ignored ones such as `node_modules` and build outputs. `root` is the repository, which an
|
|
51
70
|
* integration test points at a temporary checkout.
|
|
52
71
|
*/
|
|
@@ -72,8 +91,10 @@ export function applyScript(staging, root = SANDBOX_ROOT) {
|
|
|
72
91
|
/**
|
|
73
92
|
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, `credentials=<the secret source identities the runner's
|
|
74
93
|
* credentials read, sorted, once each, joined with ",">`, `baseFiles=<count>` followed by each sorted declared base
|
|
75
|
-
* file's path and text, each toolchain step's label and script, the base-index script
|
|
76
|
-
*
|
|
94
|
+
* file's path and text, each toolchain step's label and script, the base-index script the build runs (`baseIndexScript`
|
|
95
|
+
* with the placeholders `<base>` and `<staging>`, or for `snapshot.source: { kind: "git-fetch" }`
|
|
96
|
+
* `gitFetchBaseIndexScript` with `<url>` and `<base>`, so the remote's URL and name stay out of the key and machines
|
|
97
|
+
* with SSH and HTTPS remotes share one), and each prebuild step's label and script, joined with NUL. A runner without credentials gives
|
|
77
98
|
* `credentials=`, and one without declared base files gives `baseFiles=0`. Every snapshot step gets every credential,
|
|
78
99
|
* so the source identities are in the key once, never the values, domains, or headers: a runner that reads another
|
|
79
100
|
* source builds another snapshot, and every machine with the same runner options shares one. The base isn't in the
|
|
@@ -90,7 +111,9 @@ export function snapshotKey(steps) {
|
|
|
90
111
|
`baseFiles=${baseFiles.length}`,
|
|
91
112
|
...baseFiles.flatMap(({ path, text: content }) => [path, content]),
|
|
92
113
|
...text(steps.toolchains),
|
|
93
|
-
|
|
114
|
+
steps.source === undefined
|
|
115
|
+
? baseIndexScript("<base>", "<staging>")
|
|
116
|
+
: gitFetchBaseIndexScript("<url>", "<base>"),
|
|
94
117
|
...text(steps.prebuild),
|
|
95
118
|
].join("\0"))
|
|
96
119
|
.digest("hex");
|
|
@@ -130,6 +153,7 @@ export async function snapshotInputsAt(checkout, request) {
|
|
|
130
153
|
baseFiles,
|
|
131
154
|
toolchains: snapshot.toolchains,
|
|
132
155
|
prebuild: snapshot.prebuild,
|
|
156
|
+
source: snapshot.source,
|
|
133
157
|
}),
|
|
134
158
|
};
|
|
135
159
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Report } from "./vercel-sandbox-check.ts";
|
|
2
|
+
/**
|
|
3
|
+
* How a build sandbox gets the base commit's tracked files: `{ kind: "git-fetch", remote? }` runs a shallow
|
|
4
|
+
* `git fetch --depth 1` of the base commit inside the build sandbox, from the HTTPS form of the URL that the local
|
|
5
|
+
* checkout's Git `remote` (`"origin"` by default) names, instead of archiving the base on the launch machine and
|
|
6
|
+
* uploading it. The remote must hold the base commit.
|
|
7
|
+
*/
|
|
8
|
+
export interface SnapshotSource {
|
|
9
|
+
readonly kind: "git-fetch";
|
|
10
|
+
/** The Git remote whose URL storm reads locally and turns into an HTTPS URL; `"origin"` by default. */
|
|
11
|
+
readonly remote?: string;
|
|
12
|
+
}
|
|
13
|
+
/** `snapshot.source` with its default filled in; `undefined` when absent, `false` after reporting a problem. */
|
|
14
|
+
export declare function checkSnapshotSource(value: unknown, report: Report): Required<SnapshotSource> | undefined | false;
|
|
15
|
+
/** The HTTPS URL a build sandbox fetches from, or what is wrong with the remote URL, worded to follow "the URL". */
|
|
16
|
+
export type GitFetchUrl = {
|
|
17
|
+
readonly ok: true;
|
|
18
|
+
readonly url: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly ok: false;
|
|
21
|
+
readonly problem: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Turns a local Git remote URL into the HTTPS URL a build sandbox fetches from: SCP-style SSH (`[user@]host:path`) and
|
|
25
|
+
* `ssh://[user@]host[:port]/path` become `https://host/path` (an SSH port is dropped, since it isn't the HTTPS port),
|
|
26
|
+
* and `https://host[:port]/path` stays as it is, with the host lowercased and port 443 dropped. It refuses any other
|
|
27
|
+
* scheme (`http`, `file`, `git`), a local path, user info on an HTTPS URL or a password on an SSH one, a query or
|
|
28
|
+
* fragment, whitespace, control characters, quotes, shell metacharacters, and a path with an empty, `.`, or `..`
|
|
29
|
+
* segment, `@`, or `:`. A problem never holds any part of the URL but its scheme, so a credential in it can't leak.
|
|
30
|
+
*/
|
|
31
|
+
export declare function normalizeGitFetchUrl(raw: string): GitFetchUrl;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// `snapshot.source` on a Vercel Sandbox runner: how a build sandbox gets the base commit's tracked files. This file holds
|
|
2
|
+
// the published type, its check (called from `checkVercelSandboxOptions`), and the normalization of the local Git
|
|
3
|
+
// remote's URL to the HTTPS URL the build sandbox fetches from. The fetch script is `gitFetchBaseIndexScript`
|
|
4
|
+
// (`snapshot-key.ts`), beside the archive's base-index script.
|
|
5
|
+
import { describeOptionValue, isRecord, reportUnknownKeys } from "./vercel-sandbox-check.js";
|
|
6
|
+
const SNAPSHOT_SOURCE_KEYS = new Set(["kind", "remote"]);
|
|
7
|
+
const DEFAULT_REMOTE = "origin";
|
|
8
|
+
/** A Git remote name storm accepts: letters, digits, `.`, `_`, `-`, and `/`, starting with a letter, digit, or `_`. */
|
|
9
|
+
const REMOTE_NAME_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9._/-]*$/;
|
|
10
|
+
/** `snapshot.source` with its default filled in; `undefined` when absent, `false` after reporting a problem. */
|
|
11
|
+
export function checkSnapshotSource(value, report) {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
const path = ["snapshot", "source"];
|
|
15
|
+
if (!isRecord(value)) {
|
|
16
|
+
// Do not echo string values: a user may mistakenly pass a clone URL that embeds credentials.
|
|
17
|
+
const actual = typeof value === "string" ? "a string" : describeOptionValue(value);
|
|
18
|
+
report(path, `must be { kind: "git-fetch", remote? }, not ${actual}`);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
let ok = reportUnknownKeys(value, SNAPSHOT_SOURCE_KEYS, path, "a vercelSandbox snapshot source key", report);
|
|
22
|
+
const kind = value["kind"];
|
|
23
|
+
if (kind !== "git-fetch") {
|
|
24
|
+
report([...path, "kind"], `must be "git-fetch", not ${describeOptionValue(kind)}`);
|
|
25
|
+
ok = false;
|
|
26
|
+
}
|
|
27
|
+
const remote = value["remote"] === undefined ? DEFAULT_REMOTE : value["remote"];
|
|
28
|
+
if (typeof remote !== "string" || !REMOTE_NAME_PATTERN.test(remote)) {
|
|
29
|
+
// Do not echo string values: a user may mistakenly pass a clone URL that embeds credentials.
|
|
30
|
+
const rule = 'must be a Git remote name such as "origin" (letters, digits, ".", "_", "-", and "/", starting with a letter, digit, or "_")';
|
|
31
|
+
report([...path, "remote"], typeof remote === "string" ? rule : `${rule}, not ${describeOptionValue(remote)}`);
|
|
32
|
+
ok = false;
|
|
33
|
+
}
|
|
34
|
+
return ok ? { kind: "git-fetch", remote: remote } : false;
|
|
35
|
+
}
|
|
36
|
+
/** Whitespace, quotes, shell metacharacters, and the URL query and fragment marks. */
|
|
37
|
+
const UNSAFE_URL_CHARS = /[\s'"`$\\;|&<>(){}[\]*?!#~]/;
|
|
38
|
+
/** `scheme://authority/path`. */
|
|
39
|
+
const SCHEME_URL_PATTERN = /^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/]*)(.*)$/;
|
|
40
|
+
/** SCP-style SSH, `[user@]host:path`, with no `/` before the colon, as Git reads it. */
|
|
41
|
+
const SCP_URL_PATTERN = /^(?:([^@/]*)@)?([^@/:]+):(.*)$/;
|
|
42
|
+
/** A schemed URL's host and optional port, `host[:port]`. */
|
|
43
|
+
const HOST_PORT_PATTERN = /^([^:]+)(?::(\d{1,5}))?$/;
|
|
44
|
+
/** A bare hostname with at least one dot: lowercase letters, digits, and inner hyphens. */
|
|
45
|
+
const HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
46
|
+
const CREDENTIALS_PROBLEM = "holds credentials; remove them from the remote URL and declare a sandbox credential in runner.credentials instead";
|
|
47
|
+
/**
|
|
48
|
+
* Turns a local Git remote URL into the HTTPS URL a build sandbox fetches from: SCP-style SSH (`[user@]host:path`) and
|
|
49
|
+
* `ssh://[user@]host[:port]/path` become `https://host/path` (an SSH port is dropped, since it isn't the HTTPS port),
|
|
50
|
+
* and `https://host[:port]/path` stays as it is, with the host lowercased and port 443 dropped. It refuses any other
|
|
51
|
+
* scheme (`http`, `file`, `git`), a local path, user info on an HTTPS URL or a password on an SSH one, a query or
|
|
52
|
+
* fragment, whitespace, control characters, quotes, shell metacharacters, and a path with an empty, `.`, or `..`
|
|
53
|
+
* segment, `@`, or `:`. A problem never holds any part of the URL but its scheme, so a credential in it can't leak.
|
|
54
|
+
*/
|
|
55
|
+
export function normalizeGitFetchUrl(raw) {
|
|
56
|
+
if (raw.length === 0)
|
|
57
|
+
return { ok: false, problem: "is empty" };
|
|
58
|
+
if (hasControlChar(raw) || UNSAFE_URL_CHARS.test(raw))
|
|
59
|
+
return { ok: false, problem: "holds whitespace, a control character, a quote, or a shell metacharacter" };
|
|
60
|
+
let https;
|
|
61
|
+
let userInfo;
|
|
62
|
+
let hostPort;
|
|
63
|
+
let host;
|
|
64
|
+
let port;
|
|
65
|
+
let path;
|
|
66
|
+
const schemed = SCHEME_URL_PATTERN.exec(raw);
|
|
67
|
+
if (schemed !== null) {
|
|
68
|
+
const scheme = (schemed[1] ?? "").toLowerCase();
|
|
69
|
+
if (scheme !== "https" && scheme !== "ssh")
|
|
70
|
+
return { ok: false, problem: `uses ${scheme}://; git-fetch takes an HTTPS or SSH remote` };
|
|
71
|
+
https = scheme === "https";
|
|
72
|
+
const authority = schemed[2] ?? "";
|
|
73
|
+
const at = authority.lastIndexOf("@");
|
|
74
|
+
userInfo = at === -1 ? undefined : authority.slice(0, at);
|
|
75
|
+
hostPort = at === -1 ? authority : authority.slice(at + 1);
|
|
76
|
+
host = "";
|
|
77
|
+
path = schemed[3] ?? "";
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const scp = SCP_URL_PATTERN.exec(raw);
|
|
81
|
+
if (scp === null)
|
|
82
|
+
return { ok: false, problem: "is not an HTTPS or SSH Git URL" };
|
|
83
|
+
https = false;
|
|
84
|
+
[, userInfo, host = "", path = ""] = scp;
|
|
85
|
+
if (!path.startsWith("/"))
|
|
86
|
+
path = `/${path}`;
|
|
87
|
+
}
|
|
88
|
+
if (userInfo !== undefined && (https || userInfo.includes(":") || userInfo.includes("@")))
|
|
89
|
+
return { ok: false, problem: CREDENTIALS_PROBLEM };
|
|
90
|
+
if (hostPort !== undefined) {
|
|
91
|
+
const parsed = HOST_PORT_PATTERN.exec(hostPort);
|
|
92
|
+
if (parsed === null)
|
|
93
|
+
return { ok: false, problem: "names no valid host or port" };
|
|
94
|
+
[, host = "", port] = parsed;
|
|
95
|
+
}
|
|
96
|
+
host = host.toLowerCase();
|
|
97
|
+
if (!HOST_PATTERN.test(host))
|
|
98
|
+
return { ok: false, problem: "names no valid host" };
|
|
99
|
+
if (port !== undefined && (Number(port) < 1 || Number(port) > 65_535))
|
|
100
|
+
return { ok: false, problem: "names no valid port" };
|
|
101
|
+
if (!isRepositoryPath(path))
|
|
102
|
+
return { ok: false, problem: "names no valid repository path" };
|
|
103
|
+
const httpsPort = https && port !== undefined && Number(port) !== 443 ? `:${Number(port)}` : "";
|
|
104
|
+
return { ok: true, url: `https://${host}${httpsPort}${path}` };
|
|
105
|
+
}
|
|
106
|
+
function hasControlChar(value) {
|
|
107
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
108
|
+
const code = value.charCodeAt(index);
|
|
109
|
+
if (code <= 0x1f || code === 0x7f)
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
/** `/a/b`: one or more segments, none empty, `.`, or `..`, and no `@` or `:`. */
|
|
115
|
+
function isRepositoryPath(path) {
|
|
116
|
+
if (!path.startsWith("/") || path.includes("@") || path.includes(":"))
|
|
117
|
+
return false;
|
|
118
|
+
return path
|
|
119
|
+
.slice(1)
|
|
120
|
+
.split("/")
|
|
121
|
+
.every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
122
|
+
}
|
|
@@ -4,3 +4,5 @@ export type Report = (path: readonly string[], problem: string) => void;
|
|
|
4
4
|
export declare function reportUnknownKeys(value: Readonly<Record<string, unknown>>, known: ReadonlySet<string>, path: readonly string[], what: string, report: Report): boolean;
|
|
5
5
|
/** A value as a problem names it: a string or number as written, otherwise its kind. */
|
|
6
6
|
export declare function describeOptionValue(value: unknown): string;
|
|
7
|
+
/** Whether `value` is an object that isn't an array or null, the shape every option object takes. */
|
|
8
|
+
export declare function isRecord(value: unknown): value is Readonly<Record<string, unknown>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Pure problem-reporting helpers shared by `vercel-sandbox-options.ts
|
|
2
|
-
// `checkVercelSandboxOptions`.
|
|
1
|
+
// Pure problem-reporting helpers shared by `vercel-sandbox-options.ts`, `vercel-sandbox-secrets.ts`, and
|
|
2
|
+
// `snapshot-source.ts` during `checkVercelSandboxOptions`.
|
|
3
3
|
/** Reports each key of `value` not in `known`; whether there were none. */
|
|
4
4
|
export function reportUnknownKeys(value, known, path, what, report) {
|
|
5
5
|
let ok = true;
|
|
@@ -28,3 +28,7 @@ export function describeOptionValue(value) {
|
|
|
28
28
|
return "an object";
|
|
29
29
|
return `a ${typeof value}`;
|
|
30
30
|
}
|
|
31
|
+
/** Whether `value` is an object that isn't an array or null, the shape every option object takes. */
|
|
32
|
+
export function isRecord(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RunTestPlan } from "../sdk/extension/index.ts";
|
|
2
|
-
import { type
|
|
3
|
-
|
|
2
|
+
import { type SnapshotSource } from "./snapshot-source.ts";
|
|
3
|
+
import { type CredentialDeclaration, credentialSourceIds, type GhCredentialSource, type GhTokenFormat, type ManagedCredential, type SandboxCredentialSource, type UnsafeSecretEnvVar } from "./vercel-sandbox-secrets.ts";
|
|
4
|
+
export { type CredentialDeclaration, credentialSourceIds, type GhCredentialSource, type GhTokenFormat, type ManagedCredential, type SandboxCredentialSource, type SnapshotSource, type UnsafeSecretEnvVar, };
|
|
4
5
|
/** A bash script, run with `bash -lc` in the repository's root, and the label that names it in progress and errors. */
|
|
5
6
|
export interface RunnerStep {
|
|
6
7
|
readonly label: string;
|
|
@@ -39,6 +40,12 @@ export interface VercelSandboxOptions {
|
|
|
39
40
|
readonly vcpus: number;
|
|
40
41
|
/** A few words on what a snapshot build does; by default the steps' labels. */
|
|
41
42
|
readonly summary?: string;
|
|
43
|
+
/**
|
|
44
|
+
* How the build sandbox gets the base commit's tracked files. When omitted, storm archives the base on the launch
|
|
45
|
+
* machine and uploads it; with `{ kind: "git-fetch", remote? }`, the build sandbox fetches the base commit over
|
|
46
|
+
* HTTPS from the URL of the local checkout's Git `remote` (`"origin"` by default), with the runner's credentials.
|
|
47
|
+
*/
|
|
48
|
+
readonly source?: SnapshotSource;
|
|
42
49
|
/** Steps run before the base's files are committed in the build sandbox. They must put `git` on `PATH`. */
|
|
43
50
|
readonly toolchains: readonly ToolchainStep[];
|
|
44
51
|
/**
|
|
@@ -75,6 +82,17 @@ export interface VercelSandboxOptions {
|
|
|
75
82
|
* several domains.
|
|
76
83
|
*/
|
|
77
84
|
readonly credentials?: readonly CredentialDeclaration[];
|
|
85
|
+
/**
|
|
86
|
+
* Vercel-managed sandbox credentials passed to `Sandbox.create({ credentials })` for both build and runner
|
|
87
|
+
* sandboxes: `"npm"` passes `{ npm: true }`, so Vercel Sandbox resolves `NPM_RC` or `NPM_TOKEN` from the project's
|
|
88
|
+
* or team's Vercel environment variables, writes a credential-free `~/.npmrc` inside the sandbox, and injects the
|
|
89
|
+
* read-only auth header at the firewall without any token ever sitting on the launch machine or inside the sandbox.
|
|
90
|
+
* Included in the snapshot key (`managed:npm`). Cannot be combined with a `runner.credentials` entry setting
|
|
91
|
+
* `authorization` on `registry.npmjs.org` (which overrides the managed token), and refuses `keepSandbox` or
|
|
92
|
+
* `--keep-sandbox` above `0` because Vercel Sandbox rejects `deny-all` on a sandbox with managed credentials. When
|
|
93
|
+
* `allowedDomains` is set, it must allow the managed npm registries (such as `registry.npmjs.org`).
|
|
94
|
+
*/
|
|
95
|
+
readonly managedCredentials?: readonly ManagedCredential[];
|
|
78
96
|
/**
|
|
79
97
|
* An escape hatch for credentials that cannot travel as HTTPS headers, such as a database password, a client key,
|
|
80
98
|
* or a token a tool reads from an environment variable. Each entry (`UnsafeSecretEnvVar`) pairs the environment
|
|
@@ -113,8 +131,12 @@ export interface VercelSandboxOptions {
|
|
|
113
131
|
readonly baseRefs?: readonly string[];
|
|
114
132
|
/** The Vercel region of the runner sandbox and its snapshots; `iad1` by default. */
|
|
115
133
|
readonly region?: string;
|
|
116
|
-
/**
|
|
117
|
-
|
|
134
|
+
/**
|
|
135
|
+
* The Vercel Sandbox VCR image to build and run in; `"vercel/sandbox/node:al-24"` by default.
|
|
136
|
+
* Accepts Vercel-managed images (`"vercel/sandbox/..."`, with or without a leading `"vcr.vercel.com/"`) or
|
|
137
|
+
* digest-pinned custom VCR image references (`"<repository>@sha256:<64 lowercase hex characters>"`).
|
|
138
|
+
*/
|
|
139
|
+
readonly image?: string;
|
|
118
140
|
/**
|
|
119
141
|
* How many runner sandboxes a run from this config file can have. Without it, no run is across runner sandboxes:
|
|
120
142
|
* `--sandboxes` and `--file-lists` refuse and name this key. A run with no runner ignores it.
|
|
@@ -169,10 +191,13 @@ export declare const VERCEL_SANDBOX_DEFAULTS: {
|
|
|
169
191
|
readonly timeout: "60m";
|
|
170
192
|
readonly baseRefs: readonly ["main", "origin/main"];
|
|
171
193
|
readonly region: "iad1";
|
|
172
|
-
readonly
|
|
194
|
+
readonly image: "vercel/sandbox/node:al-24";
|
|
173
195
|
};
|
|
174
196
|
/** Vercel Sandbox runner options that passed `checkVercelSandboxOptions`, with every optional key's default filled in. */
|
|
175
197
|
export interface CheckedVercelSandboxOptions extends VercelSandboxOptions {
|
|
198
|
+
readonly snapshot: Omit<VercelSandboxOptions["snapshot"], "source"> & {
|
|
199
|
+
readonly source?: Required<SnapshotSource>;
|
|
200
|
+
};
|
|
176
201
|
readonly run: {
|
|
177
202
|
readonly install: RunnerStep;
|
|
178
203
|
readonly build: RunnerStep;
|
|
@@ -184,6 +209,11 @@ export interface CheckedVercelSandboxOptions extends VercelSandboxOptions {
|
|
|
184
209
|
* absent. `credentialSourceIds` gives their sorted, unique source identities.
|
|
185
210
|
*/
|
|
186
211
|
readonly credentials: readonly Required<CredentialDeclaration>[];
|
|
212
|
+
/**
|
|
213
|
+
* The Vercel-managed sandbox credentials passed when creating build and runner sandboxes, in the runner's order;
|
|
214
|
+
* empty when absent.
|
|
215
|
+
*/
|
|
216
|
+
readonly managedCredentials: readonly ManagedCredential[];
|
|
187
217
|
/**
|
|
188
218
|
* The unsafe secret environment variables passed into the command's environment, in the runner's order; empty when
|
|
189
219
|
* absent.
|
|
@@ -196,7 +226,7 @@ export interface CheckedVercelSandboxOptions extends VercelSandboxOptions {
|
|
|
196
226
|
readonly keepSandboxMinutes: number | undefined;
|
|
197
227
|
readonly baseRefs: readonly string[];
|
|
198
228
|
readonly region: string;
|
|
199
|
-
readonly
|
|
229
|
+
readonly image: string;
|
|
200
230
|
}
|
|
201
231
|
/**
|
|
202
232
|
* One thing wrong with Vercel Sandbox runner options: the key path inside them (`["snapshot", "vcpus"]`; empty for
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
// (no functions), and the module names no resource.
|
|
5
5
|
import { parseKeepTime, parseTtl } from "../time/index.js";
|
|
6
6
|
import { RUN_PAYLOAD_VARIABLE } from "../sdk/run/launcher.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
7
|
+
import { checkSnapshotSource } from "./snapshot-source.js";
|
|
8
|
+
import { describeOptionValue, isRecord, reportUnknownKeys } from "./vercel-sandbox-check.js";
|
|
9
|
+
import { checkCredentials, checkManagedCredentials, checkUnsafeSecretEnvVars, credentialSourceIds, } from "./vercel-sandbox-secrets.js";
|
|
10
|
+
export { credentialSourceIds, };
|
|
10
11
|
/**
|
|
11
12
|
* storm's own limit on the number of runner sandboxes, which `runner.sandboxes.max` can't pass: a guard against a
|
|
12
13
|
* typing mistake that would start hundreds of runner sandboxes, not a claim about what Vercel Sandbox holds.
|
|
@@ -18,7 +19,7 @@ export const VERCEL_SANDBOX_DEFAULTS = {
|
|
|
18
19
|
timeout: "60m",
|
|
19
20
|
baseRefs: ["main", "origin/main"],
|
|
20
21
|
region: "iad1",
|
|
21
|
-
|
|
22
|
+
image: "vercel/sandbox/node:al-24",
|
|
22
23
|
};
|
|
23
24
|
const VERCEL_SANDBOX_OPTION_KEYS = new Set([
|
|
24
25
|
"name",
|
|
@@ -28,23 +29,30 @@ const VERCEL_SANDBOX_OPTION_KEYS = new Set([
|
|
|
28
29
|
"vcpus",
|
|
29
30
|
"env",
|
|
30
31
|
"credentials",
|
|
32
|
+
"managedCredentials",
|
|
31
33
|
"unsafeSecretEnvVars",
|
|
32
34
|
"allowedDomains",
|
|
33
35
|
"timeout",
|
|
34
36
|
"keepSandbox",
|
|
35
37
|
"baseRefs",
|
|
36
38
|
"region",
|
|
37
|
-
"
|
|
39
|
+
"image",
|
|
38
40
|
"sandboxes",
|
|
39
41
|
]);
|
|
40
42
|
const SANDBOXES_KEYS = new Set(["max", "default"]);
|
|
41
43
|
const SANDBOXES_DEFAULT_RULE_KEYS = new Set(["filesPerSandbox", "max"]);
|
|
42
44
|
const VCPUS_RULE_KEYS = new Set(["resource", "option", "per", "min", "max"]);
|
|
43
|
-
const SNAPSHOT_KEYS = new Set(["vcpus", "summary", "toolchains", "prebuild"]);
|
|
45
|
+
const SNAPSHOT_KEYS = new Set(["vcpus", "summary", "source", "toolchains", "prebuild"]);
|
|
44
46
|
const RUN_KEYS = new Set(["install", "build"]);
|
|
45
47
|
const STEP_KEYS = new Set(["label", "script"]);
|
|
46
48
|
const TOOLCHAIN_STEP_KEYS = new Set(["label", "script", "baseFiles"]);
|
|
47
49
|
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
50
|
+
/** Optional VCR registry host prefix on a fully qualified image reference. */
|
|
51
|
+
const VCR_HOST_PREFIX = "vcr.vercel.com/";
|
|
52
|
+
/** Prefix for Vercel-managed sandbox images (with or without `VCR_HOST_PREFIX`). */
|
|
53
|
+
const MANAGED_IMAGE_PREFIX = "vercel/sandbox/";
|
|
54
|
+
/** Digest suffix on a pinned image reference: `sha256:` followed by 64 lowercase hex characters. */
|
|
55
|
+
const IMAGE_DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
48
56
|
/** A domain the runner's `allowedDomains` lists: a bare hostname, or one with a leading `*.`. */
|
|
49
57
|
const ALLOWED_DOMAIN_PATTERN = /^(?:\*\.)?(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
50
58
|
/**
|
|
@@ -71,6 +79,7 @@ export function checkVercelSandboxOptions(value) {
|
|
|
71
79
|
const vcpus = checkVcpus(value["vcpus"], report);
|
|
72
80
|
const env = checkEnv(value["env"], report);
|
|
73
81
|
const credentials = checkCredentials(value["credentials"], report);
|
|
82
|
+
const managedCredentials = checkManagedCredentials(value["managedCredentials"], credentials, report);
|
|
74
83
|
const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials, report);
|
|
75
84
|
const allowedDomains = checkAllowedDomains(value["allowedDomains"], report);
|
|
76
85
|
const timeout = orDefault(value["timeout"], VERCEL_SANDBOX_DEFAULTS.timeout);
|
|
@@ -81,18 +90,17 @@ export function checkVercelSandboxOptions(value) {
|
|
|
81
90
|
const keepSandboxMinutes = typeof keepSandbox === "string" ? parseKeepTime(keepSandbox) : undefined;
|
|
82
91
|
if (keepSandbox !== undefined && keepSandboxMinutes === undefined)
|
|
83
92
|
report(["keepSandbox"], `must be 0, or a whole number of minutes or hours up to 5h, not ${describeOptionValue(keepSandbox)}`);
|
|
84
|
-
else if (
|
|
85
|
-
unsafeSecretEnvVars.length > 0
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
else if (keepSandboxMinutes !== undefined && keepSandboxMinutes > 0) {
|
|
94
|
+
if (unsafeSecretEnvVars !== undefined && unsafeSecretEnvVars.length > 0)
|
|
95
|
+
report(["keepSandbox"], "can't be above 0 when runner.unsafeSecretEnvVars is set: a run that passes secrets into the runner sandbox's environment never keeps its runner sandbox");
|
|
96
|
+
if (managedCredentials !== undefined && managedCredentials.length > 0)
|
|
97
|
+
report(["keepSandbox"], "can't be above 0 when runner.managedCredentials is set: Vercel Sandbox rejects deny-all on a sandbox with managed credentials, so storm cannot fence a kept runner sandbox");
|
|
98
|
+
}
|
|
89
99
|
const baseRefs = checkBaseRefs(value["baseRefs"], report);
|
|
90
100
|
const region = orDefault(value["region"], VERCEL_SANDBOX_DEFAULTS.region);
|
|
91
101
|
if (!isNonEmptyString(region))
|
|
92
102
|
report(["region"], `must be a non-empty string, not ${describeOptionValue(region)}`);
|
|
93
|
-
const
|
|
94
|
-
if (!isNonEmptyString(runtime))
|
|
95
|
-
report(["runtime"], `must be a non-empty string, not ${describeOptionValue(runtime)}`);
|
|
103
|
+
const image = checkImage(orDefault(value["image"], VERCEL_SANDBOX_DEFAULTS.image), report);
|
|
96
104
|
const sandboxes = checkSandboxes(value["sandboxes"], report);
|
|
97
105
|
if (problems.length > 0 ||
|
|
98
106
|
snapshot === undefined ||
|
|
@@ -100,10 +108,12 @@ export function checkVercelSandboxOptions(value) {
|
|
|
100
108
|
vcpus === undefined ||
|
|
101
109
|
env === undefined ||
|
|
102
110
|
credentials === undefined ||
|
|
111
|
+
managedCredentials === undefined ||
|
|
103
112
|
unsafeSecretEnvVars === undefined ||
|
|
104
113
|
allowedDomains === null ||
|
|
105
114
|
baseRefs === undefined ||
|
|
106
115
|
timeoutMinutes === undefined ||
|
|
116
|
+
image === undefined ||
|
|
107
117
|
sandboxes === false)
|
|
108
118
|
return { ok: false, problems };
|
|
109
119
|
return {
|
|
@@ -116,6 +126,7 @@ export function checkVercelSandboxOptions(value) {
|
|
|
116
126
|
vcpus,
|
|
117
127
|
env,
|
|
118
128
|
credentials,
|
|
129
|
+
managedCredentials,
|
|
119
130
|
unsafeSecretEnvVars,
|
|
120
131
|
...(allowedDomains === undefined ? {} : { allowedDomains }),
|
|
121
132
|
timeout: timeout,
|
|
@@ -123,11 +134,44 @@ export function checkVercelSandboxOptions(value) {
|
|
|
123
134
|
keepSandboxMinutes,
|
|
124
135
|
baseRefs,
|
|
125
136
|
region: region,
|
|
126
|
-
|
|
137
|
+
image,
|
|
127
138
|
...(sandboxes === undefined ? {} : { sandboxes }),
|
|
128
139
|
},
|
|
129
140
|
};
|
|
130
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Validates `runner.image`: a non-empty string with no whitespace, either a Vercel-managed image starting with
|
|
144
|
+
* `"vercel/sandbox/"` or `"vcr.vercel.com/vercel/sandbox/"` (with a non-empty suffix) or a custom VCR image reference
|
|
145
|
+
* pinned with `@sha256:<64 hex>`. A reference that names a digest, managed or custom, must name a well-formed one. The
|
|
146
|
+
* rest of the reference's grammar is Vercel Sandbox's to check when the build sandbox starts.
|
|
147
|
+
*/
|
|
148
|
+
function checkImage(value, report) {
|
|
149
|
+
if (!isNonEmptyString(value)) {
|
|
150
|
+
report(["image"], `must be a non-empty string, not ${describeOptionValue(value)}`);
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
if (/\s/.test(value)) {
|
|
154
|
+
report(["image"], `must be an image reference with no whitespace, not ${describeOptionValue(value)}`);
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
const at = value.indexOf("@");
|
|
158
|
+
const name = at === -1 ? value : value.slice(0, at);
|
|
159
|
+
const digest = at === -1 ? undefined : value.slice(at + 1);
|
|
160
|
+
if (digest !== undefined && (name === "" || !IMAGE_DIGEST_PATTERN.test(digest))) {
|
|
161
|
+
report(["image"], `must be "<repository>@sha256:<64 lowercase hex characters>" when it names a digest, not ${describeOptionValue(value)}`);
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const repo = name.startsWith(VCR_HOST_PREFIX) ? name.slice(VCR_HOST_PREFIX.length) : name;
|
|
165
|
+
if (repo === MANAGED_IMAGE_PREFIX) {
|
|
166
|
+
report(["image"], `must name a Vercel-managed image after "${MANAGED_IMAGE_PREFIX}", not ${describeOptionValue(value)}`);
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
if (digest === undefined && !repo.startsWith(MANAGED_IMAGE_PREFIX)) {
|
|
170
|
+
report(["image"], `must be a Vercel-managed image ("${MANAGED_IMAGE_PREFIX}...") or a digest-pinned custom VCR image ("<repository>@sha256:...") so runner snapshots cannot go stale, not ${describeOptionValue(value)}`);
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
131
175
|
function checkVcpus(value, report) {
|
|
132
176
|
if (isPositiveInteger(value))
|
|
133
177
|
return value;
|
|
@@ -258,13 +302,15 @@ function checkSnapshot(value, report) {
|
|
|
258
302
|
report(["snapshot", "summary"], `must be a non-empty string, not ${describeOptionValue(summary)}`);
|
|
259
303
|
ok = false;
|
|
260
304
|
}
|
|
305
|
+
const source = checkSnapshotSource(value["source"], report);
|
|
261
306
|
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], true, report);
|
|
262
307
|
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], false, report);
|
|
263
|
-
if (!ok || toolchains === undefined || prebuild === undefined)
|
|
308
|
+
if (!ok || source === false || toolchains === undefined || prebuild === undefined)
|
|
264
309
|
return undefined;
|
|
265
310
|
return {
|
|
266
311
|
vcpus: vcpus,
|
|
267
312
|
...(summary === undefined ? {} : { summary: summary }),
|
|
313
|
+
...(source === undefined ? {} : { source }),
|
|
268
314
|
toolchains,
|
|
269
315
|
prebuild,
|
|
270
316
|
};
|
|
@@ -488,9 +534,6 @@ export function resolveSandboxCountDefault(sandboxesDefault, testPlan) {
|
|
|
488
534
|
function orDefault(value, fallback) {
|
|
489
535
|
return value === undefined ? fallback : value;
|
|
490
536
|
}
|
|
491
|
-
function isRecord(value) {
|
|
492
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
493
|
-
}
|
|
494
537
|
function isNonEmptyString(value) {
|
|
495
538
|
return typeof value === "string" && value.length > 0;
|
|
496
539
|
}
|