@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
package/dist/runner/scope.js
CHANGED
|
@@ -25,6 +25,9 @@ export const KEEP_RUNNING_LIMIT_MS = 60_000;
|
|
|
25
25
|
* `RunnerSandboxScope` and `README.md` for each method's contract.
|
|
26
26
|
*/
|
|
27
27
|
export function runnerSandboxScope(context, progress, settings) {
|
|
28
|
+
const managedCredentials = settings.managedCredentials ?? [];
|
|
29
|
+
if (managedCredentials.length > 0 && settings.keepMs > 0)
|
|
30
|
+
throw new Error("a sandbox scope with managedCredentials can't keep its runner sandbox");
|
|
28
31
|
const { runnerSandboxes: sandboxes, timer, clock } = context;
|
|
29
32
|
let phase = { kind: "open", sandboxes: new Map(), creating: new Set() };
|
|
30
33
|
const saving = new Set();
|
|
@@ -288,9 +291,10 @@ export function runnerSandboxScope(context, progress, settings) {
|
|
|
288
291
|
onSignal();
|
|
289
292
|
else
|
|
290
293
|
settings.signal.addEventListener("abort", onSignal, { once: true });
|
|
294
|
+
const managed = managedCredentials.length === 0 ? {} : { managedCredentials };
|
|
291
295
|
return {
|
|
292
|
-
startBuildSandbox: (access, request) => owned(() => sandboxes.startBuildSandbox(access, { ...request, networkPolicy: settings.basePolicy })),
|
|
293
|
-
startRunnerSandbox: (access, request) => owned(() => sandboxes.startRunnerSandbox(access, { ...request, networkPolicy: settings.basePolicy }), true),
|
|
296
|
+
startBuildSandbox: (access, request) => owned(() => sandboxes.startBuildSandbox(access, { ...request, networkPolicy: settings.basePolicy, ...managed })),
|
|
297
|
+
startRunnerSandbox: (access, request) => owned(() => sandboxes.startRunnerSandbox(access, { ...request, networkPolicy: settings.basePolicy, ...managed }), true),
|
|
294
298
|
grantCredentials,
|
|
295
299
|
revokeCredentials,
|
|
296
300
|
saveSnapshot: (sandbox, request) => track(saving, (async () => {
|
package/dist/runner/secrets.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SandboxCredential, SECRET_MIN_LENGTH, type SecretProblem } from "../sdk/extension/index.ts";
|
|
2
|
+
import type { GhTokenGateway } from "./gateways.ts";
|
|
2
3
|
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
3
4
|
export { SECRET_MIN_LENGTH, type SecretProblem };
|
|
4
5
|
/**
|
|
@@ -8,21 +9,41 @@ export { SECRET_MIN_LENGTH, type SecretProblem };
|
|
|
8
9
|
* or `__proto__`, so the map is read with `Object.hasOwn`, never by a plain lookup, which reaches `Object.prototype`.
|
|
9
10
|
*/
|
|
10
11
|
export type UnsafeSecretEnvVarMap = Readonly<Record<string, string>>;
|
|
11
|
-
/** One variable the run can't use, with its first problem. */
|
|
12
|
+
/** One launcher environment variable the run can't use, with its first problem. */
|
|
12
13
|
export interface SecretVariableProblem {
|
|
13
14
|
readonly name: string;
|
|
14
15
|
readonly problem: SecretProblem;
|
|
15
16
|
}
|
|
17
|
+
/** Machine-readable problem codes for `readCredentials` (`credentials_invalid`). */
|
|
18
|
+
export declare const CREDENTIAL_PROBLEM_KINDS: readonly ["missing", "multiline", "short", "gh-not-installed", "gh-not-authenticated", "gh-timed-out", "gh-failed", "gh-preframed"];
|
|
19
|
+
/** What keeps one declared sandbox credential from being used. */
|
|
20
|
+
export type CredentialProblemKind = (typeof CREDENTIAL_PROBLEM_KINDS)[number];
|
|
21
|
+
/** One declared sandbox credential the run can't use, with its machine-readable problem, detail, and next step. */
|
|
22
|
+
export interface CredentialProblem {
|
|
23
|
+
/** Human-readable label for the source (an env var name such as `NPM_AUTH`, or `gh (<host>)`). */
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly problem: CredentialProblemKind;
|
|
26
|
+
/** Actionable description of why the credential couldn't be used (never holds a secret value or file contents). */
|
|
27
|
+
readonly detail: string;
|
|
28
|
+
/** Actionable next step for fixing this problem (never holds a secret value). */
|
|
29
|
+
readonly hint: string;
|
|
30
|
+
}
|
|
31
|
+
/** Gateways `readCredentials` uses to resolve non-env sandbox credential sources. */
|
|
32
|
+
export interface CredentialReadContext {
|
|
33
|
+
readonly ghTokens: GhTokenGateway;
|
|
34
|
+
}
|
|
16
35
|
/**
|
|
17
|
-
* The runner's credentials with their values, in the runner's order,
|
|
18
|
-
*
|
|
36
|
+
* The runner's credentials with their values, in the runner's order, and every secret form to redact as `<token>`, or
|
|
37
|
+
* what keeps the run from starting: each unusable credential source, in first-seen order.
|
|
19
38
|
*/
|
|
20
39
|
export type CredentialRead = {
|
|
21
40
|
readonly ok: true;
|
|
22
41
|
readonly credentials: readonly Required<SandboxCredential>[];
|
|
42
|
+
/** Every secret form (header values, raw tokens, passwords, base64 credentials, etc.) to redact as `<token>`. */
|
|
43
|
+
readonly secrets: readonly string[];
|
|
23
44
|
} | {
|
|
24
45
|
readonly ok: false;
|
|
25
|
-
readonly
|
|
46
|
+
readonly problems: readonly CredentialProblem[];
|
|
26
47
|
};
|
|
27
48
|
/**
|
|
28
49
|
* The unsafe secret environment variables' values keyed by each entry's target `name`, or what keeps the run from
|
|
@@ -36,20 +57,22 @@ export type UnsafeSecretEnvVarRead = {
|
|
|
36
57
|
readonly variables: readonly SecretVariableProblem[];
|
|
37
58
|
};
|
|
38
59
|
/**
|
|
39
|
-
* The value of each credential and unsafe secret environment variable `options` declares that `env` sets,
|
|
40
|
-
* run would say of it: for
|
|
41
|
-
*
|
|
60
|
+
* The value of each env-backed credential and unsafe secret environment variable `options` declares that `env` sets,
|
|
61
|
+
* whatever a run would say of it: for commands and pure helpers that hide set environment values without doing file
|
|
62
|
+
* I/O or starting subprocesses, such as `storm snapshots list`, `storm snapshots build` (before reading credentials),
|
|
63
|
+
* and `storm test`'s pre-run line. A short or multiline value is kept, since hiding it there is safer than showing it.
|
|
42
64
|
*/
|
|
43
65
|
export declare function declaredSecretValues(options: Pick<CheckedVercelSandboxOptions, "credentials" | "unsafeSecretEnvVars"> | undefined, env: Readonly<Record<string, string | undefined>>): string[];
|
|
44
66
|
/**
|
|
45
|
-
* Reads each of `options`'s credentials' values
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
67
|
+
* Reads each of `options`'s credentials' values on this machine:
|
|
68
|
+
* - `{ kind: "env", name }`: reads the whole header value from launcher `env` through `readSecretSource`.
|
|
69
|
+
* - `{ kind: "gh", env?, host?, format? }`: uses non-empty launcher `env[source.env]` when configured, otherwise
|
|
70
|
+
* reads a token through `context.ghTokens` (at most once per host per call) and frames it as `Basic` or `Bearer`.
|
|
71
|
+
*
|
|
72
|
+
* Returns normalized sandbox credentials in the runner's order plus every secret form to redact as `<token>`, or each
|
|
73
|
+
* problem in first-seen order.
|
|
51
74
|
*/
|
|
52
|
-
export declare function readCredentials(options: Pick<CheckedVercelSandboxOptions, "credentials">, env: Readonly<Record<string, string | undefined
|
|
75
|
+
export declare function readCredentials(options: Pick<CheckedVercelSandboxOptions, "credentials">, env: Readonly<Record<string, string | undefined>>, context: CredentialReadContext): Promise<CredentialRead>;
|
|
53
76
|
/**
|
|
54
77
|
* Reads each of `options`'s unsafe secret environment variables (`runner.unsafeSecretEnvVars`) from `env`, the
|
|
55
78
|
* environment of the machine the run starts on, through `readSecretSource`, and maps each value to `entry.name` for
|
package/dist/runner/secrets.js
CHANGED
|
@@ -1,46 +1,207 @@
|
|
|
1
|
-
// The values of the runner's credentials and unsafe secret environment variables: read from each entry's
|
|
2
|
-
//
|
|
1
|
+
// The values of the runner's credentials and unsafe secret environment variables: read from each entry's source on
|
|
2
|
+
// this machine as the run settles, turned into the sandbox credentials the Sandbox firewall adds to the requests of
|
|
3
3
|
// everything the run does in a sandbox (the steps and the command, for `credentials`) or passed into the command's
|
|
4
4
|
// environment alone (for `unsafeSecretEnvVars`), and hidden as `<token>` in what the run prints and writes (`README.md`).
|
|
5
5
|
import { describeSecretSource, readSecretSource, readSecretSourceValue, SECRET_MIN_LENGTH, secretSourceId, } from "../sdk/extension/index.js";
|
|
6
|
+
import { frameGhToken, ghEnvRedactionForms, resolveGhFormat, resolveGhHost } from "./gh.js";
|
|
6
7
|
export { SECRET_MIN_LENGTH };
|
|
8
|
+
/** Machine-readable problem codes for `readCredentials` (`credentials_invalid`). */
|
|
9
|
+
export const CREDENTIAL_PROBLEM_KINDS = [
|
|
10
|
+
"missing",
|
|
11
|
+
"multiline",
|
|
12
|
+
"short",
|
|
13
|
+
"gh-not-installed",
|
|
14
|
+
"gh-not-authenticated",
|
|
15
|
+
"gh-timed-out",
|
|
16
|
+
"gh-failed",
|
|
17
|
+
"gh-preframed",
|
|
18
|
+
];
|
|
7
19
|
/**
|
|
8
|
-
* The value of each credential and unsafe secret environment variable `options` declares that `env` sets,
|
|
9
|
-
* run would say of it: for
|
|
10
|
-
*
|
|
20
|
+
* The value of each env-backed credential and unsafe secret environment variable `options` declares that `env` sets,
|
|
21
|
+
* whatever a run would say of it: for commands and pure helpers that hide set environment values without doing file
|
|
22
|
+
* I/O or starting subprocesses, such as `storm snapshots list`, `storm snapshots build` (before reading credentials),
|
|
23
|
+
* and `storm test`'s pre-run line. A short or multiline value is kept, since hiding it there is safer than showing it.
|
|
11
24
|
*/
|
|
12
25
|
export function declaredSecretValues(options, env) {
|
|
13
26
|
if (options === undefined)
|
|
14
27
|
return [];
|
|
15
28
|
const seen = new Set();
|
|
16
29
|
const values = [];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
const add = (value) => {
|
|
31
|
+
if (value.length === 0 || seen.has(value))
|
|
32
|
+
return;
|
|
33
|
+
seen.add(value);
|
|
34
|
+
values.push(value);
|
|
35
|
+
};
|
|
36
|
+
for (const { source } of options.credentials) {
|
|
37
|
+
switch (source.kind) {
|
|
38
|
+
case "env": {
|
|
39
|
+
const value = readSecretSourceValue(source, env);
|
|
40
|
+
if (value !== undefined)
|
|
41
|
+
add(value);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "gh": {
|
|
45
|
+
if (source.env !== undefined) {
|
|
46
|
+
const raw = ownNonEmpty(env, source.env);
|
|
47
|
+
if (raw !== undefined) {
|
|
48
|
+
for (const form of ghEnvRedactionForms(raw))
|
|
49
|
+
add(form);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const { source } of options.unsafeSecretEnvVars) {
|
|
22
57
|
const value = readSecretSourceValue(source, env);
|
|
23
58
|
if (value !== undefined)
|
|
24
|
-
|
|
59
|
+
add(value);
|
|
25
60
|
}
|
|
26
61
|
return values;
|
|
27
62
|
}
|
|
28
63
|
/**
|
|
29
|
-
* Reads each of `options`'s credentials' values
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
64
|
+
* Reads each of `options`'s credentials' values on this machine:
|
|
65
|
+
* - `{ kind: "env", name }`: reads the whole header value from launcher `env` through `readSecretSource`.
|
|
66
|
+
* - `{ kind: "gh", env?, host?, format? }`: uses non-empty launcher `env[source.env]` when configured, otherwise
|
|
67
|
+
* reads a token through `context.ghTokens` (at most once per host per call) and frames it as `Basic` or `Bearer`.
|
|
68
|
+
*
|
|
69
|
+
* Returns normalized sandbox credentials in the runner's order plus every secret form to redact as `<token>`, or each
|
|
70
|
+
* problem in first-seen order.
|
|
35
71
|
*/
|
|
36
|
-
export function readCredentials(options, env) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
72
|
+
export async function readCredentials(options, env, context) {
|
|
73
|
+
const envCache = new Map();
|
|
74
|
+
const overrideEnvFailures = new Set();
|
|
75
|
+
const ghCache = new Map();
|
|
76
|
+
const ghFailureSeen = new Set();
|
|
77
|
+
const problems = [];
|
|
78
|
+
const credentials = [];
|
|
79
|
+
const secretSet = new Set();
|
|
80
|
+
const addSecrets = (forms) => {
|
|
81
|
+
for (const form of forms) {
|
|
82
|
+
if (form.length > 0)
|
|
83
|
+
secretSet.add(form);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
for (const entry of options.credentials) {
|
|
87
|
+
const { domain, header, source, requests } = entry;
|
|
88
|
+
switch (source.kind) {
|
|
89
|
+
case "env": {
|
|
90
|
+
const id = secretSourceId(source);
|
|
91
|
+
let read = envCache.get(id);
|
|
92
|
+
if (read === undefined) {
|
|
93
|
+
read = readSecretSource(source, env);
|
|
94
|
+
envCache.set(id, read);
|
|
95
|
+
if (!read.ok) {
|
|
96
|
+
problems.push(envVariableProblem(describeSecretSource(source), read.problem));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (read.ok) {
|
|
100
|
+
credentials.push({ domain, header, value: read.value, requests });
|
|
101
|
+
addSecrets([read.value]);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "gh": {
|
|
106
|
+
const host = resolveGhHost(source);
|
|
107
|
+
const format = resolveGhFormat(domain, source);
|
|
108
|
+
const envOverride = source.env === undefined ? undefined : ownNonEmpty(env, source.env);
|
|
109
|
+
if (envOverride !== undefined && source.env !== undefined) {
|
|
110
|
+
const framed = frameGhToken(envOverride, format);
|
|
111
|
+
if (!framed.ok) {
|
|
112
|
+
const key = `env:${source.env}:${framed.problem}`;
|
|
113
|
+
if (!overrideEnvFailures.has(key)) {
|
|
114
|
+
overrideEnvFailures.add(key);
|
|
115
|
+
if (framed.problem === "gh-preframed") {
|
|
116
|
+
problems.push({
|
|
117
|
+
name: source.env,
|
|
118
|
+
problem: "gh-preframed",
|
|
119
|
+
detail: `${source.env} must hold a raw token, not a pre-framed Authorization header`,
|
|
120
|
+
hint: `Set ${source.env} to the raw token: storm frames it as ${format === "basic" ? "Basic" : "Bearer"} automatically.`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
problems.push(envVariableProblem(source.env, framed.problem));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
credentials.push({ domain, header, value: framed.headerValue, requests });
|
|
130
|
+
addSecrets(framed.secrets);
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
let ghRead = ghCache.get(host);
|
|
135
|
+
if (ghRead === undefined) {
|
|
136
|
+
ghRead = await context.ghTokens.readToken({ host });
|
|
137
|
+
ghCache.set(host, ghRead);
|
|
138
|
+
}
|
|
139
|
+
const label = `gh (${host})`;
|
|
140
|
+
if (!ghRead.ok) {
|
|
141
|
+
const failureKey = `gh:${host}:${source.env ?? ""}`;
|
|
142
|
+
if (!ghFailureSeen.has(failureKey)) {
|
|
143
|
+
ghFailureSeen.add(failureKey);
|
|
144
|
+
const { failure } = ghRead;
|
|
145
|
+
const problemKind = failure.kind === "not-installed"
|
|
146
|
+
? "gh-not-installed"
|
|
147
|
+
: failure.kind === "not-authenticated"
|
|
148
|
+
? "gh-not-authenticated"
|
|
149
|
+
: failure.kind === "timed-out"
|
|
150
|
+
? "gh-timed-out"
|
|
151
|
+
: "gh-failed";
|
|
152
|
+
const baseHint = failure.kind === "not-installed"
|
|
153
|
+
? "Install the GitHub CLI (gh) and run `gh auth login`"
|
|
154
|
+
: failure.kind === "not-authenticated"
|
|
155
|
+
? `Run \`gh auth login --hostname ${host}\``
|
|
156
|
+
: `Check that \`gh auth token --hostname ${host}\` succeeds on this machine`;
|
|
157
|
+
problems.push({
|
|
158
|
+
name: label,
|
|
159
|
+
problem: problemKind,
|
|
160
|
+
detail: failure.message,
|
|
161
|
+
hint: withEnvFallback(baseHint, source.env),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
const framed = frameGhToken(ghRead.token, format);
|
|
167
|
+
if (!framed.ok) {
|
|
168
|
+
const failureKey = `gh-token:${host}:${framed.problem}`;
|
|
169
|
+
if (!ghFailureSeen.has(failureKey)) {
|
|
170
|
+
ghFailureSeen.add(failureKey);
|
|
171
|
+
if (framed.problem === "gh-preframed") {
|
|
172
|
+
problems.push({
|
|
173
|
+
name: label,
|
|
174
|
+
problem: "gh-preframed",
|
|
175
|
+
detail: `gh auth token --hostname ${host} returned a pre-framed Authorization header instead of a raw token`,
|
|
176
|
+
hint: withEnvFallback(`Re-authenticate with \`gh auth login --hostname ${host}\``, source.env),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (framed.problem === "multiline") {
|
|
180
|
+
problems.push({
|
|
181
|
+
name: label,
|
|
182
|
+
problem: "multiline",
|
|
183
|
+
detail: `gh auth token --hostname ${host} returned a value with a carriage return or a line feed`,
|
|
184
|
+
hint: withEnvFallback(`Re-authenticate with \`gh auth login --hostname ${host}\``, source.env),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
problems.push({
|
|
189
|
+
name: label,
|
|
190
|
+
problem: "short",
|
|
191
|
+
detail: `gh auth token --hostname ${host} returned fewer than ${SECRET_MIN_LENGTH} characters`,
|
|
192
|
+
hint: withEnvFallback(`Re-authenticate with \`gh auth login --hostname ${host}\``, source.env),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
credentials.push({ domain, header, value: framed.headerValue, requests });
|
|
199
|
+
addSecrets(framed.secrets);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return problems.length === 0 ? { ok: true, credentials, secrets: [...secretSet] } : { ok: false, problems };
|
|
44
205
|
}
|
|
45
206
|
/**
|
|
46
207
|
* Reads each of `options`'s unsafe secret environment variables (`runner.unsafeSecretEnvVars`) from `env`, the
|
|
@@ -77,3 +238,35 @@ function readUniqueSources(entries, env, map) {
|
|
|
77
238
|
}
|
|
78
239
|
return variables.length === 0 ? { ok: true, items } : { ok: false, variables };
|
|
79
240
|
}
|
|
241
|
+
function envVariableProblem(name, problem) {
|
|
242
|
+
switch (problem) {
|
|
243
|
+
case "missing":
|
|
244
|
+
return {
|
|
245
|
+
name,
|
|
246
|
+
problem,
|
|
247
|
+
detail: `${name} is not set`,
|
|
248
|
+
hint: `Set ${name} in this machine's environment.`,
|
|
249
|
+
};
|
|
250
|
+
case "multiline":
|
|
251
|
+
return {
|
|
252
|
+
name,
|
|
253
|
+
problem,
|
|
254
|
+
detail: `${name} holds a carriage return or a line feed`,
|
|
255
|
+
hint: `Set ${name} to a value on one line: storm hides each value in output a line at a time, and doesn't trim one.`,
|
|
256
|
+
};
|
|
257
|
+
case "short":
|
|
258
|
+
return {
|
|
259
|
+
name,
|
|
260
|
+
problem,
|
|
261
|
+
detail: `${name} holds fewer than ${SECRET_MIN_LENGTH} characters`,
|
|
262
|
+
hint: `Set ${name} to the whole secret.`,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function withEnvFallback(base, envVar) {
|
|
267
|
+
return envVar === undefined ? `${base}.` : `${base}, or set ${envVar} in this machine's environment.`;
|
|
268
|
+
}
|
|
269
|
+
function ownNonEmpty(env, name) {
|
|
270
|
+
const value = Object.hasOwn(env, name) ? env[name] : undefined;
|
|
271
|
+
return value === undefined || value.length === 0 ? undefined : value;
|
|
272
|
+
}
|
package/dist/runner/session.js
CHANGED
|
@@ -18,11 +18,14 @@ export function openRunnerSession(context, request, control, progress) {
|
|
|
18
18
|
const hasUnsafeSecretEnvVars = Object.keys(unsafeSecretEnvVars).length > 0;
|
|
19
19
|
if (hasUnsafeSecretEnvVars && request.keepMs > 0)
|
|
20
20
|
throw new Error("a runner session with unsafeSecretEnvVars can't keep its runner sandbox");
|
|
21
|
+
if (request.prepared.options.managedCredentials.length > 0 && request.keepMs > 0)
|
|
22
|
+
throw new Error("a runner session with managedCredentials can't keep its runner sandbox");
|
|
21
23
|
let commandRunning = false;
|
|
22
24
|
// When the run is canceled, the scope reports `stopping` and revokes every credential at once.
|
|
23
25
|
const scope = runnerSandboxScope(context, progress, {
|
|
24
26
|
keepMs: request.keepMs,
|
|
25
27
|
basePolicy: runnerNetworkPolicy(request.prepared.options),
|
|
28
|
+
managedCredentials: request.prepared.options.managedCredentials,
|
|
26
29
|
signal,
|
|
27
30
|
commandRunning: () => commandRunning,
|
|
28
31
|
});
|
|
@@ -9,13 +9,13 @@ export interface SharedSnapshotBucketInput {
|
|
|
9
9
|
readonly teamId: string;
|
|
10
10
|
readonly projectId: string;
|
|
11
11
|
readonly region: string;
|
|
12
|
-
readonly
|
|
12
|
+
readonly image: string;
|
|
13
13
|
readonly runnerName: string;
|
|
14
14
|
readonly snapshotKey: string;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* The 16-hex-character bucket identifier for `input`: the first 16 hex characters of sha256 over its team ID, project
|
|
18
|
-
* ID, region,
|
|
18
|
+
* ID, region, image, runner name, and snapshot key, joined with NUL.
|
|
19
19
|
*/
|
|
20
20
|
export declare function sharedSnapshotBucket(input: SharedSnapshotBucketInput): string;
|
|
21
21
|
/** The name prefix shared by every named sandbox in `bucket`. */
|
|
@@ -80,7 +80,7 @@ export declare function classifyVerifiedSharedSnapshot(row: NamedSandboxInfo & {
|
|
|
80
80
|
* `base`, and its snapshot `snapshot`. Null unless the canonical classifier marks it `ready` (status `created`, known
|
|
81
81
|
* expiry from `snapshot.expiresAt ?? sandbox.tags["expires-at"]`, and more than an hour left).
|
|
82
82
|
*/
|
|
83
|
-
export declare function usableSharedEntry(access: SandboxAccess, runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "
|
|
83
|
+
export declare function usableSharedEntry(access: SandboxAccess, runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "image">, snapshotKey: string, base: string, sandbox: NamedSandboxInfo, snapshot: SnapshotInfo, now: Date): RunnerSnapshotEntry | null;
|
|
84
84
|
/**
|
|
85
85
|
* Runs `task` for indexes `0` to `count - 1`, at most `limit` at a time, in index order. Before starting each task it
|
|
86
86
|
* asks `proceed`; once that says no, no further task starts, and the ones in flight still finish.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Shared snapshot index naming, bucketing, concurrency, and canonical entry classification. Each bucket hashes
|
|
2
|
-
// the team, project, region,
|
|
2
|
+
// the team, project, region, image, runner name, and snapshot key into 16 hex characters, and each entry's named
|
|
3
3
|
// sandbox is `storm-snap-<bucket>-<base>`. Lookup, listing, publishing, and pruning share one status and expiry
|
|
4
4
|
// classifier so they never disagree on whether an entry is usable or expired.
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
@@ -33,11 +33,11 @@ function hasSnapshotId(row) {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* The 16-hex-character bucket identifier for `input`: the first 16 hex characters of sha256 over its team ID, project
|
|
36
|
-
* ID, region,
|
|
36
|
+
* ID, region, image, runner name, and snapshot key, joined with NUL.
|
|
37
37
|
*/
|
|
38
38
|
export function sharedSnapshotBucket(input) {
|
|
39
39
|
return createHash("sha256")
|
|
40
|
-
.update([input.teamId, input.projectId, input.region, input.
|
|
40
|
+
.update([input.teamId, input.projectId, input.region, input.image, input.runnerName, input.snapshotKey].join("\0"))
|
|
41
41
|
.digest("hex")
|
|
42
42
|
.slice(0, 16);
|
|
43
43
|
}
|
|
@@ -128,7 +128,7 @@ export function usableSharedEntry(access, runner, snapshotKey, base, sandbox, sn
|
|
|
128
128
|
teamId: access.teamId,
|
|
129
129
|
projectId: access.projectId,
|
|
130
130
|
region: runner.region,
|
|
131
|
-
|
|
131
|
+
image: runner.image,
|
|
132
132
|
runnerName: runner.name,
|
|
133
133
|
snapshotKey,
|
|
134
134
|
base,
|
|
@@ -6,7 +6,7 @@ import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
|
6
6
|
/** What `listSharedSnapshots` queries in the shared snapshot index. */
|
|
7
7
|
export interface SharedSnapshotListRequest {
|
|
8
8
|
readonly access: SandboxAccess;
|
|
9
|
-
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "
|
|
9
|
+
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "image">;
|
|
10
10
|
readonly snapshotKey: string;
|
|
11
11
|
}
|
|
12
12
|
/** One entry returned by `listSharedSnapshots`, verified against the Sandbox API when stopped with a snapshot ID. */
|
|
@@ -11,7 +11,7 @@ export interface SharedSnapshotLookupContext {
|
|
|
11
11
|
export interface SharedSnapshotLookupRequest {
|
|
12
12
|
readonly access: SandboxAccess;
|
|
13
13
|
readonly repoRoot: string;
|
|
14
|
-
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "
|
|
14
|
+
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "image">;
|
|
15
15
|
readonly snapshotKey: string;
|
|
16
16
|
readonly mergeBase: string;
|
|
17
17
|
/**
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// it stopped once saved, as an entry of the shared snapshot index.
|
|
6
6
|
import { runnerTags } from "./context.js";
|
|
7
7
|
import { SNAPSHOT_EXPIRATION_MS } from "./local-snapshot-index.js";
|
|
8
|
-
import { baseIndexScript, STAGED_FILES } from "./snapshot-key.js";
|
|
8
|
+
import { baseIndexScript, gitFetchBaseIndexScript, STAGED_FILES } from "./snapshot-key.js";
|
|
9
|
+
import { normalizeGitFetchUrl } from "./snapshot-source.js";
|
|
9
10
|
import { networkPolicyStop, runStep, sandboxStop } from "./steps.js";
|
|
10
11
|
/** How long a build sandbox may live: 30 minutes. */
|
|
11
12
|
export const BUILD_SANDBOX_TIMEOUT_MS = 30 * 60_000;
|
|
@@ -25,18 +26,28 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
25
26
|
summary: options.snapshot.summary ??
|
|
26
27
|
[...options.snapshot.toolchains, ...options.snapshot.prebuild].map(({ label }) => label).join(", "),
|
|
27
28
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
let fetchUrl;
|
|
30
|
+
if (options.snapshot.source !== undefined) {
|
|
31
|
+
const resolved = await resolveGitFetchUrl(context.checkout, {
|
|
32
|
+
repoRoot,
|
|
33
|
+
remote: options.snapshot.source.remote,
|
|
34
|
+
});
|
|
35
|
+
if (!resolved.ok)
|
|
36
|
+
return { kind: "failed", failure: { kind: "checkout-failed", failure: resolved.failure } };
|
|
37
|
+
fetchUrl = resolved.value;
|
|
38
|
+
}
|
|
39
|
+
const startBuild = () => scope.startBuildSandbox(access, {
|
|
40
|
+
region: options.region,
|
|
41
|
+
image: options.image,
|
|
42
|
+
vcpus: options.snapshot.vcpus,
|
|
43
|
+
timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
|
|
44
|
+
...(publish === undefined
|
|
45
|
+
? { tags: runnerTags(options.name, "snapshot-build", request.user) }
|
|
46
|
+
: { name: publish.name, tags: publish.tags }),
|
|
47
|
+
});
|
|
48
|
+
const [started, baseStep] = fetchUrl === undefined
|
|
49
|
+
? await Promise.all([startBuild(), context.checkout.baseArchive({ repoRoot, base })])
|
|
50
|
+
: [await startBuild(), fetchUrl];
|
|
40
51
|
if (!started.ok)
|
|
41
52
|
return started.failure.kind === "name-taken"
|
|
42
53
|
? { kind: "name-taken", name: started.failure.name, message: started.failure.message }
|
|
@@ -50,14 +61,21 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
50
61
|
vcpus: options.snapshot.vcpus,
|
|
51
62
|
ms: now() - startedAt,
|
|
52
63
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
let baseStepScript;
|
|
65
|
+
if (typeof baseStep === "string") {
|
|
66
|
+
baseStepScript = gitFetchBaseIndexScript(baseStep, base);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (!baseStep.ok)
|
|
70
|
+
return { kind: "failed", failure: { kind: "checkout-failed", failure: baseStep.failure } };
|
|
71
|
+
const staged = await context.runnerSandboxes.upload(sandbox, [
|
|
72
|
+
{ name: STAGED_FILES.baseTarball, content: baseStep.value.tarball },
|
|
73
|
+
{ name: STAGED_FILES.baseFileList, content: baseStep.value.fileList },
|
|
74
|
+
], signal);
|
|
75
|
+
if (!staged.ok)
|
|
76
|
+
return sandboxStop("upload", staged.failure);
|
|
77
|
+
baseStepScript = baseIndexScript(base, staged.value.directory);
|
|
78
|
+
}
|
|
61
79
|
if (prepared.baseFiles.length > 0) {
|
|
62
80
|
const encoder = new TextEncoder();
|
|
63
81
|
const placed = await context.runnerSandboxes.placeBaseFiles(sandbox, prepared.baseFiles.map(({ path, text }) => ({ name: path, content: encoder.encode(text) })), signal);
|
|
@@ -66,11 +84,13 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
66
84
|
}
|
|
67
85
|
// Every credential the runner declares goes on the steps' requests, from before the first toolchain step until
|
|
68
86
|
// `saveSnapshot` revokes them before saving (or the scope's fence revokes them if a step fails or the build is
|
|
69
|
-
// canceled). storm's own base-index step falls inside
|
|
70
|
-
//
|
|
87
|
+
// canceled). storm's own base-index step falls inside. With `snapshot.source: { kind: "git-fetch" }` its fetch needs
|
|
88
|
+
// them, since a credential for the Git host reaches the fetch's requests only this way. Otherwise it runs only tar and
|
|
89
|
+
// git on the uploaded files, so it makes no request, and revoking and granting again around it would add two writes
|
|
90
|
+
// and their failures for nothing.
|
|
71
91
|
const steps = [
|
|
72
92
|
...options.snapshot.toolchains,
|
|
73
|
-
{ label: BASE_INDEX_LABEL, script:
|
|
93
|
+
{ label: BASE_INDEX_LABEL, script: baseStepScript },
|
|
74
94
|
...options.snapshot.prebuild,
|
|
75
95
|
];
|
|
76
96
|
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: options.region });
|
|
@@ -127,7 +147,7 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
127
147
|
teamId: access.teamId,
|
|
128
148
|
projectId: access.projectId,
|
|
129
149
|
region: options.region,
|
|
130
|
-
|
|
150
|
+
image: options.image,
|
|
131
151
|
runnerName: options.name,
|
|
132
152
|
snapshotKey: prepared.snapshotKey,
|
|
133
153
|
base,
|
|
@@ -152,3 +172,12 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
152
172
|
value: { entry, ms, sizeBytes: saved.value.sizeBytes, localIndexFailure: written.ok ? null : written.failure },
|
|
153
173
|
};
|
|
154
174
|
}
|
|
175
|
+
async function resolveGitFetchUrl(checkout, request) {
|
|
176
|
+
const remote = await checkout.remoteUrl(request);
|
|
177
|
+
if (!remote.ok)
|
|
178
|
+
return remote;
|
|
179
|
+
const fetchUrl = normalizeGitFetchUrl(remote.value);
|
|
180
|
+
if (fetchUrl.ok)
|
|
181
|
+
return { ok: true, value: fetchUrl.url };
|
|
182
|
+
return { ok: false, failure: { message: `the URL of Git remote "${request.remote}" ${fetchUrl.problem}` } };
|
|
183
|
+
}
|
|
@@ -20,6 +20,7 @@ export async function chooseSnapshotForRun(context, request, control, progress)
|
|
|
20
20
|
const scope = runnerSandboxScope(context, progress, {
|
|
21
21
|
keepMs: 0,
|
|
22
22
|
basePolicy: runnerNetworkPolicy(request.prepared.options),
|
|
23
|
+
managedCredentials: request.prepared.options.managedCredentials,
|
|
23
24
|
signal,
|
|
24
25
|
});
|
|
25
26
|
try {
|