hammerkit 2.1.0-next.8 → 2.1.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/build.schema.json +28 -126
- package/dist/cli.js +0 -5
- package/dist/dashboard/assets/graph-canvas-DtJSpova.js +8 -0
- package/dist/dashboard/assets/index-BndChMep.css +2 -0
- package/dist/dashboard/assets/{index-CE5PSB3y.js → index-DRSwIRXd.js} +9 -15
- package/dist/dashboard/index.html +2 -2
- package/dist/docker/item-network.js +5 -6
- package/dist/docker/remove-orphaned-containers.js +4 -5
- package/dist/environment/replace-env-variables.js +5 -8
- package/dist/environment/run-source-envs.js +1 -2
- package/dist/executer/check-readiness.js +4 -8
- package/dist/executer/deadline.js +63 -10
- package/dist/executer/docker-service.js +15 -21
- package/dist/executer/execute-work-task.js +15 -3
- package/dist/harness/sandbox-client.js +1 -0
- package/dist/harness/service-tools.js +25 -1
- package/dist/kubernetes/cluster-state.js +48 -14
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +14 -62
- package/dist/kubernetes/ensure-persistent-data.js +14 -3
- package/dist/kubernetes/kept-claims.js +9 -12
- package/dist/kubernetes/resources.js +5 -1
- package/dist/optimizer/work-task-cache-description.js +3 -5
- package/dist/planner/image-build.js +0 -5
- package/dist/planner/service-definition.js +1 -2
- package/dist/planner/utils/append-work-service.js +4 -12
- package/dist/planner/utils/dependency-outputs.js +6 -7
- package/dist/planner/validate.js +0 -41
- package/dist/planner/work-healthcheck.js +2 -23
- package/dist/planner/work-runtime-docker.js +1 -24
- package/dist/planner/work-runtime-kubernetes.js +16 -37
- package/dist/planner/work-secret.js +11 -33
- package/dist/planner/work-service-id.js +6 -30
- package/dist/planner/work-service.js +2 -2
- package/dist/program.js +1 -19
- package/dist/remote/annotations.js +31 -11
- package/dist/remote/collect-bundle.js +3 -2
- package/dist/remote/remote-status.js +1 -1
- package/dist/remote/remote-work-commands.js +50 -7
- package/dist/schema/build-file-base-task-schema.js +1 -16
- package/dist/schema/build-file-image-build-schema.js +8 -5
- package/dist/schema/build-file-service-container-healthcheck.js +7 -25
- package/dist/schema/reference-parser.js +43 -108
- package/dist/schema/work-scope-parser.js +0 -8
- package/dist/secrets/prefetch-secrets.js +1 -20
- package/dist/server/capacity.js +6 -18
- package/dist/server/endpoints.js +52 -32
- package/dist/server/kubernetes-backend.js +28 -114
- package/dist/server/kubernetes-sandbox-storage.js +2 -3
- package/dist/server/overview.js +1 -7
- package/dist/server/plan.js +0 -8
- package/dist/server/public-paths.js +52 -0
- package/dist/server/run-request.js +52 -1
- package/dist/server/run-retry.js +6 -0
- package/dist/server/run-source-environment.js +1 -1
- package/dist/server/runs.js +6 -4
- package/dist/server/sandbox-files-api.js +12 -27
- package/dist/server/sandbox-files.js +2 -3
- package/dist/server/sandbox-pod.js +1 -1
- package/dist/server/sandboxes-api.js +14 -65
- package/dist/server/sandboxes.js +3 -19
- package/dist/server/server-config.js +2 -59
- package/dist/server/server.js +20 -8
- package/dist/server/service-runs.js +41 -8
- package/package.json +1 -1
- package/dist/dashboard/assets/graph-canvas-BFnEN5i0.js +0 -8
- package/dist/dashboard/assets/index-Dt3ITvRO.css +0 -2
- package/dist/executer/docker-healthcheck.js +0 -73
- package/dist/network/healthcheck-request.js +0 -38
- package/dist/server/borrowed-quota.js +0 -216
|
@@ -48,7 +48,6 @@ function getWorkContext(context, scope, environment) {
|
|
|
48
48
|
// its init task's need on it, which narrowing follows
|
|
49
49
|
const tasks = Object.values(context.tasks).map((task) => (0, append_work_task_1.appendWorkTask)(workTree, task.cwd, task, environment, context));
|
|
50
50
|
const services = Object.values(context.services).map((service) => (0, append_work_service_1.appendWorkService)(workTree, service, environment, context));
|
|
51
|
-
refuseBases(context, (0, work_scope_1.isContextTaskFilter)(scope) ? [scope.taskName] : [...(scope.names ?? []), ...(scope.taskNames ?? [])]);
|
|
52
51
|
const apply = { servicesAlone: !(0, work_scope_1.isContextTaskFilter)(scope) && !!scope.names && !!scope.stop };
|
|
53
52
|
const selectedTasks = [];
|
|
54
53
|
const selectedServices = [];
|
|
@@ -87,13 +86,6 @@ function getWorkContext(context, scope, environment) {
|
|
|
87
86
|
return filteredWorkTree;
|
|
88
87
|
}
|
|
89
88
|
exports.getWorkContext = getWorkContext;
|
|
90
|
-
// A base (`abstract: true`) is not run by its name, as it is not listed
|
|
91
|
-
function refuseBases(context, names) {
|
|
92
|
-
const base = names.find((name) => name in context.bases);
|
|
93
|
-
if (base) {
|
|
94
|
-
throw new Error(`${base} is abstract, a base for extend that doesn't run: run a task that extends it`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
89
|
// The whole build file is planned first, so a shared service lists every task
|
|
98
90
|
// and service that needs it. Those outside this run never start or end, and a
|
|
99
91
|
// service waiting for them to finish would keep the run open forever.
|
|
@@ -1,34 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prefetchSecrets =
|
|
3
|
+
exports.prefetchSecrets = void 0;
|
|
4
4
|
const plan_work_tasks_1 = require("../planner/utils/plan-work-tasks");
|
|
5
5
|
const work_secret_1 = require("../planner/work-secret");
|
|
6
6
|
const provider_values_1 = require("./provider-values");
|
|
7
|
-
function secretsOf(workTree) {
|
|
8
|
-
return [
|
|
9
|
-
...[...(0, plan_work_tasks_1.iterateWorkServices)(workTree)].flatMap((service) => ('secrets' in service.data ? service.data.secrets : [])),
|
|
10
|
-
...[...(0, plan_work_tasks_1.iterateWorkTasks)(workTree)].flatMap((task) => task.data.secrets),
|
|
11
|
-
];
|
|
12
|
-
}
|
|
13
|
-
// A secret of a provider that this machine does not declare fails a command only when the
|
|
14
|
-
// command needs it: a run needs every secret of the tasks and services it holds, the other
|
|
15
|
-
// commands the `cache: true` ones, for task ids. A task elsewhere in the build file that reads
|
|
16
|
-
// it does not stop them (ADR 0008).
|
|
17
|
-
function requireReadableSecrets(workTree, needed = () => true) {
|
|
18
|
-
for (const secret of secretsOf(workTree)) {
|
|
19
|
-
if (secret.source.type === 'unavailable' && needed(secret)) {
|
|
20
|
-
throw new Error(secret.source.error);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.requireReadableSecrets = requireReadableSecrets;
|
|
25
7
|
// Fetches the values a task id needs; a run drops the ones of the previous run
|
|
26
8
|
// first (`newRun`), any other command reuses what the run already fetched. A task id is computed synchronously and holds the
|
|
27
9
|
// digest of each `cache: true` secret, so those values must be in memory before
|
|
28
10
|
// anything asks for an id. Secrets that don't affect the id are read when their
|
|
29
11
|
// task starts, and a plan without provider secrets calls no provider.
|
|
30
12
|
async function prefetchSecrets(workTree, environment, newRun = false) {
|
|
31
|
-
requireReadableSecrets(workTree, (secret) => secret.cache);
|
|
32
13
|
if (newRun) {
|
|
33
14
|
(0, provider_values_1.beginSecretRun)(environment);
|
|
34
15
|
}
|
package/dist/server/capacity.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatMemory = exports.formatCpu = exports.HostCapacity = exports.KubernetesCapacity = exports.
|
|
3
|
+
exports.formatMemory = exports.formatCpu = exports.HostCapacity = exports.KubernetesCapacity = exports.cachedCapacity = exports.parseQuantity = void 0;
|
|
4
4
|
const os_1 = require("os");
|
|
5
5
|
const log_1 = require("../log");
|
|
6
6
|
const apply_1 = require("../kubernetes/apply");
|
|
@@ -71,16 +71,6 @@ function briefly(e, what) {
|
|
|
71
71
|
}
|
|
72
72
|
return what === 'nodes' ? 'nodes not readable' : 'metrics not readable';
|
|
73
73
|
}
|
|
74
|
-
// The CPU and memory pods may request under a quota, if it limits them
|
|
75
|
-
function getQuotaResources(hard) {
|
|
76
|
-
const cpu = (0, units_1.parseQuantity)(hard['requests.cpu'] ?? hard.cpu);
|
|
77
|
-
const memory = (0, units_1.parseQuantity)(hard['requests.memory'] ?? hard.memory);
|
|
78
|
-
if (cpu === undefined && memory === undefined) {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
return { ...(cpu !== undefined ? { cpu } : {}), ...(memory !== undefined ? { memory } : {}) };
|
|
82
|
-
}
|
|
83
|
-
exports.getQuotaResources = getQuotaResources;
|
|
84
74
|
const ENDED = ['Succeeded', 'Failed'];
|
|
85
75
|
// On Kubernetes: per namespace of the server, its pods' requests, its quota and its usage.
|
|
86
76
|
class KubernetesCapacity {
|
|
@@ -172,13 +162,11 @@ class KubernetesCapacity {
|
|
|
172
162
|
name: this.options.quotaName,
|
|
173
163
|
namespace,
|
|
174
164
|
});
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
group.share = share;
|
|
181
|
-
}
|
|
165
|
+
const hard = quota.spec?.hard ?? {};
|
|
166
|
+
const cpu = (0, units_1.parseQuantity)(hard['requests.cpu'] ?? hard.cpu);
|
|
167
|
+
const memory = (0, units_1.parseQuantity)(hard['requests.memory'] ?? hard.memory);
|
|
168
|
+
if (cpu !== undefined || memory !== undefined) {
|
|
169
|
+
group.quota = { ...(cpu !== undefined ? { cpu } : {}), ...(memory !== undefined ? { memory } : {}) };
|
|
182
170
|
}
|
|
183
171
|
}
|
|
184
172
|
catch (e) {
|
package/dist/server/endpoints.js
CHANGED
|
@@ -8,6 +8,7 @@ const net_1 = require("net");
|
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const oauth_1 = require("./oauth");
|
|
10
10
|
const policy_1 = require("./policy");
|
|
11
|
+
const public_paths_1 = require("./public-paths");
|
|
11
12
|
const service_runs_1 = require("./service-runs");
|
|
12
13
|
const units_1 = require("../utils/units");
|
|
13
14
|
const dashboard_1 = require("./dashboard");
|
|
@@ -149,25 +150,30 @@ class EndpointGateway {
|
|
|
149
150
|
return page(res, 404, 'Not found', '<p>There is no endpoint at this address.</p>');
|
|
150
151
|
}
|
|
151
152
|
const principal = await this.caller(label, req);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
// A public path of the endpoint is for anybody: a caller who may not open the run is
|
|
154
|
+
// treated as no caller there. Any other path needs a caller who may open the run.
|
|
155
|
+
const publicPath = (0, public_paths_1.isPublicPath)(found.endpoint.publicPaths, req.url ?? '');
|
|
156
|
+
const visitor = principal && this.mayOpen(principal, found.run) ? principal : null;
|
|
157
|
+
if (!visitor && !publicPath) {
|
|
158
|
+
if (!principal) {
|
|
159
|
+
return this.signIn(label, req, res, url);
|
|
160
|
+
}
|
|
156
161
|
this.options.log(`deny endpoint ${label} iss=${principal.iss} sub=${principal.sub}`);
|
|
157
162
|
return page(res, 403, 'Not allowed', `<p>You are signed in as <code>${escape(principal.sub)}</code> of <code>${escape(principal.iss)}</code>, which may not open this endpoint.</p><p><a href="${OWN_PATH}logout">Sign out</a></p>`);
|
|
158
163
|
}
|
|
159
|
-
if (url.pathname === `${OWN_PATH}status` || url.pathname === `${OWN_PATH}extend`) {
|
|
160
|
-
return this.status(label, found.run, found.endpoint,
|
|
164
|
+
if (visitor && (url.pathname === `${OWN_PATH}status` || url.pathname === `${OWN_PATH}extend`)) {
|
|
165
|
+
return this.status(label, found.run, found.endpoint, visitor, req, res, url);
|
|
161
166
|
}
|
|
162
167
|
if (url.pathname.startsWith(OWN_PATH)) {
|
|
163
168
|
return page(res, 404, 'Not found', '<p>There is no such page.</p>');
|
|
164
169
|
}
|
|
165
|
-
// a
|
|
166
|
-
|
|
170
|
+
// Only a signed-in visit keeps the services up or wakes them: a request without a caller
|
|
171
|
+
// of a public path does neither, so anybody can not keep a run awake or wake it
|
|
172
|
+
const refused = visitor ? this.registry.visit(found.run.id, this.options.mayWake) : undefined;
|
|
167
173
|
if (!found.target) {
|
|
168
|
-
return this.notUp(res, this.registry.endpoint(label)?.run ?? found.run, refused);
|
|
174
|
+
return this.notUp(res, this.registry.endpoint(label)?.run ?? found.run, refused, !!visitor);
|
|
169
175
|
}
|
|
170
|
-
this.forward(found.target,
|
|
176
|
+
this.forward(found.target, visitor, req, res);
|
|
171
177
|
}
|
|
172
178
|
// A WebSocket (or any upgrade) to an endpoint, after the same checks as a request.
|
|
173
179
|
async upgrade(label, req, socket, head) {
|
|
@@ -338,7 +344,8 @@ class EndpointGateway {
|
|
|
338
344
|
res.on('close', () => upstream.destroy());
|
|
339
345
|
req.pipe(upstream);
|
|
340
346
|
}
|
|
341
|
-
// What reaches the app: the request without the server's cookie and headers, with who asked
|
|
347
|
+
// What reaches the app: the request without the server's cookie and headers, with who asked
|
|
348
|
+
// when a caller is known; a request let through without one carries no such header.
|
|
342
349
|
forwardedHeaders(req, principal) {
|
|
343
350
|
const headers = {};
|
|
344
351
|
for (const [name, value] of Object.entries(req.headers)) {
|
|
@@ -359,29 +366,42 @@ class EndpointGateway {
|
|
|
359
366
|
headers['x-forwarded-proto'] = this.base.scheme;
|
|
360
367
|
headers['x-forwarded-host'] = req.headers.host ?? '';
|
|
361
368
|
headers['x-forwarded-for'] = req.socket.remoteAddress ?? '';
|
|
362
|
-
|
|
369
|
+
if (principal) {
|
|
370
|
+
headers['x-hammerkit-caller'] = `${principal.iss} ${principal.sub}`;
|
|
371
|
+
}
|
|
363
372
|
return headers;
|
|
364
373
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
if (
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
374
|
+
// What a request is told when the run is not up: the status and headers of its state, here
|
|
375
|
+
// once. Only a signed-in caller hears why it is not up (its owner, who stopped it, its error);
|
|
376
|
+
// anybody else hears the state alone.
|
|
377
|
+
notUp(res, run, refused, signedIn) {
|
|
378
|
+
const starting = run.state === 'queued' || run.state === 'running' || run.state === 'awaiting-approval';
|
|
379
|
+
const asleep = run.state === 'asleep';
|
|
380
|
+
if (!starting && !asleep) {
|
|
381
|
+
if (!signedIn) {
|
|
382
|
+
return page(res, 410, 'Ended', '<p>This endpoint ended.</p>');
|
|
383
|
+
}
|
|
384
|
+
const why = run.stoppedBy === 'ttl'
|
|
385
|
+
? 'its time ran out'
|
|
386
|
+
: run.stoppedBy === 'replaced'
|
|
387
|
+
? 'a newer run of the same name replaced it'
|
|
388
|
+
: run.stoppedBy
|
|
389
|
+
? `${escape(run.stoppedBy.sub)} stopped it`
|
|
390
|
+
: escape(run.error ?? run.state);
|
|
391
|
+
return page(res, 410, 'Ended', `<p>This endpoint ended${run.finishedAt ? ` at ${escape(run.finishedAt)}` : ''}: ${why}.</p><p>Ask <code>${escape(run.owner.sub)}</code> to start it again.</p>`);
|
|
392
|
+
}
|
|
393
|
+
// a page reloads until the services are up, and a sleeping run is asked again once there is a place for it
|
|
394
|
+
const seconds = asleep ? '30' : '5';
|
|
395
|
+
res.setHeader('refresh', seconds);
|
|
396
|
+
res.setHeader('retry-after', seconds);
|
|
397
|
+
const text = !signedIn
|
|
398
|
+
? asleep
|
|
399
|
+
? 'The services of this endpoint sleep, a signed-in visit wakes them.'
|
|
400
|
+
: 'The services of this endpoint are not up yet, this page reloads until they are.'
|
|
401
|
+
: asleep
|
|
402
|
+
? `The services of this endpoint sleep and can not wake now: ${escape(refused ?? 'try again')}.`
|
|
403
|
+
: `The services of this endpoint are ${run.wakes ? `waking up${run.volumesKept ? ' with the volumes they kept' : ''}` : 'starting'} (${escape(run.state)}), this page reloads until they are up.`;
|
|
404
|
+
return page(res, 503, asleep ? 'Asleep' : 'Starting', `<p>${text}</p>`);
|
|
385
405
|
}
|
|
386
406
|
async status(label, run, endpoint, principal, req, res, url) {
|
|
387
407
|
const csrf = this.sign(`csrf\0${label}\0${principal.iss}\0${principal.sub}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.awaitRunObjectsGone = exports.removeRunObjects = exports.CallerNamespaces = exports.
|
|
3
|
+
exports.awaitRunObjectsGone = exports.removeRunObjects = exports.CallerNamespaces = exports.getVolumeScope = exports.getPrivilegedNamespaceProblem = exports.getCapabilitiesProblem = exports.getPodSecurityLabels = exports.KubernetesExecutor = exports.getRunRoleBinding = exports.removeServiceRunNamespace = exports.getServerIngressPolicy = exports.getNamespacePolicies = exports.getClusterAccess = exports.isCallerNamespace = exports.SERVICE_RUN_LABEL = exports.getServiceRunNamespace = exports.getCallerNamespace = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const os_1 = require("os");
|
|
@@ -9,7 +9,6 @@ const net_1 = require("net");
|
|
|
9
9
|
const apply_1 = require("../kubernetes/apply");
|
|
10
10
|
const job_placement_1 = require("../kubernetes/job-placement");
|
|
11
11
|
const capacity_1 = require("./capacity");
|
|
12
|
-
const borrowed_quota_1 = require("./borrowed-quota");
|
|
13
12
|
const kubernetes_instance_1 = require("../kubernetes/kubernetes-instance");
|
|
14
13
|
const log_1 = require("../log");
|
|
15
14
|
const network_policy_1 = require("../kubernetes/network-policy");
|
|
@@ -260,9 +259,9 @@ exports.getRunRoleBinding = getRunRoleBinding;
|
|
|
260
259
|
* of a caller execute side by side in their namespace, up to `runs.limits.running`:
|
|
261
260
|
* the objects of a run are named and found by its run label (getItemKey), so two runs
|
|
262
261
|
* of the same task have their own. What two runs share are the claims the server keeps
|
|
263
|
-
* (`backend.keepVolumes`) of a scope (getVolumeScope)
|
|
264
|
-
*
|
|
265
|
-
*
|
|
262
|
+
* (`backend.keepVolumes`) of a scope (getVolumeScope): the runs of one scope go one at
|
|
263
|
+
* a time (exclusive). When a run ends, everything made for it is removed, but for the
|
|
264
|
+
* kept claims, which go once they expired.
|
|
266
265
|
*/
|
|
267
266
|
class KubernetesExecutor {
|
|
268
267
|
constructor(config, processEnvs, options) {
|
|
@@ -270,8 +269,7 @@ class KubernetesExecutor {
|
|
|
270
269
|
// per caller namespace, what changes objects of the whole namespace: its setup, the
|
|
271
270
|
// removal of what a stopped server left, the sweeps of kept claims. The last one waiting.
|
|
272
271
|
this.queues = new Map();
|
|
273
|
-
// per caller namespace, the runs that execute in it
|
|
274
|
-
// their volume scope
|
|
272
|
+
// per caller namespace, the runs that execute in it: by run label, their volume scope
|
|
275
273
|
this.active = new Map();
|
|
276
274
|
// per caller namespace, when its kept claims are next looked at
|
|
277
275
|
this.sweeps = new Map();
|
|
@@ -304,27 +302,13 @@ class KubernetesExecutor {
|
|
|
304
302
|
this.keep = config.backend.keepVolumes === false ? 0 : (0, units_1.parseDuration)(config.backend.keepVolumes);
|
|
305
303
|
this.keepServiceRuns = config.runs.up.keepVolumes;
|
|
306
304
|
this.log = options.log;
|
|
307
|
-
const { quota, maxQuota, pools } = config.backend;
|
|
308
|
-
if (quota && maxQuota) {
|
|
309
|
-
this.quotas = new borrowed_quota_1.BorrowedQuotas({
|
|
310
|
-
quota,
|
|
311
|
-
maxQuota,
|
|
312
|
-
room: () => (0, borrowed_quota_1.readPoolRoom)(this.instance, pools),
|
|
313
|
-
write: async (namespace, hard) => {
|
|
314
|
-
await (0, apply_1.replace)(this.instance, getNamespaceQuota(namespace, hard));
|
|
315
|
-
},
|
|
316
|
-
log: options.log,
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
305
|
this.host = new executor_1.HostExecutor({ ...options, placement: this.placement() });
|
|
320
306
|
}
|
|
321
307
|
// what the namespaces of the server's callers and service runs request and use
|
|
322
308
|
capacity() {
|
|
323
309
|
const prefix = this.config.backend.namespacePrefix;
|
|
324
|
-
const { quota, maxQuota } = this.config.backend;
|
|
325
310
|
return new capacity_1.KubernetesCapacity(this.instance, {
|
|
326
311
|
quotaName: POLICY_NAME,
|
|
327
|
-
...(quota && maxQuota ? { share: (0, capacity_1.getQuotaResources)(quota) } : {}),
|
|
328
312
|
namespaces: async () => (await this.instance.coreApi.listNamespace({ labelSelector: `${MANAGED_LABEL}=true` })).items
|
|
329
313
|
.filter((namespace) => isCallerNamespace(prefix, namespace.metadata?.name ?? ''))
|
|
330
314
|
.map((namespace) => ({
|
|
@@ -359,11 +343,7 @@ class KubernetesExecutor {
|
|
|
359
343
|
runs = new Map();
|
|
360
344
|
this.active.set(namespace, runs);
|
|
361
345
|
}
|
|
362
|
-
|
|
363
|
-
runs.set(label, getVolumeScope(run));
|
|
364
|
-
}
|
|
365
|
-
// the caller is promised its share while the run executes
|
|
366
|
-
this.quotas?.enter(namespace, run.id);
|
|
346
|
+
runs.set(label, getVolumeScope(run));
|
|
367
347
|
try {
|
|
368
348
|
await this.host.execute(run, context);
|
|
369
349
|
}
|
|
@@ -372,9 +352,6 @@ class KubernetesExecutor {
|
|
|
372
352
|
if (runs.size === 0 && this.active.get(namespace) === runs) {
|
|
373
353
|
this.active.delete(namespace);
|
|
374
354
|
}
|
|
375
|
-
await this.quotas
|
|
376
|
-
?.leave(namespace, run.id)
|
|
377
|
-
.catch((e) => this.log?.(`the quotas could not be worked out again: ${(0, log_1.getErrorMessage)(e)}`));
|
|
378
355
|
}
|
|
379
356
|
}
|
|
380
357
|
// A service run moves to another commit in its namespace: unchanged services stay, the
|
|
@@ -440,41 +417,17 @@ class KubernetesExecutor {
|
|
|
440
417
|
this.serviceRunsSwept = false;
|
|
441
418
|
}
|
|
442
419
|
}
|
|
443
|
-
// The runs of a scope share
|
|
444
|
-
//
|
|
445
|
-
//
|
|
446
|
-
|
|
447
|
-
excludes(run, other) {
|
|
448
|
-
const held = this.holds(run);
|
|
449
|
-
const theirs = this.holds(other);
|
|
450
|
-
if (!held || !theirs || held.scope !== theirs.scope) {
|
|
451
|
-
return false;
|
|
452
|
-
}
|
|
453
|
-
if (!held.tasks || !theirs.tasks) {
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
const tasks = new Set(theirs.tasks);
|
|
457
|
-
return held.tasks.some((task) => tasks.has(task));
|
|
458
|
-
}
|
|
459
|
-
// The kept claims a run mounts: its scope in the caller's namespace and the tasks of the
|
|
460
|
-
// claims (getKeptClaimTasks), all of the scope's for a run without a plan. Nothing for a
|
|
461
|
-
// run that mounts none.
|
|
462
|
-
holds(run) {
|
|
420
|
+
// The runs of a scope share its kept claims, which one of them may change at a time:
|
|
421
|
+
// what a task finds in one is what the last run left there. Without kept claims, runs
|
|
422
|
+
// share no object and nothing is held.
|
|
423
|
+
exclusive(run) {
|
|
463
424
|
if (this.keep === 0 || run.up) {
|
|
464
425
|
return undefined;
|
|
465
426
|
}
|
|
466
|
-
|
|
467
|
-
if (tasks?.length === 0) {
|
|
468
|
-
return undefined;
|
|
469
|
-
}
|
|
470
|
-
return {
|
|
471
|
-
scope: `${getCallerNamespace(this.config.backend.namespacePrefix, run.owner)}/${getVolumeScope(run)}`,
|
|
472
|
-
tasks,
|
|
473
|
-
};
|
|
427
|
+
return `${getCallerNamespace(this.config.backend.namespacePrefix, run.owner)}/${getVolumeScope(run)}`;
|
|
474
428
|
}
|
|
475
|
-
// The scopes of the runs that execute in the namespace
|
|
476
|
-
//
|
|
477
|
-
// mounts none.
|
|
429
|
+
// The scopes of the runs that execute in the namespace, but `except`'s: their kept claims
|
|
430
|
+
// are theirs to mount and stay. A server that keeps none mounts none.
|
|
478
431
|
scopesInUse(namespace, except) {
|
|
479
432
|
if (this.keep === 0) {
|
|
480
433
|
return new Set();
|
|
@@ -521,8 +474,6 @@ class KubernetesExecutor {
|
|
|
521
474
|
quota: this.config.runs.up.quota,
|
|
522
475
|
});
|
|
523
476
|
});
|
|
524
|
-
// its pods take room the callers can't borrow
|
|
525
|
-
await this.quotas?.serviceRun(namespace, this.config.runs.up.quota ?? this.config.backend.quota);
|
|
526
477
|
context.emit({ type: 'log', task: 'hammerkit', stream: 'stdout', text: `runs in the namespace ${namespace}` });
|
|
527
478
|
return { kubernetes: this.environmentOf(run, namespace), env: this.access.env };
|
|
528
479
|
}
|
|
@@ -553,9 +504,6 @@ class KubernetesExecutor {
|
|
|
553
504
|
}
|
|
554
505
|
});
|
|
555
506
|
this.sweepLeftClaims();
|
|
556
|
-
// the quota of the caller, and of the callers it borrows from or lends to, before its
|
|
557
|
-
// tasks run
|
|
558
|
-
await this.quotas?.apply(namespace);
|
|
559
507
|
context.emit({ type: 'log', task: 'hammerkit', stream: 'stdout', text: `runs in the namespace ${namespace}` });
|
|
560
508
|
return {
|
|
561
509
|
kubernetes: this.environmentOf(run, namespace, work, capabilitiesProblem),
|
|
@@ -592,9 +540,6 @@ class KubernetesExecutor {
|
|
|
592
540
|
}
|
|
593
541
|
else {
|
|
594
542
|
this.serviceRuns.delete(namespace);
|
|
595
|
-
await this.quotas
|
|
596
|
-
?.serviceRunEnded(namespace)
|
|
597
|
-
.catch((e) => this.log?.(`the quotas could not be worked out again: ${(0, log_1.getErrorMessage)(e)}`));
|
|
598
543
|
}
|
|
599
544
|
}
|
|
600
545
|
return;
|
|
@@ -791,22 +736,6 @@ function getPrivilegedNamespaceProblem(namespace, labels, backend) {
|
|
|
791
736
|
`${namespace} ${ENFORCE_LABEL}=baseline ${AUDIT_LABEL}- --overwrite`);
|
|
792
737
|
}
|
|
793
738
|
exports.getPrivilegedNamespaceProblem = getPrivilegedNamespaceProblem;
|
|
794
|
-
// The tasks of a run whose kept claims it mounts, by name: each container task of its plan,
|
|
795
|
-
// which mounts its own claim, while the tasks that depend on it and the services that mount its
|
|
796
|
-
// outputs mount it too (they have it in their plan). Another task has none: an aggregate, or a
|
|
797
|
-
// local task on a server that allows them. A kept claim is named after its task
|
|
798
|
-
// (getClaimName), so two runs with no task in common mount no claim in common, whatever
|
|
799
|
-
// their tasks are. Null for a run without a plan (submitted by a version that recorded none).
|
|
800
|
-
function getKeptClaimTasks(run) {
|
|
801
|
-
if (!run.plan) {
|
|
802
|
-
return null;
|
|
803
|
-
}
|
|
804
|
-
return Object.entries(run.plan)
|
|
805
|
-
.filter(([, task]) => task.kind === 'task' && task.runtime === 'docker')
|
|
806
|
-
.map(([name]) => name)
|
|
807
|
-
.sort();
|
|
808
|
-
}
|
|
809
|
-
exports.getKeptClaimTasks = getKeptClaimTasks;
|
|
810
739
|
// What may mount a claim a run kept: the runs of the same branch or tag of a repository,
|
|
811
740
|
// which share its cache, so that the runs of two branches go side by side and the runs of one find what
|
|
812
741
|
// the last one left; on a sandbox the runs of that sandbox only, whose claim is on the same
|
|
@@ -826,19 +755,6 @@ function getVolumeScope(run) {
|
|
|
826
755
|
return (0, executor_1.cacheNamespace)(run);
|
|
827
756
|
}
|
|
828
757
|
exports.getVolumeScope = getVolumeScope;
|
|
829
|
-
function getPolicyMetadata(namespace) {
|
|
830
|
-
return {
|
|
831
|
-
name: POLICY_NAME,
|
|
832
|
-
namespace,
|
|
833
|
-
annotations: { 'hammerkit.dev/version': (0, version_1.getVersion)() },
|
|
834
|
-
labels: { [MANAGED_LABEL]: 'true' },
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
// The ResourceQuota of a namespace of the server
|
|
838
|
-
function getNamespaceQuota(namespace, hard) {
|
|
839
|
-
return { apiVersion: 'v1', kind: 'ResourceQuota', metadata: getPolicyMetadata(namespace), spec: { hard } };
|
|
840
|
-
}
|
|
841
|
-
exports.getNamespaceQuota = getNamespaceQuota;
|
|
842
758
|
/**
|
|
843
759
|
* The namespaces of callers on the cluster: named by the caller (getCallerNamespace),
|
|
844
760
|
* made on first use, with the operator's quota.
|
|
@@ -926,9 +842,18 @@ class CallerNamespaces {
|
|
|
926
842
|
]) {
|
|
927
843
|
await (0, apply_1.replace)(this.instance, policy);
|
|
928
844
|
}
|
|
929
|
-
const metadata =
|
|
930
|
-
|
|
931
|
-
|
|
845
|
+
const metadata = {
|
|
846
|
+
name: POLICY_NAME,
|
|
847
|
+
namespace,
|
|
848
|
+
annotations: { 'hammerkit.dev/version': (0, version_1.getVersion)() },
|
|
849
|
+
labels: { [MANAGED_LABEL]: 'true' },
|
|
850
|
+
};
|
|
851
|
+
const quota = {
|
|
852
|
+
apiVersion: 'v1',
|
|
853
|
+
kind: 'ResourceQuota',
|
|
854
|
+
metadata,
|
|
855
|
+
spec: { hard: serviceRun?.quota ?? backend.quota },
|
|
856
|
+
};
|
|
932
857
|
const defaults = backend.defaultResources;
|
|
933
858
|
const limits = {
|
|
934
859
|
apiVersion: 'v1',
|
|
@@ -944,21 +869,10 @@ class CallerNamespaces {
|
|
|
944
869
|
],
|
|
945
870
|
},
|
|
946
871
|
};
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
const borrows = !!backend.maxQuota && !serviceRun;
|
|
950
|
-
if (borrows) {
|
|
951
|
-
await this.instance.objectApi.create(quota).catch((e) => {
|
|
952
|
-
if ((0, apply_1.statusCodeOf)(e) !== 409) {
|
|
953
|
-
throw e;
|
|
954
|
-
}
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
const objects = [
|
|
958
|
-
...(borrows ? [] : [[quota, !!hard]]),
|
|
872
|
+
for (const [object, wanted] of [
|
|
873
|
+
[quota, !!(serviceRun?.quota ?? backend.quota)],
|
|
959
874
|
[limits, !!defaults],
|
|
960
|
-
]
|
|
961
|
-
for (const [object, wanted] of objects) {
|
|
875
|
+
]) {
|
|
962
876
|
if (wanted) {
|
|
963
877
|
await (0, apply_1.replace)(this.instance, object);
|
|
964
878
|
}
|
|
@@ -1030,9 +1030,8 @@ class KubernetesSandboxFiles {
|
|
|
1030
1030
|
changes() {
|
|
1031
1031
|
return this.ask({ op: 'changes' });
|
|
1032
1032
|
}
|
|
1033
|
-
diff(format, author
|
|
1034
|
-
|
|
1035
|
-
return this.ask({ op: 'diff', format, author, ...(paths ? { paths } : {}) });
|
|
1033
|
+
diff(format, author) {
|
|
1034
|
+
return this.ask({ op: 'diff', format, author });
|
|
1036
1035
|
}
|
|
1037
1036
|
async commit(author) {
|
|
1038
1037
|
return (await this.ask({ op: 'commit', author })) ?? undefined;
|
package/dist/server/overview.js
CHANGED
|
@@ -238,7 +238,7 @@ const STATES = [
|
|
|
238
238
|
'cancelled',
|
|
239
239
|
'rejected',
|
|
240
240
|
];
|
|
241
|
-
// `scope`, `state` (a comma separated list)
|
|
241
|
+
// `scope`, `state` (a comma separated list) and `kind` of GET /v1/runs.
|
|
242
242
|
function parseRunFilter(params, grant, now = Date.now()) {
|
|
243
243
|
const scope = params.get('scope') ?? 'mine';
|
|
244
244
|
if (scope !== 'mine' && scope !== 'visible' && scope !== 'all') {
|
|
@@ -264,10 +264,6 @@ function parseRunFilter(params, grant, now = Date.now()) {
|
|
|
264
264
|
if (id !== undefined && !/^run_[A-Za-z0-9_-]{16}$/.test(id)) {
|
|
265
265
|
throw new Error('id: the id of a run, run_...');
|
|
266
266
|
}
|
|
267
|
-
const sandbox = params.get('sandbox') ?? undefined;
|
|
268
|
-
if (sandbox !== undefined && !runs_1.SANDBOX_ID_PATTERN.test(sandbox)) {
|
|
269
|
-
throw new Error('sandbox: the id of a sandbox, sbx_...');
|
|
270
|
-
}
|
|
271
267
|
const since = parseMoment(params.get('since'), now, 'since');
|
|
272
268
|
const until = parseMoment(params.get('until'), now, 'until');
|
|
273
269
|
if (since !== undefined && until !== undefined && until < since) {
|
|
@@ -278,7 +274,6 @@ function parseRunFilter(params, grant, now = Date.now()) {
|
|
|
278
274
|
...(states ? { states } : {}),
|
|
279
275
|
...(kind ? { kind } : {}),
|
|
280
276
|
...(id ? { id } : {}),
|
|
281
|
-
...(sandbox ? { sandbox } : {}),
|
|
282
277
|
...(since !== undefined ? { since } : {}),
|
|
283
278
|
...(until !== undefined ? { until } : {}),
|
|
284
279
|
};
|
|
@@ -304,7 +299,6 @@ exports.FilterRefused = FilterRefused;
|
|
|
304
299
|
function filterRuns(runs, viewer, filter) {
|
|
305
300
|
return runs.filter((run) => (filter.scope === 'mine' ? owns(viewer, run) : maySee(viewer, run)) &&
|
|
306
301
|
(!filter.id || run.id === filter.id) &&
|
|
307
|
-
(!filter.sandbox || (run.source.type === 'sandbox' && run.source.id === filter.sandbox)) &&
|
|
308
302
|
(!filter.states || filter.states.includes(run.state)) &&
|
|
309
303
|
(!filter.kind || (filter.kind === 'services') === !!run.up) &&
|
|
310
304
|
(filter.since === undefined || Date.parse(run.createdAt) >= filter.since) &&
|
package/dist/server/plan.js
CHANGED
|
@@ -19,7 +19,6 @@ const parse_error_1 = require("../schema/parse-error");
|
|
|
19
19
|
const task_arguments_1 = require("../planner/utils/task-arguments");
|
|
20
20
|
const work_network_1 = require("../planner/work-network");
|
|
21
21
|
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
22
|
-
const prefetch_secrets_1 = require("../secrets/prefetch-secrets");
|
|
23
22
|
class DefinitionError extends Error {
|
|
24
23
|
}
|
|
25
24
|
exports.DefinitionError = DefinitionError;
|
|
@@ -168,9 +167,6 @@ function describeSecret(secret) {
|
|
|
168
167
|
if (source.type === 'provider') {
|
|
169
168
|
return { from: `${source.provider}:${source.ref}`, account: source.account, target };
|
|
170
169
|
}
|
|
171
|
-
if (source.type === 'unavailable') {
|
|
172
|
-
return { from: source.from, account: null, target };
|
|
173
|
-
}
|
|
174
170
|
return { from: source.type === 'env' ? `env:${source.name}` : `file:${source.path}`, account: null, target };
|
|
175
171
|
}
|
|
176
172
|
// What a server refuses to publish. A secret that reads a file or a variable of the
|
|
@@ -427,10 +423,6 @@ async function planBundle(bundle, environment, options = {}) {
|
|
|
427
423
|
}
|
|
428
424
|
const context = await (0, reference_parser_1.parseReferences)(ctx, scope, inspected);
|
|
429
425
|
const workTree = (0, work_scope_parser_1.getWorkContext)(context, options.scope ?? { environmentName: null }, inspected);
|
|
430
|
-
// the server's providers and accounts are the ones that count: a task it could never read
|
|
431
|
-
// a secret of is refused when it is published, and a run when it is planned (only the
|
|
432
|
-
// tasks and services of the run count then)
|
|
433
|
-
(0, prefetch_secrets_1.requireReadableSecrets)(workTree);
|
|
434
426
|
const items = itemsOf(workTree);
|
|
435
427
|
if (options.policy) {
|
|
436
428
|
const policyProblems = findPolicyProblems(items, options.policy, directory);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPublicPath = exports.publicPathProblem = void 0;
|
|
4
|
+
// A segment of a path a public path or a request is made of: letters, digits and . _ ~ -
|
|
5
|
+
const SEGMENT = /^[A-Za-z0-9._~-]+$/;
|
|
6
|
+
const isDotSegment = (segment) => segment === '.' || segment === '..';
|
|
7
|
+
/**
|
|
8
|
+
* Why a configured public path (such as `/mcp` or `/.well-known`) can not be one, or null
|
|
9
|
+
* when it can. It is a path of plain segments with no `.` or `..`, and never the server's own.
|
|
10
|
+
*/
|
|
11
|
+
function publicPathProblem(path) {
|
|
12
|
+
const segments = path.slice(1).split('/');
|
|
13
|
+
if (!path.startsWith('/') || segments.some((segment) => !SEGMENT.test(segment))) {
|
|
14
|
+
return 'expected a path like /mcp or /.well-known, with letters, digits, . _ ~ - and /';
|
|
15
|
+
}
|
|
16
|
+
if (segments.some(isDotSegment)) {
|
|
17
|
+
return 'a public path has no . or .. segment';
|
|
18
|
+
}
|
|
19
|
+
if (segments[0] === '.hammerkit') {
|
|
20
|
+
return "the server's own paths can not be public";
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
exports.publicPathProblem = publicPathProblem;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a request for `target` (the request target, query included) is for one of the
|
|
27
|
+
* public paths of its endpoint, which is the path itself and everything below it, by
|
|
28
|
+
* segments: `/mcp` takes `/mcp/oauth/token`, not `/mcpx`. A target that is not in its plain
|
|
29
|
+
* form (an empty, dot, or escaped segment, a backslash, a `%`) is never public: such a path
|
|
30
|
+
* could read as another one to the app, so it needs the sign-in like any other.
|
|
31
|
+
*/
|
|
32
|
+
function isPublicPath(publicPaths, target) {
|
|
33
|
+
if (!publicPaths?.length) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const path = target.split('?')[0];
|
|
37
|
+
if (!path.startsWith('/')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const segments = path.slice(1).split('/');
|
|
41
|
+
// a trailing slash is an empty last segment, which a request may end with
|
|
42
|
+
const plain = segments.every((segment, index) => (segment !== '' || index === segments.length - 1) && (segment === '' || SEGMENT.test(segment)));
|
|
43
|
+
if (!plain || segments.some(isDotSegment)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return publicPaths.some((publicPath) => {
|
|
47
|
+
const wanted = publicPath.slice(1).split('/');
|
|
48
|
+
return segments.length >= wanted.length && wanted.every((segment, index) => segments[index] === segment);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.isPublicPath = isPublicPath;
|
|
52
|
+
//# sourceMappingURL=public-paths.js.map
|