hammerkit 2.0.0-next.2 → 2.0.0-next.21
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/cache/backends/registry/registry-client.js +8 -2
- package/dist/cache/explain.js +7 -5
- package/dist/cache/last-resolved.js +11 -0
- package/dist/cli.js +4 -1
- package/dist/dashboard/assets/graph-canvas-DLioOiRN.css +1 -0
- package/dist/dashboard/assets/graph-canvas-DtJSpova.js +8 -0
- package/dist/dashboard/assets/index-BndChMep.css +2 -0
- package/dist/dashboard/assets/index-DRSwIRXd.js +17 -0
- package/dist/dashboard/index.html +3 -3
- package/dist/dashboard/logo.png +0 -0
- package/dist/docker/item-network.js +51 -18
- package/dist/docker/package.js +85 -76
- package/dist/docker/server-tools.js +96 -0
- package/dist/docker/stream.js +15 -7
- package/dist/environment/replace-env-variables.js +1 -1
- package/dist/environment/run-source-envs.js +18 -0
- package/dist/executer/check-container-binds.js +158 -0
- package/dist/executer/docker-service.js +42 -3
- package/dist/executer/docker-task.js +21 -5
- package/dist/executer/execute-command.js +9 -15
- package/dist/executer/execute-work-task.js +14 -2
- package/dist/executer/execute-work-tree.js +2 -1
- package/dist/executer/execution-steps.js +3 -2
- package/dist/executer/local-task.js +3 -0
- package/dist/executer/print-container-options.js +10 -10
- package/dist/executer/process-manager.js +84 -5
- package/dist/executer/scheduler/enqueue-next.js +6 -1
- package/dist/executer/scheduler/state-key.js +71 -34
- package/dist/executer/task-priority.js +131 -0
- package/dist/executer/watch-loop.js +18 -5
- package/dist/file/get-file-context.js +5 -1
- package/dist/file/stat-beneath.js +66 -0
- package/dist/file/within-root.js +13 -4
- package/dist/harness/connect.js +1 -6
- package/dist/harness/mcp-command.js +1 -1
- package/dist/harness/sandbox-client.js +39 -4
- package/dist/harness/service-tools.js +2 -2
- package/dist/kubernetes/await-running-state.js +98 -18
- package/dist/kubernetes/claim-layout.js +10 -1
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +10 -1
- package/dist/kubernetes/ensure-persistent-data.js +129 -26
- package/dist/kubernetes/follow-pod-logs.js +128 -29
- package/dist/kubernetes/kept-claims.js +16 -1
- package/dist/kubernetes/network-gate.js +74 -11
- package/dist/kubernetes/network-policy.js +35 -13
- package/dist/kubernetes/quota-wait.js +97 -0
- package/dist/kubernetes/remove-stale-items.js +15 -2
- package/dist/kubernetes/restore-kubernetes-data.js +28 -4
- package/dist/kubernetes/sandbox-runner.js +3 -4
- package/dist/kubernetes/store-kubernetes-data.js +14 -2
- package/dist/kubernetes/transfer-tools.js +66 -0
- package/dist/kubernetes/volumes.js +78 -14
- package/dist/optimizer/calculate-checksum.js +46 -3
- package/dist/optimizer/check-key.js +7 -0
- package/dist/optimizer/check-keys.js +19 -5
- package/dist/optimizer/get-work-cache-stats.js +55 -31
- package/dist/optimizer/work-task-cache-description.js +36 -7
- package/dist/parser/read-build-file.js +8 -3
- package/dist/planner/utils/append-work-service.js +1 -1
- package/dist/planner/utils/append-work-task.js +1 -1
- package/dist/planner/utils/assert-item-paths.js +6 -7
- package/dist/planner/utils/template-value.js +20 -4
- package/dist/planner/work-item-executions.js +27 -0
- package/dist/planner/work-runtime-docker.js +31 -50
- package/dist/planner/work-runtime-kubernetes.js +70 -41
- package/dist/planner/work-runtime-local.js +3 -7
- package/dist/planner/work-secret.js +135 -13
- package/dist/planner/work-tree.js +10 -0
- package/dist/remote/collect-bundle.js +9 -1
- package/dist/remote/host-config.js +49 -3
- package/dist/remote/location.js +5 -5
- package/dist/remote/remote-commands.js +12 -14
- package/dist/remote/remote-work-commands.js +31 -10
- package/dist/schema/schema-parser.js +46 -2
- package/dist/schema/work-scope-parser.js +16 -1
- package/dist/secrets/secret-catalog.js +8 -1
- package/dist/server/capacity.js +71 -41
- package/dist/server/dashboard.js +35 -14
- package/dist/server/endpoints.js +10 -1
- package/dist/server/executor.js +68 -35
- package/dist/server/kubernetes-backend.js +29 -4
- package/dist/server/kubernetes-sandbox-storage.js +14 -4
- package/dist/server/oauth.js +16 -1
- package/dist/server/overview.js +100 -13
- package/dist/server/plan.js +41 -6
- package/dist/server/policy.js +22 -9
- package/dist/server/repo-access.js +4 -3
- package/dist/server/run-environment.js +5 -2
- package/dist/server/run-plan.js +18 -6
- package/dist/server/run-retry.js +57 -0
- package/dist/server/run-source-environment.js +39 -0
- package/dist/server/run-worker.js +71 -9
- package/dist/server/runs.js +133 -7
- package/dist/server/sandbox-files.js +339 -55
- package/dist/server/sandbox-patch.js +43 -17
- package/dist/server/sandboxes.js +57 -23
- package/dist/server/server-config.js +28 -5
- package/dist/server/server.js +150 -20
- package/dist/server/service-runs.js +50 -5
- package/dist/server/sources.js +68 -11
- package/dist/server/timings.js +23 -3
- package/dist/utils/buffer-context.js +30 -20
- package/dist/utils/limit.js +30 -0
- package/dist/utils/line-splitter.js +52 -0
- package/dist/utils/read-lines.js +65 -0
- package/dist/utils/tar.js +51 -1
- package/dist/utils/units.js +36 -1
- package/dist/utils/web-links.js +34 -0
- package/package.json +1 -1
- package/dist/dashboard/assets/index-CjnKm5-3.css +0 -2
- package/dist/dashboard/assets/index-zPXa4klZ.js +0 -13
- package/dist/dashboard/favicon.svg +0 -1
package/dist/server/executor.js
CHANGED
|
@@ -13,6 +13,7 @@ const git_checkout_1 = require("./git-checkout");
|
|
|
13
13
|
const run_plan_1 = require("./run-plan");
|
|
14
14
|
const work_network_1 = require("../planner/work-network");
|
|
15
15
|
const execute_docker_1 = require("../executer/execute-docker");
|
|
16
|
+
const run_source_environment_1 = require("./run-source-environment");
|
|
16
17
|
// `.git` as a file system may read it: any case, and a name Windows reads without its
|
|
17
18
|
// trailing dots and spaces, or by its short name
|
|
18
19
|
function isGitDirectory(segment) {
|
|
@@ -43,12 +44,21 @@ exports.defaultWorker = defaultWorker;
|
|
|
43
44
|
// owner may write in the sandbox is not part of it. It leaves entries a run from main can
|
|
44
45
|
// find, keyed by the files it ran on, as a ref run of a branch does: so only a caller who
|
|
45
46
|
// may push a branch of the repository and run from it may check (server.ts).
|
|
47
|
+
//
|
|
48
|
+
// An approved run on a sandbox runs on a copy of the approved files too, but its owner
|
|
49
|
+
// may not use its accounts without the approval: it has a cache of its own, so what the
|
|
50
|
+
// owner's other runs built from files nobody approved (ignored ones) is not restored in it.
|
|
46
51
|
function cacheNamespace(run) {
|
|
47
52
|
const repository = run.source.type === 'ref' || (run.source.type === 'sandbox' && run.source.check);
|
|
53
|
+
const kind = repository
|
|
54
|
+
? 'ref'
|
|
55
|
+
: run.source.type === 'sandbox' && (run.approvals?.length ?? 0) > 0
|
|
56
|
+
? 'approved'
|
|
57
|
+
: run.source.type;
|
|
48
58
|
const key = repository
|
|
49
59
|
? `ref\0${run.source.repo}`
|
|
50
|
-
: `${
|
|
51
|
-
return `${
|
|
60
|
+
: `${kind}\0${run.owner.iss}\0${run.owner.sub}`;
|
|
61
|
+
return `${kind}-${(0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 24)}`;
|
|
52
62
|
}
|
|
53
63
|
exports.cacheNamespace = cacheNamespace;
|
|
54
64
|
// The docker volumes of a run's services are its caller's, within the cache's source trust:
|
|
@@ -193,7 +203,7 @@ class HostExecutor {
|
|
|
193
203
|
// what was approved is what runs: the accounts are read again from the files with
|
|
194
204
|
// the environment of the run, and the run may use no more than it was admitted for
|
|
195
205
|
const policy = source.type === 'sandbox' && sandboxes ? sandboxes.policy : planning.policy;
|
|
196
|
-
const planned = await (0, run_plan_1.planRun)(bundle, run, planning.environment, policy);
|
|
206
|
+
const planned = await (0, run_plan_1.planRun)(bundle, run, (0, run_source_environment_1.runPlanningEnvironment)(planning.environment, run.source), policy);
|
|
197
207
|
const extra = planned.accounts.filter((account) => !run.accounts.includes(account));
|
|
198
208
|
if (extra.length > 0) {
|
|
199
209
|
throw new Error(`the run would use ${extra.join(', ')}, which it was not admitted for`);
|
|
@@ -212,76 +222,93 @@ class HostExecutor {
|
|
|
212
222
|
const root = this.directoryOf(run);
|
|
213
223
|
let attachment;
|
|
214
224
|
try {
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
//
|
|
218
|
-
|
|
225
|
+
// The process of the run starts in the published files, which it reads its build files
|
|
226
|
+
// from, and its tasks work on other files (`work`): a checkout, a sandbox or a copy of
|
|
227
|
+
// one. The published files are a directory of the run no task mounts, so what the
|
|
228
|
+
// process parses for each task it runs, and what the secret providers it starts read
|
|
229
|
+
// of their directory, is what was published and never what a task wrote.
|
|
230
|
+
const published = (0, path_1.join)(root, 'bundle');
|
|
231
|
+
await (0, promises_1.mkdir)(published, { recursive: true });
|
|
232
|
+
await this.writeBundle(published, bundle.files);
|
|
219
233
|
let input;
|
|
220
234
|
let claim;
|
|
221
|
-
// the files
|
|
235
|
+
// the files the tasks work on
|
|
222
236
|
let work;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
const sourceStarted = new Date();
|
|
238
|
+
// A check works on the files a push of the sandbox commits, copied out of it, and so
|
|
239
|
+
// does a run that was approved: what was approved is those files, and the sandbox has
|
|
240
|
+
// more (its ignored files, node_modules, outputs), which its owner and their runs write
|
|
241
|
+
// while the run waits and runs.
|
|
242
|
+
const copied = source.type === 'sandbox' && (source.check || (run.approvals?.length ?? 0) > 0);
|
|
243
|
+
// (`source.type` again: TypeScript narrows `source` by it, not by `copied`)
|
|
244
|
+
if (source.type === 'sandbox' && copied) {
|
|
226
245
|
const { registry, network } = sandboxes;
|
|
227
|
-
|
|
246
|
+
const what = source.check ? 'the check' : 'the approved run';
|
|
247
|
+
if (!source.check) {
|
|
248
|
+
// what was approved is what runs: the files may have changed since, by a run
|
|
249
|
+
// before this one on the sandbox (the copy checks it again, under the sandbox's lock)
|
|
250
|
+
const state = await registry.state(source.id, abortCtrl.signal);
|
|
251
|
+
if (state.tree !== source.tree) {
|
|
252
|
+
throw new Error(`the files of the sandbox ${source.id} changed since the run was approved, they are ${state.tree} now and were ${source.tree}, submit the run again`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
work = (0, path_1.join)(root, 'source');
|
|
228
256
|
try {
|
|
229
|
-
await registry.exportTree(source.id, source.tree,
|
|
257
|
+
await registry.exportTree(source.id, source.tree, work, abortCtrl.signal);
|
|
230
258
|
}
|
|
231
259
|
catch (e) {
|
|
232
|
-
throw new Error(`the files of the sandbox ${source.id} could not be copied for
|
|
260
|
+
throw new Error(`the files of the sandbox ${source.id} could not be copied for ${what}, submit it again: ${e instanceof Error ? e.message : String(e)}`);
|
|
233
261
|
}
|
|
234
262
|
// a repository of its own, as a checkout of the commit is: the root of the project,
|
|
235
263
|
// which the paths of the tasks' keys are relative to, is the one of git
|
|
236
|
-
await (0, git_checkout_1.git)(['init', '--quiet',
|
|
264
|
+
await (0, git_checkout_1.git)(['init', '--quiet', work], {}, abortCtrl.signal, `${what} of sandbox ${source.id}`, 'init');
|
|
237
265
|
context.emit({
|
|
238
266
|
type: 'log',
|
|
239
267
|
task: 'hammerkit',
|
|
240
268
|
stream: 'stdout',
|
|
241
|
-
text:
|
|
269
|
+
text: `${source.check ? 'check' : 'approved run'} of sandbox ${source.id} of ${source.repo}: files ${source.tree}, fetched at ${source.commit}`,
|
|
242
270
|
});
|
|
243
|
-
|
|
271
|
+
// the tasks see the published build files in place of the sandbox's own
|
|
272
|
+
await this.writeBundle(work, bundle.files);
|
|
244
273
|
input = {
|
|
245
|
-
entry: (0, path_1.join)(
|
|
274
|
+
entry: (0, path_1.join)(published, version.entry),
|
|
275
|
+
directory: { read: published, work },
|
|
246
276
|
...(planning.policy.network ? { network: (0, work_network_1.toNetworkSchema)(planning.policy.network) } : {}),
|
|
247
277
|
sandboxNetwork: network,
|
|
248
278
|
};
|
|
249
279
|
}
|
|
250
280
|
else if (source.type === 'ref') {
|
|
251
|
-
|
|
281
|
+
work = (0, path_1.join)(root, 'source');
|
|
252
282
|
const { repo, ref, commit: pinned } = source;
|
|
253
283
|
const credentials = await repos.credentials(repo);
|
|
254
284
|
let commit;
|
|
255
285
|
try {
|
|
256
286
|
// a woken service run starts the commit it started first, where the ref is now or not
|
|
257
287
|
const fetched = run.wakes ? pinned : ref;
|
|
258
|
-
commit = await (0, git_checkout_1.checkoutRef)(repos.url(repo), fetched,
|
|
288
|
+
commit = await (0, git_checkout_1.checkoutRef)(repos.url(repo), fetched, work, credentials.env, abortCtrl.signal, pinned);
|
|
259
289
|
}
|
|
260
290
|
catch (e) {
|
|
261
291
|
throw repos.scrub(e, credentials.values);
|
|
262
292
|
}
|
|
263
293
|
context.emit({ type: 'log', task: 'hammerkit', stream: 'stdout', text: `checked out ${repo} at ${commit}` });
|
|
264
|
-
|
|
294
|
+
// the tasks see the published build files in place of the checkout's own
|
|
295
|
+
await this.writeBundle(work, bundle.files);
|
|
265
296
|
// what the version was checked against at publish holds while it runs too
|
|
266
297
|
input = {
|
|
267
|
-
entry: (0, path_1.join)(
|
|
298
|
+
entry: (0, path_1.join)(published, version.entry),
|
|
299
|
+
directory: { read: published, work },
|
|
268
300
|
...(planning.policy.network ? { network: (0, work_network_1.toNetworkSchema)(planning.policy.network) } : {}),
|
|
269
301
|
};
|
|
270
302
|
}
|
|
271
303
|
else {
|
|
272
|
-
//
|
|
273
|
-
//
|
|
304
|
+
// a run its caller may run without an approval works on the sandbox itself, whose
|
|
305
|
+
// own build files are just files
|
|
274
306
|
const { registry, network } = sandboxes;
|
|
275
307
|
// read before the run attaches: until then the walk of the last run's measure holds
|
|
276
308
|
const state = await registry.state(source.id, abortCtrl.signal);
|
|
277
309
|
attachment = await registry.attach(source.id, (0, path_1.join)(root, 'sandbox'));
|
|
278
310
|
work = attachment.directory;
|
|
279
311
|
claim = attachment.claim;
|
|
280
|
-
// what was approved is what runs: the files may have changed since, by a run
|
|
281
|
-
// before this one on the sandbox
|
|
282
|
-
if (run.approvals?.length && state.tree !== source.tree) {
|
|
283
|
-
throw new Error(`the files of the sandbox ${source.id} changed since the run was approved, they are ${state.tree} now and were ${source.tree}, submit the run again`);
|
|
284
|
-
}
|
|
285
312
|
if (claim && !this.options.placement) {
|
|
286
313
|
throw new Error(`the sandbox ${source.id} is a claim on a cluster, this server runs tasks on its own docker`);
|
|
287
314
|
}
|
|
@@ -291,10 +318,6 @@ class HostExecutor {
|
|
|
291
318
|
stream: 'stdout',
|
|
292
319
|
text: `sandbox ${source.id} of ${source.repo} at ${state.commit}, files ${state.tree}${state.clean ? '' : ' with changes'}`,
|
|
293
320
|
});
|
|
294
|
-
const published = (0, path_1.join)(root, 'bundle');
|
|
295
|
-
await (0, promises_1.mkdir)(published, { recursive: true });
|
|
296
|
-
await this.writeBundle(published, bundle.files);
|
|
297
|
-
cwd = published;
|
|
298
321
|
input = {
|
|
299
322
|
entry: (0, path_1.join)(published, version.entry),
|
|
300
323
|
directory: { read: published, work },
|
|
@@ -303,12 +326,17 @@ class HostExecutor {
|
|
|
303
326
|
sandboxNetwork: network,
|
|
304
327
|
};
|
|
305
328
|
}
|
|
329
|
+
emitPhase(context, 'source', sourceStarted);
|
|
306
330
|
const home = (0, path_1.join)(root, 'home');
|
|
307
331
|
await (0, promises_1.mkdir)(home, { recursive: true });
|
|
308
332
|
const cache = (0, path_1.join)(this.options.cache, cacheNamespace(run));
|
|
309
333
|
await (0, promises_1.mkdir)(cache, { recursive: true });
|
|
310
334
|
const placement = this.options.placement;
|
|
311
|
-
const
|
|
335
|
+
const namespaceStarted = new Date();
|
|
336
|
+
const placed = placement ? await placement.prepare(run, context, { root: work, claim }) : undefined;
|
|
337
|
+
if (placed) {
|
|
338
|
+
emitPhase(context, 'namespace', namespaceStarted);
|
|
339
|
+
}
|
|
312
340
|
try {
|
|
313
341
|
await this.runInProcess(worker, {
|
|
314
342
|
...input,
|
|
@@ -317,6 +345,7 @@ class HostExecutor {
|
|
|
317
345
|
accounts: run.accounts,
|
|
318
346
|
volumeScope: volumeScope(run, this.options.directory),
|
|
319
347
|
...((0, checks_1.isCheckRun)(run) ? { check: true } : {}),
|
|
348
|
+
...(context.durations ? { durations: context.durations } : {}),
|
|
320
349
|
catalog: planning.environment.hosted?.catalog,
|
|
321
350
|
...(run.up
|
|
322
351
|
? {
|
|
@@ -328,7 +357,7 @@ class HostExecutor {
|
|
|
328
357
|
: {}),
|
|
329
358
|
...(placed ? { kubernetes: placed.kubernetes } : {}),
|
|
330
359
|
...(!placed && this.options.capabilityRuntime ? { capabilityRuntime: this.options.capabilityRuntime } : {}),
|
|
331
|
-
},
|
|
360
|
+
}, published, { ...(0, run_source_environment_1.withRunSource)(this.processEnvironment(home, cache), run.source), ...placed?.env }, context, abortCtrl.signal);
|
|
332
361
|
}
|
|
333
362
|
finally {
|
|
334
363
|
if (placement && placed) {
|
|
@@ -504,4 +533,8 @@ class HostExecutor {
|
|
|
504
533
|
}
|
|
505
534
|
}
|
|
506
535
|
exports.HostExecutor = HostExecutor;
|
|
536
|
+
// A step of a run before its tasks, for its timeline (RunPhase)
|
|
537
|
+
function emitPhase(context, phase, startedAt) {
|
|
538
|
+
context.emit({ type: 'phase', phase, startedAt: startedAt.toISOString(), finishedAt: new Date().toISOString() });
|
|
539
|
+
}
|
|
507
540
|
//# sourceMappingURL=executor.js.map
|
|
@@ -12,6 +12,7 @@ const capacity_1 = require("./capacity");
|
|
|
12
12
|
const kubernetes_instance_1 = require("../kubernetes/kubernetes-instance");
|
|
13
13
|
const log_1 = require("../log");
|
|
14
14
|
const network_policy_1 = require("../kubernetes/network-policy");
|
|
15
|
+
const network_gate_1 = require("../kubernetes/network-gate");
|
|
15
16
|
const sleep_1 = require("../utils/sleep");
|
|
16
17
|
const version_1 = require("../version");
|
|
17
18
|
const executor_1 = require("./executor");
|
|
@@ -98,6 +99,8 @@ function readInClusterNamespace() {
|
|
|
98
99
|
* Policies add up, so neither selects the pods of a limited item: its own policy (see
|
|
99
100
|
* buildNetworkPolicy) is all it may reach, DNS left out, and all that may reach it. An
|
|
100
101
|
* egress proxy takes connections from its item only (buildProxyPolicy).
|
|
102
|
+
* - the pods that copy files into and out of claims: no network at all (they are limited,
|
|
103
|
+
* and the policies of the items whose labels they carry leave them out)
|
|
101
104
|
*/
|
|
102
105
|
function getNamespacePolicies(namespace, deniedEgress, allowedEgress = []) {
|
|
103
106
|
const metadata = (name) => ({
|
|
@@ -157,6 +160,17 @@ function getNamespacePolicies(namespace, deniedEgress, allowedEgress = []) {
|
|
|
157
160
|
ingress: [],
|
|
158
161
|
},
|
|
159
162
|
},
|
|
163
|
+
{
|
|
164
|
+
apiVersion: 'networking.k8s.io/v1',
|
|
165
|
+
kind: 'NetworkPolicy',
|
|
166
|
+
metadata: metadata('hammerkit-transfer'),
|
|
167
|
+
spec: {
|
|
168
|
+
// the pods that copy files into and out of a claim, which are reached through the
|
|
169
|
+
// API (exec): nothing in or out
|
|
170
|
+
podSelector: { matchLabels: { [network_policy_1.TRANSFER_LABEL]: 'true' } },
|
|
171
|
+
policyTypes: ['Ingress', 'Egress'],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
160
174
|
];
|
|
161
175
|
}
|
|
162
176
|
exports.getNamespacePolicies = getNamespacePolicies;
|
|
@@ -565,6 +579,7 @@ class KubernetesExecutor {
|
|
|
565
579
|
// The cluster as the process of a run sees it: the namespace its tasks and services go in.
|
|
566
580
|
environmentOf(run, namespace, work, capabilitiesProblem) {
|
|
567
581
|
const backend = this.config.backend;
|
|
582
|
+
const openGate = (0, network_gate_1.getOpenNetworkGate)(backend);
|
|
568
583
|
return {
|
|
569
584
|
type: 'kubernetes',
|
|
570
585
|
namespace,
|
|
@@ -585,6 +600,7 @@ class KubernetesExecutor {
|
|
|
585
600
|
// the claims of a service run go with its namespace
|
|
586
601
|
...(this.keep > 0 && !run.up ? { volumeScope: getVolumeScope(run) } : {}),
|
|
587
602
|
...(run.up ? { serviceRun: true } : {}),
|
|
603
|
+
...(openGate ? { openGate } : {}),
|
|
588
604
|
...(backend.capabilities
|
|
589
605
|
? {
|
|
590
606
|
capabilities: {
|
|
@@ -720,12 +736,21 @@ function getPrivilegedNamespaceProblem(namespace, labels, backend) {
|
|
|
720
736
|
`${namespace} ${ENFORCE_LABEL}=baseline ${AUDIT_LABEL}- --overwrite`);
|
|
721
737
|
}
|
|
722
738
|
exports.getPrivilegedNamespaceProblem = getPrivilegedNamespaceProblem;
|
|
723
|
-
// What may mount a claim a run kept: the runs of the same
|
|
724
|
-
// cache,
|
|
725
|
-
//
|
|
739
|
+
// What may mount a claim a run kept: the runs of the same branch or tag of a repository,
|
|
740
|
+
// which share its cache, so that the runs of two branches go side by side and the runs of one find what
|
|
741
|
+
// the last one left; on a sandbox the runs of that sandbox only, whose claim is on the same
|
|
742
|
+
// node or zone as the kept ones. An approved run on a sandbox keeps nothing with those runs,
|
|
743
|
+
// whose outputs nobody approved, as its cache is apart from theirs: it has a scope of its own,
|
|
744
|
+
// per sandbox, so that approved runs on two sandboxes go side by side. The owner is the namespace's.
|
|
726
745
|
function getVolumeScope(run) {
|
|
727
746
|
if (run.source.type === 'sandbox' && !run.source.check) {
|
|
728
|
-
|
|
747
|
+
const id = (0, crypto_1.createHash)('sha256').update(run.source.id).digest('hex').slice(0, 24);
|
|
748
|
+
return (run.approvals?.length ?? 0) > 0 ? `approved-${id}` : `sandbox-${id}`;
|
|
749
|
+
}
|
|
750
|
+
// a ref given as a commit hash names no branch: its runs keep the repository's claims
|
|
751
|
+
if (run.source.type === 'ref' && !/^[0-9a-f]{40}([0-9a-f]{24})?$/i.test(run.source.ref)) {
|
|
752
|
+
const key = `ref\0${run.source.repo}\0${run.source.ref}`;
|
|
753
|
+
return `ref-${(0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 24)}`;
|
|
729
754
|
}
|
|
730
755
|
return (0, executor_1.cacheNamespace)(run);
|
|
731
756
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPushRefusal = exports.KubernetesSandboxStorage = exports.getSandboxNames = void 0;
|
|
3
|
+
exports.AnswerReader = exports.getPushRefusal = exports.KubernetesSandboxStorage = exports.getSandboxNames = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -542,7 +542,9 @@ class KubernetesSandboxStorage {
|
|
|
542
542
|
// the process ends when the server stops waiting for it: closing the connection does
|
|
543
543
|
// not end a command in a pod
|
|
544
544
|
const seconds = Math.ceil((['create', 'fetch', 'move', 'archive'].includes(request.op) ? FETCH_TIMEOUT_MS : REQUEST_TIMEOUT_MS) / 1000);
|
|
545
|
-
const done = this.withPod(key, (pod) => this.exec(pod, ['timeout', String(seconds), 'hammerkit', 'server-sandbox', CLAIM_PATH], stream_1.Readable.from([Buffer.from(JSON.stringify(encoded))]), reader,
|
|
545
|
+
const done = this.withPod(key, (pod) => this.exec(pod, ['timeout', String(seconds), 'hammerkit', 'server-sandbox', CLAIM_PATH], stream_1.Readable.from([Buffer.from(JSON.stringify(encoded))]), reader,
|
|
546
|
+
// a request that failed (an answer too large) stops the command too
|
|
547
|
+
AbortSignal.any([signal, reader.stopped])));
|
|
546
548
|
done.then(() => reader.complete(), (e) => reader.fail(e));
|
|
547
549
|
const answer = await reader.answer;
|
|
548
550
|
if (!answer.header.ok) {
|
|
@@ -911,16 +913,22 @@ function holdBack(socket, stdout) {
|
|
|
911
913
|
* memory, unless the first line says it is a stream: then it is passed on as it comes.
|
|
912
914
|
*/
|
|
913
915
|
class AnswerReader extends stream_1.Writable {
|
|
914
|
-
constructor(body) {
|
|
916
|
+
constructor(body, maxBytes = MAX_ANSWER_BYTES) {
|
|
915
917
|
super();
|
|
916
918
|
this.body = body;
|
|
919
|
+
this.maxBytes = maxBytes;
|
|
917
920
|
this.chunks = [];
|
|
918
921
|
this.size = 0;
|
|
922
|
+
this.stop = new AbortController();
|
|
923
|
+
// aborted once the answer failed: nothing reads the rest
|
|
924
|
+
this.stopped = this.stop.signal;
|
|
919
925
|
this.answer = new Promise((resolve, reject) => {
|
|
920
926
|
this.resolveAnswer = resolve;
|
|
921
927
|
this.rejectAnswer = reject;
|
|
922
928
|
});
|
|
923
929
|
this.answer.catch(() => undefined);
|
|
930
|
+
// an answer that is too large or no answer at all fails the request, not the server
|
|
931
|
+
this.on('error', (e) => this.fail(e));
|
|
924
932
|
}
|
|
925
933
|
_write(chunk, _encoding, callback) {
|
|
926
934
|
if (this.stream) {
|
|
@@ -933,7 +941,7 @@ class AnswerReader extends stream_1.Writable {
|
|
|
933
941
|
return;
|
|
934
942
|
}
|
|
935
943
|
this.size += chunk.length;
|
|
936
|
-
if (this.size >
|
|
944
|
+
if (this.size > this.maxBytes) {
|
|
937
945
|
callback(new Error('the answer of the pod of the sandbox is too large'));
|
|
938
946
|
return;
|
|
939
947
|
}
|
|
@@ -986,6 +994,7 @@ class AnswerReader extends stream_1.Writable {
|
|
|
986
994
|
}
|
|
987
995
|
}
|
|
988
996
|
fail(e) {
|
|
997
|
+
this.stop.abort();
|
|
989
998
|
const error = e instanceof Error ? e : new Error(String(e));
|
|
990
999
|
if (this.stream) {
|
|
991
1000
|
this.stream.destroy(error);
|
|
@@ -993,6 +1002,7 @@ class AnswerReader extends stream_1.Writable {
|
|
|
993
1002
|
this.rejectAnswer(error);
|
|
994
1003
|
}
|
|
995
1004
|
}
|
|
1005
|
+
exports.AnswerReader = AnswerReader;
|
|
996
1006
|
// The files of a sandbox on a cluster: each call is a request to the pod of its files.
|
|
997
1007
|
class KubernetesSandboxFiles {
|
|
998
1008
|
constructor(request, rawFile) {
|
package/dist/server/oauth.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenVerifier = exports.quote = exports.TokenError = void 0;
|
|
3
|
+
exports.TokenVerifier = exports.quote = exports.TokenError = exports.displayName = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
+
/**
|
|
6
|
+
* How pages name a person: the `name` of their token, else `preferred_username`, else `email`
|
|
7
|
+
* (with the scopes `profile email`); none with `openid` alone, which carries the subject only.
|
|
8
|
+
*/
|
|
9
|
+
function displayName(principal) {
|
|
10
|
+
const claims = principal.claims ?? {};
|
|
11
|
+
for (const value of [principal.name, claims.name, claims.preferred_username, claims.email]) {
|
|
12
|
+
const trimmed = value?.trim();
|
|
13
|
+
if (trimmed) {
|
|
14
|
+
return trimmed.slice(0, 100);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
exports.displayName = displayName;
|
|
5
20
|
// The reason is for the operator's log, never for the caller.
|
|
6
21
|
class TokenError extends Error {
|
|
7
22
|
}
|
package/dist/server/overview.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.visibleCapacity = exports.filterRuns = exports.FilterRefused = exports.parseRunFilter = exports.getOverview = exports.queuePlace = exports.visibleReason = exports.toListedRun = exports.mayRead = exports.seesActivityOf = exports.seesActivity = exports.maySee = exports.decides = exports.owns = exports.mayDecide = exports.runActions = exports.getViewer = exports.describeWait = void 0;
|
|
3
|
+
exports.visibleCapacity = exports.filterRuns = exports.FilterRefused = exports.parseRunFilter = exports.getOverview = exports.queuePlace = exports.visibleReason = exports.toListedRun = exports.mayRead = exports.seesActivityOf = exports.seesActivity = exports.maySee = exports.decides = exports.owns = exports.mayDecide = exports.mayRetry = exports.runActions = exports.getViewer = exports.describeWait = void 0;
|
|
4
4
|
const policy_1 = require("./policy");
|
|
5
5
|
const runs_1 = require("./runs");
|
|
6
6
|
const service_runs_1 = require("./service-runs");
|
|
7
7
|
const repo_1 = require("./repo");
|
|
8
|
+
const units_1 = require("../utils/units");
|
|
8
9
|
var wait_reason_1 = require("./wait-reason");
|
|
9
10
|
Object.defineProperty(exports, "describeWait", { enumerable: true, get: function () { return wait_reason_1.describeWait; } });
|
|
10
11
|
function getViewer(config, principal) {
|
|
@@ -12,22 +13,46 @@ function getViewer(config, principal) {
|
|
|
12
13
|
principal,
|
|
13
14
|
grant: (0, policy_1.getGrant)(config.entitlements, principal),
|
|
14
15
|
activity: config.runs.activity === 'everyone',
|
|
16
|
+
nameOf: (owner) => (0, policy_1.subjectName)(config.entitlements, owner),
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
exports.getViewer = getViewer;
|
|
18
20
|
function runActions(viewer, run) {
|
|
19
21
|
if ((0, runs_1.isFinal)(run.state)) {
|
|
20
|
-
return undefined;
|
|
22
|
+
return mayRetry(viewer, run) ? { retry: true } : undefined;
|
|
21
23
|
}
|
|
22
24
|
const mine = owns(viewer, run);
|
|
23
25
|
const may = {
|
|
24
|
-
...(mine || decides(viewer, run)
|
|
26
|
+
...(mine || decides(viewer, run) || (run.up && (0, service_runs_1.mayPublishEndpoints)(viewer.grant, run))
|
|
27
|
+
? { stop: true }
|
|
28
|
+
: {}),
|
|
25
29
|
...(run.up && run.upAt && (mine || (0, service_runs_1.mayOpenEndpoints)(viewer.grant, run)) ? { extend: true } : {}),
|
|
26
30
|
...(mayDecide(viewer, run) ? { decide: true } : {}),
|
|
31
|
+
...(run.up && run.state === 'asleep' && (mine || (0, service_runs_1.mayOpenEndpoints)(viewer.grant, run))
|
|
32
|
+
? { wake: true }
|
|
33
|
+
: {}),
|
|
27
34
|
};
|
|
28
35
|
return Object.keys(may).length > 0 ? may : undefined;
|
|
29
36
|
}
|
|
30
37
|
exports.runActions = runActions;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the caller may start a run again, as far as the run tells: it is over, they read it
|
|
40
|
+
* whole (what a retry runs again is what they read, its arguments too), they may run anything,
|
|
41
|
+
* and from where it ran: a repository of their entitlements, or a sandbox of their own. Which
|
|
42
|
+
* accounts they may use, and whether they need an approval, is decided when they retry it.
|
|
43
|
+
*/
|
|
44
|
+
function mayRetry(viewer, run) {
|
|
45
|
+
if (!(0, runs_1.isFinal)(run.state) || !mayRead(viewer, run) || !(0, policy_1.mayRun)(viewer.grant)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (run.source.type === 'ref') {
|
|
49
|
+
return (0, repo_1.matchesAnyRepo)(viewer.grant.repos, run.source.repo);
|
|
50
|
+
}
|
|
51
|
+
// a sandbox is its owner's, while they may still keep sandboxes of its repository
|
|
52
|
+
const repo = run.source.type === 'sandbox' ? run.source.repo : undefined;
|
|
53
|
+
return (repo !== undefined && owns(viewer, run) && viewer.grant.sandboxes.some((sandbox) => (0, repo_1.matchesRepo)(sandbox.repo, repo)));
|
|
54
|
+
}
|
|
55
|
+
exports.mayRetry = mayRetry;
|
|
31
56
|
// A run that waits for an approval the caller may give: not their own.
|
|
32
57
|
function mayDecide(viewer, run) {
|
|
33
58
|
return (run.state === 'awaiting-approval' &&
|
|
@@ -85,7 +110,8 @@ function mayRead(viewer, run) {
|
|
|
85
110
|
return owns(viewer, run) || viewer.grant.observe || decides(viewer, run);
|
|
86
111
|
}
|
|
87
112
|
exports.mayRead = mayRead;
|
|
88
|
-
|
|
113
|
+
// `entryOf` names where in its repository the build file of a version is.
|
|
114
|
+
function toListedRun(viewer, run, queue, entryOf) {
|
|
89
115
|
const { owner, results, plan, options, up, error, ...rest } = run;
|
|
90
116
|
const mine = owns(viewer, run);
|
|
91
117
|
const may = runActions(viewer, run);
|
|
@@ -100,9 +126,11 @@ function toListedRun(viewer, run, queue) {
|
|
|
100
126
|
...(result.cache ? { cached: result.cache.hit } : {}),
|
|
101
127
|
},
|
|
102
128
|
]));
|
|
129
|
+
const entry = entryOf?.(run.definition);
|
|
130
|
+
const name = owner.name ?? viewer.nameOf?.(owner);
|
|
103
131
|
return {
|
|
104
132
|
...rest,
|
|
105
|
-
...(mine ? { plan, options } : { owner: { iss: owner.iss, sub: owner.sub } }),
|
|
133
|
+
...(mine ? { plan, options } : { owner: { iss: owner.iss, sub: owner.sub, ...(name ? { name } : {}) } }),
|
|
106
134
|
...(up
|
|
107
135
|
? {
|
|
108
136
|
up: {
|
|
@@ -116,6 +144,7 @@ function toListedRun(viewer, run, queue) {
|
|
|
116
144
|
...(queue ? { queue } : {}),
|
|
117
145
|
...(may ? { may } : {}),
|
|
118
146
|
...(!mine && mayRead(viewer, run) ? { readable: true } : {}),
|
|
147
|
+
...(entry ? { entry } : {}),
|
|
119
148
|
};
|
|
120
149
|
}
|
|
121
150
|
exports.toListedRun = toListedRun;
|
|
@@ -141,7 +170,8 @@ function queuePlace(registry, viewer, run) {
|
|
|
141
170
|
return { position: queue.position, waitsFor: visibleReason(queue.waitsFor, visible) };
|
|
142
171
|
}
|
|
143
172
|
exports.queuePlace = queuePlace;
|
|
144
|
-
function getOverview(snapshot, usage, viewer) {
|
|
173
|
+
function getOverview(snapshot, usage, viewer, entryOf) {
|
|
174
|
+
const list = (run, place) => toListedRun(viewer, run, place, entryOf);
|
|
145
175
|
const runs = new Map();
|
|
146
176
|
for (const run of [
|
|
147
177
|
...snapshot.running,
|
|
@@ -160,7 +190,7 @@ function getOverview(snapshot, usage, viewer) {
|
|
|
160
190
|
return {
|
|
161
191
|
...place,
|
|
162
192
|
mine: owns(viewer, entry.run),
|
|
163
|
-
...(maySee(viewer, entry.run) ? { run:
|
|
193
|
+
...(maySee(viewer, entry.run) ? { run: list(entry.run, place) } : {}),
|
|
164
194
|
};
|
|
165
195
|
});
|
|
166
196
|
const running = snapshot.running.filter((run) => maySee(viewer, run));
|
|
@@ -170,19 +200,19 @@ function getOverview(snapshot, usage, viewer) {
|
|
|
170
200
|
places: {
|
|
171
201
|
max: snapshot.places.max,
|
|
172
202
|
used: snapshot.places.used,
|
|
173
|
-
runs: running.map((run) =>
|
|
203
|
+
runs: running.map((run) => list(run)),
|
|
174
204
|
others: snapshot.running.length - running.length,
|
|
175
205
|
},
|
|
176
206
|
queue,
|
|
177
207
|
approvals: {
|
|
178
208
|
waiting: snapshot.awaiting.runs.length,
|
|
179
209
|
max: snapshot.awaiting.max,
|
|
180
|
-
runs: snapshot.awaiting.runs.filter((run) => maySee(viewer, run)).map((run) =>
|
|
210
|
+
runs: snapshot.awaiting.runs.filter((run) => maySee(viewer, run)).map((run) => list(run)),
|
|
181
211
|
},
|
|
182
212
|
services: {
|
|
183
213
|
open: snapshot.services.taken,
|
|
184
214
|
...(snapshot.services.max !== undefined ? { max: snapshot.services.max } : {}),
|
|
185
|
-
runs: snapshot.services.runs.filter((run) => maySee(viewer, run)).map((run) =>
|
|
215
|
+
runs: snapshot.services.runs.filter((run) => maySee(viewer, run)).map((run) => list(run)),
|
|
186
216
|
},
|
|
187
217
|
limits: {
|
|
188
218
|
waiting: meter(usage.waiting, limits?.waiting),
|
|
@@ -209,7 +239,7 @@ const STATES = [
|
|
|
209
239
|
'rejected',
|
|
210
240
|
];
|
|
211
241
|
// `scope`, `state` (a comma separated list) and `kind` of GET /v1/runs.
|
|
212
|
-
function parseRunFilter(params, grant) {
|
|
242
|
+
function parseRunFilter(params, grant, now = Date.now()) {
|
|
213
243
|
const scope = params.get('scope') ?? 'mine';
|
|
214
244
|
if (scope !== 'mine' && scope !== 'visible' && scope !== 'all') {
|
|
215
245
|
throw new Error('scope: mine, visible or all');
|
|
@@ -234,9 +264,35 @@ function parseRunFilter(params, grant) {
|
|
|
234
264
|
if (id !== undefined && !/^run_[A-Za-z0-9_-]{16}$/.test(id)) {
|
|
235
265
|
throw new Error('id: the id of a run, run_...');
|
|
236
266
|
}
|
|
237
|
-
|
|
267
|
+
const since = parseMoment(params.get('since'), now, 'since');
|
|
268
|
+
const until = parseMoment(params.get('until'), now, 'until');
|
|
269
|
+
if (since !== undefined && until !== undefined && until < since) {
|
|
270
|
+
throw new Error('until: after since');
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
scope,
|
|
274
|
+
...(states ? { states } : {}),
|
|
275
|
+
...(kind ? { kind } : {}),
|
|
276
|
+
...(id ? { id } : {}),
|
|
277
|
+
...(since !== undefined ? { since } : {}),
|
|
278
|
+
...(until !== undefined ? { until } : {}),
|
|
279
|
+
};
|
|
238
280
|
}
|
|
239
281
|
exports.parseRunFilter = parseRunFilter;
|
|
282
|
+
// `7d` back from now, or a time such as `2026-11-01T08:00:00Z`, in ms
|
|
283
|
+
function parseMoment(value, now, name) {
|
|
284
|
+
if (value === null) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
if (/^(\d+(\.\d+)?(ms|s|m|h|d))+$/.test(value)) {
|
|
288
|
+
return now - (0, units_1.parseDuration)(value);
|
|
289
|
+
}
|
|
290
|
+
const at = /^\d{4}-\d{2}-\d{2}/.test(value) ? Date.parse(value) : NaN;
|
|
291
|
+
if (!Number.isFinite(at)) {
|
|
292
|
+
throw new Error(`${name}: a duration back from now, such as 1h, 24h or 7d, or a time, such as 2026-11-01T08:00:00Z`);
|
|
293
|
+
}
|
|
294
|
+
return at;
|
|
295
|
+
}
|
|
240
296
|
class FilterRefused extends Error {
|
|
241
297
|
}
|
|
242
298
|
exports.FilterRefused = FilterRefused;
|
|
@@ -244,7 +300,9 @@ function filterRuns(runs, viewer, filter) {
|
|
|
244
300
|
return runs.filter((run) => (filter.scope === 'mine' ? owns(viewer, run) : maySee(viewer, run)) &&
|
|
245
301
|
(!filter.id || run.id === filter.id) &&
|
|
246
302
|
(!filter.states || filter.states.includes(run.state)) &&
|
|
247
|
-
(!filter.kind || (filter.kind === 'services') === !!run.up)
|
|
303
|
+
(!filter.kind || (filter.kind === 'services') === !!run.up) &&
|
|
304
|
+
(filter.since === undefined || Date.parse(run.createdAt) >= filter.since) &&
|
|
305
|
+
(filter.until === undefined || Date.parse(run.createdAt) <= filter.until));
|
|
248
306
|
}
|
|
249
307
|
exports.filterRuns = filterRuns;
|
|
250
308
|
// The machines and what the runs take, with whose the namespaces are where the caller may
|
|
@@ -255,6 +313,35 @@ function visibleCapacity(capacity, viewer) {
|
|
|
255
313
|
...capacity,
|
|
256
314
|
// what the cluster answered is for operators; others learn that something is missing
|
|
257
315
|
problems: viewer.grant.observe || capacity.problems.length === 0 ? capacity.problems : ['some of it could not be read'],
|
|
316
|
+
...(capacity.unknown
|
|
317
|
+
? {
|
|
318
|
+
unknown: everyone
|
|
319
|
+
? capacity.unknown
|
|
320
|
+
: {
|
|
321
|
+
...(capacity.unknown.total ? { total: 'not readable' } : {}),
|
|
322
|
+
...(capacity.unknown.used ? { used: 'not readable' } : {}),
|
|
323
|
+
},
|
|
324
|
+
}
|
|
325
|
+
: {}),
|
|
326
|
+
// what others' runs and sandboxes take shows, not what they are
|
|
327
|
+
...(capacity.uses
|
|
328
|
+
? {
|
|
329
|
+
uses: capacity.uses.map((use) => {
|
|
330
|
+
const mine = use.owner?.iss === viewer.principal.iss && use.owner?.sub === viewer.principal.sub;
|
|
331
|
+
const name = use.owner && !use.owner.name ? viewer.nameOf?.(use.owner) : undefined;
|
|
332
|
+
return everyone || mine || !use.owner
|
|
333
|
+
? name && use.owner
|
|
334
|
+
? { ...use, owner: { ...use.owner, name } }
|
|
335
|
+
: use
|
|
336
|
+
: {
|
|
337
|
+
kind: use.kind,
|
|
338
|
+
pods: use.pods,
|
|
339
|
+
requested: use.requested,
|
|
340
|
+
...(use.used ? { used: use.used } : {}),
|
|
341
|
+
};
|
|
342
|
+
}),
|
|
343
|
+
}
|
|
344
|
+
: {}),
|
|
258
345
|
groups: capacity.groups.map((group) => {
|
|
259
346
|
const mine = group.owner?.iss === viewer.principal.iss && group.owner?.sub === viewer.principal.sub;
|
|
260
347
|
if (everyone || mine || !group.owner) {
|