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.
Files changed (69) hide show
  1. package/build.schema.json +28 -126
  2. package/dist/cli.js +0 -5
  3. package/dist/dashboard/assets/graph-canvas-DtJSpova.js +8 -0
  4. package/dist/dashboard/assets/index-BndChMep.css +2 -0
  5. package/dist/dashboard/assets/{index-CE5PSB3y.js → index-DRSwIRXd.js} +9 -15
  6. package/dist/dashboard/index.html +2 -2
  7. package/dist/docker/item-network.js +5 -6
  8. package/dist/docker/remove-orphaned-containers.js +4 -5
  9. package/dist/environment/replace-env-variables.js +5 -8
  10. package/dist/environment/run-source-envs.js +1 -2
  11. package/dist/executer/check-readiness.js +4 -8
  12. package/dist/executer/deadline.js +63 -10
  13. package/dist/executer/docker-service.js +15 -21
  14. package/dist/executer/execute-work-task.js +15 -3
  15. package/dist/harness/sandbox-client.js +1 -0
  16. package/dist/harness/service-tools.js +25 -1
  17. package/dist/kubernetes/cluster-state.js +48 -14
  18. package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +14 -62
  19. package/dist/kubernetes/ensure-persistent-data.js +14 -3
  20. package/dist/kubernetes/kept-claims.js +9 -12
  21. package/dist/kubernetes/resources.js +5 -1
  22. package/dist/optimizer/work-task-cache-description.js +3 -5
  23. package/dist/planner/image-build.js +0 -5
  24. package/dist/planner/service-definition.js +1 -2
  25. package/dist/planner/utils/append-work-service.js +4 -12
  26. package/dist/planner/utils/dependency-outputs.js +6 -7
  27. package/dist/planner/validate.js +0 -41
  28. package/dist/planner/work-healthcheck.js +2 -23
  29. package/dist/planner/work-runtime-docker.js +1 -24
  30. package/dist/planner/work-runtime-kubernetes.js +16 -37
  31. package/dist/planner/work-secret.js +11 -33
  32. package/dist/planner/work-service-id.js +6 -30
  33. package/dist/planner/work-service.js +2 -2
  34. package/dist/program.js +1 -19
  35. package/dist/remote/annotations.js +31 -11
  36. package/dist/remote/collect-bundle.js +3 -2
  37. package/dist/remote/remote-status.js +1 -1
  38. package/dist/remote/remote-work-commands.js +50 -7
  39. package/dist/schema/build-file-base-task-schema.js +1 -16
  40. package/dist/schema/build-file-image-build-schema.js +8 -5
  41. package/dist/schema/build-file-service-container-healthcheck.js +7 -25
  42. package/dist/schema/reference-parser.js +43 -108
  43. package/dist/schema/work-scope-parser.js +0 -8
  44. package/dist/secrets/prefetch-secrets.js +1 -20
  45. package/dist/server/capacity.js +6 -18
  46. package/dist/server/endpoints.js +52 -32
  47. package/dist/server/kubernetes-backend.js +28 -114
  48. package/dist/server/kubernetes-sandbox-storage.js +2 -3
  49. package/dist/server/overview.js +1 -7
  50. package/dist/server/plan.js +0 -8
  51. package/dist/server/public-paths.js +52 -0
  52. package/dist/server/run-request.js +52 -1
  53. package/dist/server/run-retry.js +6 -0
  54. package/dist/server/run-source-environment.js +1 -1
  55. package/dist/server/runs.js +6 -4
  56. package/dist/server/sandbox-files-api.js +12 -27
  57. package/dist/server/sandbox-files.js +2 -3
  58. package/dist/server/sandbox-pod.js +1 -1
  59. package/dist/server/sandboxes-api.js +14 -65
  60. package/dist/server/sandboxes.js +3 -19
  61. package/dist/server/server-config.js +2 -59
  62. package/dist/server/server.js +20 -8
  63. package/dist/server/service-runs.js +41 -8
  64. package/package.json +1 -1
  65. package/dist/dashboard/assets/graph-canvas-BFnEN5i0.js +0 -8
  66. package/dist/dashboard/assets/index-Dt3ITvRO.css +0 -2
  67. package/dist/executer/docker-healthcheck.js +0 -73
  68. package/dist/network/healthcheck-request.js +0 -38
  69. package/dist/server/borrowed-quota.js +0 -216
@@ -1,20 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runRequestSchema = exports.runOptionsSchema = exports.MAX_ARGS_BYTES = exports.MAX_ARGS = exports.MAX_ENDPOINTS = exports.SERVICE_RUN_NAME_PATTERN = void 0;
3
+ exports.runRequestSchema = exports.runOptionsSchema = exports.MAX_ARGS_BYTES = exports.MAX_ARGS = exports.MAX_PUBLIC_PATHS = exports.MAX_ENDPOINTS = exports.SERVICE_RUN_NAME_PATTERN = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const units_1 = require("../utils/units");
6
6
  const bundle_1 = require("../remote/bundle");
7
7
  const repo_1 = require("./repo");
8
8
  const runs_1 = require("./runs");
9
+ const public_paths_1 = require("./public-paths");
9
10
  const name = zod_1.z.string().min(1).max(200);
10
11
  // The name of a service run, one DNS label: the hosts of its endpoints carry it, and a run of
11
12
  // the same caller with the same name replaces it
12
13
  exports.SERVICE_RUN_NAME_PATTERN = /^[a-z0-9]([a-z0-9-]{0,38}[a-z0-9])?$/;
13
14
  // endpoints one service run may publish
14
15
  exports.MAX_ENDPOINTS = 5;
16
+ // public paths one endpoint may have
17
+ exports.MAX_PUBLIC_PATHS = 10;
15
18
  // what one run may pass after `--`
16
19
  exports.MAX_ARGS = 100;
17
20
  exports.MAX_ARGS_BYTES = 16 * 1024;
21
+ // a path of an endpoint that needs no sign-in of the server, see isPublicPath
22
+ const publicPath = zod_1.z.string().superRefine((path, ctx) => {
23
+ const problem = (0, public_paths_1.publicPathProblem)(path);
24
+ if (problem) {
25
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: problem });
26
+ }
27
+ });
18
28
  // What `POST /v1/runs` takes. Who is asking and which accounts they may use is
19
29
  // decided from the token, never from this body; the accounts a run uses are those
20
30
  // its secrets are read as, which the server derives from the published build file.
@@ -124,6 +134,22 @@ exports.runRequestSchema = zod_1.z
124
134
  .array(zod_1.z.object({ service: name, port: zod_1.z.number().int().min(1).max(65535) }).strict())
125
135
  .max(exports.MAX_ENDPOINTS)
126
136
  .default([]),
137
+ // paths of those endpoints that need no sign-in of the server, such as an app's own sign-in
138
+ // for an MCP client; the run they are written for must be the one the run gets (see
139
+ // refusePublicPaths), and the endpoint one the run publishes
140
+ publicPaths: zod_1.z
141
+ .array(zod_1.z
142
+ .object({
143
+ run: zod_1.z
144
+ .string()
145
+ .regex(exports.SERVICE_RUN_NAME_PATTERN, 'expected lower case letters, digits and -, at most 40, as a DNS label'),
146
+ service: name,
147
+ port: zod_1.z.number().int().min(1).max(65535),
148
+ paths: zod_1.z.array(publicPath).min(1).max(exports.MAX_PUBLIC_PATHS),
149
+ })
150
+ .strict())
151
+ .max(exports.MAX_ENDPOINTS)
152
+ .default([]),
127
153
  })
128
154
  .strict()
129
155
  .refine((request) => request.services.length > 0 || request.tasks.length > 0 || (request.options.filter ?? []).length > 0, {
@@ -147,6 +173,31 @@ exports.runRequestSchema = zod_1.z
147
173
  request.endpoints.length === 0), { message: 'ttl, sleepTtl, name and endpoints are for a run of services', path: ['services'] })
148
174
  .refine((request) => new Set(request.endpoints.map((endpoint) => `${endpoint.service}:${endpoint.port}`)).size ===
149
175
  request.endpoints.length, { message: 'an endpoint is named twice', path: ['endpoints'] })
176
+ .refine((request) => request.publicPaths.length === 0 || request.services.length > 0, {
177
+ message: 'public paths are for a run of services',
178
+ path: ['publicPaths'],
179
+ })
180
+ .superRefine((request, ctx) => {
181
+ const seen = new Set();
182
+ for (const entry of request.publicPaths) {
183
+ const endpoint = `${entry.service}:${entry.port}`;
184
+ if (!request.endpoints.some((published) => published.service === entry.service && published.port === entry.port)) {
185
+ ctx.addIssue({
186
+ code: zod_1.z.ZodIssueCode.custom,
187
+ message: `a public path names ${endpoint}, which the run does not publish`,
188
+ path: ['publicPaths'],
189
+ });
190
+ }
191
+ if (seen.has(endpoint)) {
192
+ ctx.addIssue({
193
+ code: zod_1.z.ZodIssueCode.custom,
194
+ message: 'an endpoint has its public paths named twice',
195
+ path: ['publicPaths'],
196
+ });
197
+ }
198
+ seen.add(endpoint);
199
+ }
200
+ })
150
201
  .refine((request) => (request.options.args ?? []).length === 0 || request.tasks.length === 1, {
151
202
  message: 'arguments go to one task, name exactly one in tasks',
152
203
  path: ['options', 'args'],
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRetryRequest = void 0;
4
4
  const runs_1 = require("./runs");
5
5
  const run_request_1 = require("./run-request");
6
+ // The public paths of the endpoints of a service run, for the run started again under its name
7
+ function publicPathsOf(up) {
8
+ const { name } = up;
9
+ return up.endpoints.flatMap(({ service, port, publicPaths }) => publicPaths ? [{ run: name, service, port, paths: publicPaths }] : []);
10
+ }
6
11
  /**
7
12
  * A retry (`POST /v1/runs/<id>/retry`) is the request the run was started with, sent again by
8
13
  * who retries it: the same published build file, tasks or services, settings and arguments,
@@ -44,6 +49,7 @@ function getRetryRequest(run, owner) {
44
49
  ...(run.up.sleepTtl ? { sleepTtl: `${run.up.sleepTtl}ms` } : {}),
45
50
  name: run.up.name,
46
51
  endpoints: run.up.endpoints.map(({ service, port }) => ({ service, port })),
52
+ publicPaths: publicPathsOf(run.up),
47
53
  }
48
54
  : {}),
49
55
  });
@@ -9,7 +9,7 @@ const COMMIT = /^[0-9a-f]{40}([0-9a-f]{24})?$/i;
9
9
  // repository, and the branch or tag and the commit it was pinned to, or the repository and the
10
10
  // sandbox. None of them is a credential, so a task that reads them still takes arguments and
11
11
  // keeps its network (see PLAIN_SERVER_ENVS). A sandbox has no commit: its files may hold
12
- // changes. A run from an upload has none of them. Each is a name of RUN_SOURCE_ENVS.
12
+ // changes. A run from an upload has none of them.
13
13
  function runSourceEnvironment(source) {
14
14
  if (source.type === 'ref') {
15
15
  return {
@@ -817,13 +817,15 @@ class RunRegistry {
817
817
  return [...this.entries.values()].find((entry) => entry.run.state === 'running' && onSandbox(entry.run, source.id))
818
818
  ?.run.id;
819
819
  }
820
- // The run that executes and holds what the run would (RunExecutor.excludes)
820
+ // The run that executes and holds what the run would (RunExecutor.exclusive)
821
821
  held(run) {
822
- const executor = this.options.executor;
823
- if (!executor.excludes) {
822
+ const exclusive = this.options.executor.exclusive?.bind(this.options.executor);
823
+ const key = exclusive?.(run);
824
+ if (key === undefined) {
824
825
  return undefined;
825
826
  }
826
- return [...this.entries.values()].find((entry) => entry.run.state === 'running' && entry.run.id !== run.id && executor.excludes?.(run, entry.run))?.run.id;
827
+ return [...this.entries.values()].find((entry) => entry.run.state === 'running' && exclusive?.(entry.run) === key)
828
+ ?.run.id;
827
829
  }
828
830
  // What keeps a queued run from starting, checked as dispatch checks it: what holds it
829
831
  // even when a place frees up is named first.
@@ -76,14 +76,10 @@ const searchSchema = zod_1.z.preprocess((body) => {
76
76
  * PUT /v1/sandboxes/<id>/files/<path> write bytes, If-Match: "<sha256>"
77
77
  * POST /v1/sandboxes/<id>/search ripgrep
78
78
  * POST /v1/sandboxes/<id>/edits { dryRun, ops }, all or nothing
79
- * GET /v1/sandboxes/<id>/changes?format=summary|diff|patch (diff: &path=… for some files)
79
+ * GET /v1/sandboxes/<id>/changes?format=summary|diff|patch
80
80
  *
81
81
  * Reading a file works at any time. Writes, and the reads that walk the files (tree, search,
82
82
  * changes), are `409` while a run holds the sandbox.
83
- *
84
- * Who may read the sandbox, its owner and who observes, was decided by `handleSandboxes`:
85
- * reads go as its owner. Writes go as the caller, so the registry answers anybody but the
86
- * owner `404`.
87
83
  */
88
84
  async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, path, req, res, url) {
89
85
  const who = `iss=${principal.iss} sub=${principal.sub}`;
@@ -103,7 +99,7 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
103
99
  limit: intParam(url, 'limit'),
104
100
  cursor: url.searchParams.get('cursor') ?? undefined,
105
101
  };
106
- const tree = await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.tree(query));
102
+ const tree = await sandboxes.read(principal, sandbox.id, (files) => files.tree(query));
107
103
  (0, http_1.send)(res, 200, tree);
108
104
  }
109
105
  else if (action === 'search') {
@@ -111,7 +107,7 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
111
107
  return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'POST' });
112
108
  }
113
109
  const query = parse(searchSchema, await (0, http_1.readJson)(req));
114
- (0, http_1.send)(res, 200, await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.search(query)));
110
+ (0, http_1.send)(res, 200, await sandboxes.read(principal, sandbox.id, (files) => files.search(query)));
115
111
  }
116
112
  else if (action === 'edits') {
117
113
  if (method !== 'POST') {
@@ -128,7 +124,7 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
128
124
  if (method !== 'GET') {
129
125
  return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'GET' });
130
126
  }
131
- await handleChanges(sandboxes, sandbox, res, url);
127
+ await handleChanges(sandboxes, principal, sandbox, res, url);
132
128
  }
133
129
  }
134
130
  catch (e) {
@@ -144,10 +140,9 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
144
140
  exports.handleSandboxFiles = handleSandboxFiles;
145
141
  async function handleFile(sandboxes, log, principal, sandbox, path, req, res, url) {
146
142
  const method = req.method;
147
- // reading, as its owner
148
- const files = () => sandboxes.files(sandbox.owner, sandbox.id);
143
+ const files = sandboxes.files(principal, sandbox.id);
149
144
  if (method === 'HEAD') {
150
- const stat = await files().stat(path);
145
+ const stat = await files.stat(path);
151
146
  if (!stat) {
152
147
  res.writeHead(404, { 'cache-control': 'no-store' });
153
148
  res.end();
@@ -158,11 +153,11 @@ async function handleFile(sandboxes, log, principal, sandbox, path, req, res, ur
158
153
  }
159
154
  else if (method === 'GET') {
160
155
  if (url.searchParams.has('stat')) {
161
- const stat = await files().stat(path);
156
+ const stat = await files.stat(path);
162
157
  return stat ? (0, http_1.send)(res, 200, stat) : (0, http_1.send)(res, 404, { error: `${path} does not exist` });
163
158
  }
164
159
  if (url.searchParams.has('raw')) {
165
- const raw = await files().raw(path);
160
+ const raw = await files.raw(path);
166
161
  const headers = { ...statHeaders(raw.stat), 'content-type': 'application/octet-stream' };
167
162
  if (raw.content) {
168
163
  res.writeHead(200, { ...headers, etag: `"${raw.sha256}"` });
@@ -184,7 +179,7 @@ async function handleFile(sandboxes, log, principal, sandbox, path, req, res, ur
184
179
  });
185
180
  return;
186
181
  }
187
- (0, http_1.send)(res, 200, await files().read(path, { offset: intParam(url, 'offset'), limit: intParam(url, 'limit') }));
182
+ (0, http_1.send)(res, 200, await files.read(path, { offset: intParam(url, 'offset'), limit: intParam(url, 'limit') }));
188
183
  }
189
184
  else if (method === 'PUT') {
190
185
  const content = await readBytes(req, sandbox_files_1.MAX_FILE_BYTES);
@@ -203,12 +198,10 @@ async function handleFile(sandboxes, log, principal, sandbox, path, req, res, ur
203
198
  (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'GET, HEAD, PUT' });
204
199
  }
205
200
  }
206
- // the most files one diff may name
207
- const MAX_DIFF_PATHS = 100;
208
- async function handleChanges(sandboxes, sandbox, res, url) {
201
+ async function handleChanges(sandboxes, principal, sandbox, res, url) {
209
202
  const format = url.searchParams.get('format') ?? 'summary';
210
203
  if (format === 'summary') {
211
- const files = await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.changes());
204
+ const files = await sandboxes.read(principal, sandbox.id, (files) => files.changes());
212
205
  return (0, http_1.send)(res, 200, { commit: sandbox.commit, files });
213
206
  }
214
207
  if (format !== 'diff' && format !== 'patch') {
@@ -219,15 +212,7 @@ async function handleChanges(sandboxes, sandbox, res, url) {
219
212
  email: textParam(url, 'email') ?? 'hammerkit@localhost',
220
213
  message: textParam(url, 'message', 4000, true) ?? `Changes of sandbox ${sandbox.id}`,
221
214
  };
222
- // the diff of some files only, as a list of changes opens one; a rename names both its paths
223
- const paths = url.searchParams.getAll('path');
224
- if (paths.length > 0 && format !== 'diff') {
225
- return (0, http_1.send)(res, 400, { error: 'path: only a diff takes paths, a patch is whole' });
226
- }
227
- if (paths.length > MAX_DIFF_PATHS || paths.some((path) => path === '' || path.length > 4096 || path.includes('\0'))) {
228
- return (0, http_1.send)(res, 400, { error: `path: at most ${MAX_DIFF_PATHS}, each a path of the sandbox` });
229
- }
230
- const text = await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.diff(format, author, paths.length > 0 ? paths : undefined));
215
+ const text = await sandboxes.read(principal, sandbox.id, (files) => files.diff(format, author));
231
216
  res.writeHead(200, { 'content-type': 'text/x-diff; charset=utf-8', 'cache-control': 'no-store' });
232
217
  res.end(text);
233
218
  }
@@ -822,11 +822,10 @@ class HostSandboxFiles {
822
822
  return files;
823
823
  });
824
824
  }
825
- async diff(format, author, paths) {
825
+ async diff(format, author) {
826
826
  return this.withFilesIndex(async (run) => {
827
827
  if (format === 'diff') {
828
- const only = paths && paths.length > 0 ? ['--', ...paths.map((path) => `:(literal)${path}`)] : [];
829
- return run(['diff', '--cached', '-M', 'HEAD', ...only], 'read', { maxBuffer: this.maxChangesBytes });
828
+ return run(['diff', '--cached', '-M', 'HEAD'], 'read', { maxBuffer: this.maxChangesBytes });
830
829
  }
831
830
  // a commit of the changes on top of the commit the sandbox is at, which no branch
832
831
  // points to, written out as `git format-patch` writes it
@@ -80,7 +80,7 @@ async function answer(storage, directory, request, out) {
80
80
  case 'changes':
81
81
  return send(await files().changes());
82
82
  case 'diff':
83
- return send(await files().diff(request.format, request.author, request.paths));
83
+ return send(await files().diff(request.format, request.author));
84
84
  case 'commit':
85
85
  return send((await storage.commit(key, request.author, AbortSignal.timeout(10 * 60000))) ?? null);
86
86
  case 'move':
@@ -45,8 +45,7 @@ const pushSchema = zod_1.z
45
45
  * The sandboxes of a caller: checkouts on the server that runs work on.
46
46
  *
47
47
  * POST /v1/sandboxes { repo, ref } fetch a branch into a new sandbox
48
- * GET /v1/sandboxes the caller's sandboxes, their limits and usage;
49
- * `?scope=all` everybody's, with `observe`
48
+ * GET /v1/sandboxes the caller's sandboxes, their limits and usage
50
49
  * GET /v1/sandboxes/<id> one sandbox
51
50
  * DELETE /v1/sandboxes/<id> cancel its runs and remove it
52
51
  * POST /v1/sandboxes/<id>/fetch { ref } move a sandbox without changes to a branch's commit
@@ -54,10 +53,7 @@ const pushSchema = zod_1.z
54
53
  * ... /v1/sandboxes/<id>/tree, files/<path>, search, edits, changes: its files, see
55
54
  * `handleSandboxFiles`
56
55
  *
57
- * A sandbox is its owner's: anybody else gets `404`. Who observes (`observe` on an
58
- * entitlement) may read every sandbox, as they read every run: list them, and get one, its
59
- * tree, files, search and changes. Everything that changes a sandbox or runs on it stays
60
- * its owner's, and is `404` to them too.
56
+ * A sandbox is its owner's: anybody else gets `404`.
61
57
  */
62
58
  async function handleSandboxes(config, sandboxes, repos, log, principal, req, res, url) {
63
59
  const match = /^\/v1\/sandboxes(?:\/([^/]+)(?:\/(fetch|push|tree|search|edits|changes)|\/(files)\/(.+))?)?$/.exec(url.pathname);
@@ -68,23 +64,12 @@ async function handleSandboxes(config, sandboxes, repos, log, principal, req, re
68
64
  const action = named ?? files;
69
65
  const method = req.method;
70
66
  const who = `iss=${principal.iss} sub=${principal.sub}`;
71
- const show = (sandbox) => view(config, sandboxes, principal, sandbox);
72
67
  try {
73
68
  if (!id) {
74
69
  if (method === 'GET') {
75
- const scope = url.searchParams.get('scope') ?? 'mine';
76
- if (scope !== 'mine' && scope !== 'all') {
77
- (0, http_1.send)(res, 400, { error: 'scope: mine or all' });
78
- return true;
79
- }
80
- if (scope === 'all' && !(0, policy_1.getGrant)(config.entitlements, principal).observe) {
81
- (0, http_1.send)(res, 403, { error: 'scope all needs an entitlement with observe' });
82
- return true;
83
- }
84
70
  const limits = sandboxes.limits;
85
- // the limits and the usage are the caller's, whichever sandboxes they list
86
71
  (0, http_1.send)(res, 200, {
87
- sandboxes: (scope === 'all' ? sandboxes.all() : sandboxes.list(principal)).map(show),
72
+ sandboxes: sandboxes.list(principal).map((sandbox) => view(sandboxes, sandbox)),
88
73
  limits: { count: limits.count, bytes: limits.bytes },
89
74
  used: sandboxes.usage(principal),
90
75
  });
@@ -99,29 +84,21 @@ async function handleSandboxes(config, sandboxes, repos, log, principal, req, re
99
84
  }
100
85
  const sandbox = await sandboxes.create(principal, body.repo, body.ref);
101
86
  log(`sandbox create ${sandbox.id} ${who} repo=${sandbox.repo} commit=${sandbox.commit} bytes=${sandbox.bytes}`);
102
- (0, http_1.send)(res, 201, show(sandbox));
87
+ (0, http_1.send)(res, 201, view(sandboxes, sandbox));
103
88
  }
104
89
  else {
105
90
  (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'GET, POST' });
106
91
  }
107
92
  return true;
108
93
  }
109
- const known = runs_1.SANDBOX_ID_PATTERN.test(id);
110
- const own = known ? sandboxes.get(principal, id) : undefined;
111
- const observes = (0, policy_1.getGrant)(config.entitlements, principal).observe;
112
- const reading = isRead(action, method);
113
- // who observes reads the sandbox of anybody; a change is for its owner, and else not found
114
- const sandbox = own ?? (known && observes && reading ? sandboxes.peek(id) : undefined);
94
+ const sandbox = runs_1.SANDBOX_ID_PATTERN.test(id) ? sandboxes.get(principal, id) : undefined;
115
95
  if (!sandbox) {
116
96
  (0, http_1.send)(res, 404, { error: 'not found' });
117
97
  return true;
118
98
  }
119
99
  if (action && action !== 'fetch' && action !== 'push') {
120
- // the owner may have lost the repository, or the sandbox's branch, since they created
121
- // it; who observes reads it all the same
122
- const refused = own && !(observes && reading)
123
- ? (0, policy_1.decideSandbox)((0, policy_1.getGrant)(config.entitlements, principal), sandbox.repo, sandbox.ref, (repo) => repos.readable(repo))
124
- : undefined;
100
+ // the caller may have lost the repository, or the sandbox's branch, since they created it
101
+ const refused = (0, policy_1.decideSandbox)((0, policy_1.getGrant)(config.entitlements, principal), sandbox.repo, sandbox.ref, (repo) => repos.readable(repo));
125
102
  if (refused) {
126
103
  log(`refuse sandbox ${action} ${id} ${who}: ${refused.error}`);
127
104
  (0, http_1.send)(res, refused.status, { error: refused.error });
@@ -156,15 +133,15 @@ async function handleSandboxes(config, sandboxes, repos, log, principal, req, re
156
133
  if ('branch' in body) {
157
134
  const pushed = await sandboxes.push(principal, id, body.branch, { ...author(principal), message: body.message }, (0, policy_1.sandboxPushBranches)(grant, sandbox.repo));
158
135
  log(`sandbox push ${id} ${who} branch=${body.branch} commit=${pushed.commit}`);
159
- (0, http_1.send)(res, 200, { branch: body.branch, commit: pushed.commit, sandbox: show(pushed) });
136
+ (0, http_1.send)(res, 200, { branch: body.branch, commit: pushed.commit, sandbox: view(sandboxes, pushed) });
160
137
  return true;
161
138
  }
162
139
  const fetched = await sandboxes.fetch(principal, id, body.ref);
163
140
  log(`sandbox fetch ${id} ${who} ref=${body.ref} commit=${fetched.commit}`);
164
- (0, http_1.send)(res, 200, show(fetched));
141
+ (0, http_1.send)(res, 200, view(sandboxes, fetched));
165
142
  }
166
143
  else if (method === 'GET') {
167
- (0, http_1.send)(res, 200, show(sandbox));
144
+ (0, http_1.send)(res, 200, view(sandboxes, sandbox));
168
145
  }
169
146
  else if (method === 'DELETE') {
170
147
  // a caller who lost the entitlement can still delete what they keep
@@ -229,39 +206,11 @@ function author(principal) {
229
206
  return { name, email: `${local}@${host}` };
230
207
  }
231
208
  exports.author = author;
232
- /**
233
- * Whether a request only reads a sandbox, which who observes may: the sandbox, its tree, a
234
- * file, a search and its changes. Edits, a write of a file, a fetch, a push and a delete
235
- * change it.
236
- */
237
- function isRead(action, method) {
238
- switch (action) {
239
- case undefined:
240
- return method === 'GET';
241
- case 'tree':
242
- case 'changes':
243
- return method === 'GET';
244
- case 'files':
245
- return method === 'GET' || method === 'HEAD';
246
- case 'search':
247
- // ripgrep's query is a body
248
- return method === 'POST';
249
- default:
250
- return false;
251
- }
252
- }
253
- // A sandbox as the caller sees it, and the run that holds it: their own without its owner,
254
- // one of somebody else (who observes) with whose it is, as a run of somebody else names it.
255
- function view(config, sandboxes, principal, sandbox) {
209
+ // What the owner sees: everything but the owner, and the run that holds it.
210
+ function view(sandboxes, sandbox) {
256
211
  const { owner, ...visible } = sandbox;
212
+ void owner;
257
213
  const run = sandboxes.holder(sandbox.id);
258
- const mine = owner.iss === principal.iss && owner.sub === principal.sub;
259
- const name = owner.name ?? (0, policy_1.subjectName)(config.entitlements, owner);
260
- return {
261
- ...visible,
262
- ...(mine ? {} : { owner: { iss: owner.iss, sub: owner.sub, ...(name ? { name } : {}) } }),
263
- busy: run !== undefined,
264
- run: run ?? null,
265
- };
214
+ return { ...visible, busy: run !== undefined, run: run ?? null };
266
215
  }
267
216
  //# sourceMappingURL=sandboxes-api.js.map
@@ -6,7 +6,6 @@ const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
7
7
  const units_1 = require("../utils/units");
8
8
  const git_checkout_1 = require("./git-checkout");
9
- const oauth_1 = require("./oauth");
10
9
  const runs_1 = require("./runs");
11
10
  const repo_1 = require("./repo");
12
11
  const sandbox_storage_1 = require("./sandbox-storage");
@@ -23,8 +22,7 @@ class SandboxError extends Error {
23
22
  exports.SandboxError = SandboxError;
24
23
  /**
25
24
  * The sandboxes of a server: who owns which, the limits, and one change at a time per
26
- * sandbox. Everything is scoped to the owner: somebody else's sandbox is "not found". Only
27
- * `all` and `peek` show the sandboxes of everybody, for who may read them (`observe`).
25
+ * sandbox. Everything is scoped to the owner: somebody else's sandbox is "not found".
28
26
  */
29
27
  class SandboxRegistry {
30
28
  constructor(options) {
@@ -113,18 +111,6 @@ class SandboxRegistry {
113
111
  const sandbox = this.sandboxes.get(id);
114
112
  return sandbox && owns(owner, sandbox) && !this.deleting.has(id) ? copy(sandbox) : undefined;
115
113
  }
116
- // The sandboxes of everybody, oldest first: what who observes sees.
117
- all() {
118
- return [...this.sandboxes.values()]
119
- .filter((sandbox) => !this.deleting.has(sandbox.id))
120
- .sort((a, b) => a.createdAt.localeCompare(b.createdAt))
121
- .map(copy);
122
- }
123
- // A sandbox of anybody, for who observes: to read, never to change.
124
- peek(id) {
125
- const sandbox = this.sandboxes.get(id);
126
- return sandbox && !this.deleting.has(id) ? copy(sandbox) : undefined;
127
- }
128
114
  holder(id) {
129
115
  return this.runs.holder(id);
130
116
  }
@@ -202,10 +188,9 @@ class SandboxRegistry {
202
188
  }
203
189
  this.creating.set(id, { owner: { iss: owner.iss, sub: owner.sub }, bytes });
204
190
  const at = this.timestamp();
205
- const name = (0, oauth_1.displayName)(owner);
206
191
  const sandbox = {
207
192
  id,
208
- owner: { iss: owner.iss, sub: owner.sub, ...(name ? { name } : {}) },
193
+ owner: { iss: owner.iss, sub: owner.sub },
209
194
  repo,
210
195
  ref,
211
196
  commit,
@@ -563,9 +548,8 @@ function owns(owner, sandbox) {
563
548
  const of = 'owner' in sandbox ? sandbox.owner : sandbox;
564
549
  return of.iss === owner.iss && of.sub === owner.sub;
565
550
  }
566
- // what the storage keeps a sandbox by: its owner's identity, not the name they had
567
551
  function keyOf(sandbox) {
568
- return { id: sandbox.id, owner: { iss: sandbox.owner.iss, sub: sandbox.owner.sub } };
552
+ return { id: sandbox.id, owner: sandbox.owner };
569
553
  }
570
554
  function copy(sandbox) {
571
555
  return {
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMaxQuotaIssues = exports.detectPlatform = exports.getSecretCatalog = exports.readServerConfig = exports.getServerAccounts = exports.getSandboxRuntimes = exports.serverConfigSchema = exports.sourceSchema = exports.entitlementSchema = exports.endpointGrantSchema = exports.endpointLevelSchema = exports.sandboxGrantSchema = exports.sandboxBranchTypeSchema = exports.buildsLevelSchema = exports.accountLevelSchema = exports.getMaxVolumeSize = exports.DEFAULT_MAX_VOLUME_SIZE = exports.DEFAULT_DENIED_EGRESS = exports.kubernetesPoolSchema = exports.accountSchema = exports.issuerSchema = exports.serverPlatformSchema = void 0;
3
+ exports.detectPlatform = exports.getSecretCatalog = exports.readServerConfig = exports.getServerAccounts = exports.getSandboxRuntimes = exports.serverConfigSchema = exports.sourceSchema = exports.entitlementSchema = exports.endpointGrantSchema = exports.endpointLevelSchema = exports.sandboxGrantSchema = exports.sandboxBranchTypeSchema = exports.buildsLevelSchema = exports.accountLevelSchema = exports.getMaxVolumeSize = exports.DEFAULT_MAX_VOLUME_SIZE = exports.DEFAULT_DENIED_EGRESS = exports.kubernetesPoolSchema = exports.accountSchema = exports.issuerSchema = exports.serverPlatformSchema = void 0;
4
4
  const run_source_envs_1 = require("../environment/run-source-envs");
5
5
  const net_1 = require("net");
6
6
  const zod_1 = require("zod");
7
7
  const yaml_1 = require("yaml");
8
8
  const log_1 = require("../log");
9
9
  const units_1 = require("../utils/units");
10
- const borrowed_quota_1 = require("./borrowed-quota");
11
10
  const version_1 = require("../version");
12
11
  const network_schema_1 = require("../schema/network-schema");
13
12
  const capabilities_schema_1 = require("../schema/capabilities-schema");
@@ -276,12 +275,8 @@ const kubernetesBackendSchema = zod_1.z
276
275
  })
277
276
  .strict())
278
277
  .default({}),
279
- // the ResourceQuota of every caller's namespace, such as `requests.cpu: '8'`: what each
280
- // caller is promised
278
+ // the ResourceQuota of every caller's namespace, such as `requests.cpu: '8'`
281
279
  quota: zod_1.z.record(zod_1.z.union([zod_1.z.string().min(1), zod_1.z.number()]).transform(String)).optional(),
282
- // how far the CPU and memory of a caller's quota rise above `quota` while the nodes of the
283
- // pools have room no other caller is promised (see BorrowedQuotas); never when left out
284
- maxQuota: zod_1.z.record(zod_1.z.union([zod_1.z.string().min(1), zod_1.z.number()]).transform(String)).optional(),
285
280
  // what a container without `resources` requests (a LimitRange), so it is
286
281
  // admitted under a quota that limits compute
287
282
  defaultResources: zod_1.z
@@ -859,13 +854,6 @@ exports.serverConfigSchema = zod_1.z
859
854
  }
860
855
  }
861
856
  }
862
- for (const issue of getMaxQuotaIssues(backend.quota, backend.maxQuota)) {
863
- ctx.addIssue({
864
- code: zod_1.z.ZodIssueCode.custom,
865
- path: ['backend', 'maxQuota', ...issue.path],
866
- message: issue.message,
867
- });
868
- }
869
857
  if (backend.maxVolumeSize && (0, units_1.parseSize)(backend.volumeSize) > (0, units_1.parseSize)(backend.maxVolumeSize)) {
870
858
  ctx.addIssue({
871
859
  code: zod_1.z.ZodIssueCode.custom,
@@ -1083,49 +1071,4 @@ function detectPlatform() {
1083
1071
  return { os, arch };
1084
1072
  }
1085
1073
  exports.detectPlatform = detectPlatform;
1086
- // What is wrong with `backend.maxQuota`: a key a caller may borrow (CPU and memory, see
1087
- // BORROWED_RESOURCES) that `quota` has too, no less than there, and a limit only with the
1088
- // requests of its resource, which say how much room the caller takes of the nodes.
1089
- function getMaxQuotaIssues(quota, maxQuota) {
1090
- if (!maxQuota) {
1091
- return [];
1092
- }
1093
- if (!quota) {
1094
- return [{ path: [], message: 'a caller borrows above backend.quota, which is not set' }];
1095
- }
1096
- const issues = [];
1097
- for (const [key, value] of Object.entries(maxQuota)) {
1098
- const resource = (0, borrowed_quota_1.getBorrowedResource)(key);
1099
- if (!resource) {
1100
- issues.push({
1101
- path: [key],
1102
- message: `${key} can't be borrowed, only ${Object.values(borrowed_quota_1.BORROWED_RESOURCES)
1103
- .flatMap((keys) => [...keys.requests, ...keys.limits])
1104
- .join(', ')}`,
1105
- });
1106
- continue;
1107
- }
1108
- if (quota[key] === undefined) {
1109
- issues.push({ path: [key], message: `${key} is not in backend.quota, the share it rises from` });
1110
- continue;
1111
- }
1112
- const max = (0, units_1.parseQuantity)(value);
1113
- const share = (0, units_1.parseQuantity)(quota[key]);
1114
- if (max === undefined) {
1115
- issues.push({ path: [key], message: `expected a quantity such as 8, 500m or 16Gi` });
1116
- }
1117
- else if (share !== undefined && max < share) {
1118
- issues.push({ path: [key], message: `${value} is less than ${quota[key]} of backend.quota` });
1119
- }
1120
- const requests = borrowed_quota_1.BORROWED_RESOURCES[resource].requests;
1121
- if (!requests.includes(key) && !requests.some((other) => maxQuota[other] !== undefined)) {
1122
- issues.push({
1123
- path: [key],
1124
- message: `${key} rises with the requests of ${resource}, add ${requests[0]} to backend.maxQuota`,
1125
- });
1126
- }
1127
- }
1128
- return issues;
1129
- }
1130
- exports.getMaxQuotaIssues = getMaxQuotaIssues;
1131
1074
  //# sourceMappingURL=server-config.js.map
@@ -328,7 +328,13 @@ exports.refuseWake = refuseWake;
328
328
  function runsTheSame(run, next) {
329
329
  const sorted = (values) => JSON.stringify([...values].sort());
330
330
  const options = (value) => JSON.stringify(value ?? {}, Object.keys(value ?? {}).sort());
331
- const endpoints = (spec) => JSON.stringify(spec.endpoints.map((endpoint) => [endpoint.service, endpoint.port, endpoint.host]));
331
+ // the public paths are part of an endpoint: a run that opens other paths is not the same run
332
+ const endpoints = (spec) => JSON.stringify(spec.endpoints.map((endpoint) => [
333
+ endpoint.service,
334
+ endpoint.port,
335
+ endpoint.host,
336
+ sorted(endpoint.publicPaths ?? []),
337
+ ]));
332
338
  return (!!run.up &&
333
339
  run.source.type === 'ref' &&
334
340
  run.source.repo === next.source.repo &&
@@ -513,6 +519,16 @@ async function startRun(config, registry, definitions, sources, sandboxes, plann
513
519
  return;
514
520
  }
515
521
  }
522
+ // a service run is named after its branch unless it says, and its endpoints after that
523
+ const serviceName = request.services.length > 0
524
+ ? request.name ??
525
+ (0, service_runs_1.getServiceRunName)(request.source.type === 'ref' ? request.source.ref : sandbox?.ref)
526
+ : '';
527
+ const misnamed = (0, service_runs_1.refusePublicPaths)(request, serviceName);
528
+ if (misnamed) {
529
+ (0, http_2.send)(res, 400, { error: misnamed });
530
+ return;
531
+ }
516
532
  // the accounts of a run are read from the files it is pinned to, with the engine
517
533
  const bundle = version.plan ? await definitions.files(version) : undefined;
518
534
  if (!version.plan || !bundle) {
@@ -537,7 +553,8 @@ async function startRun(config, registry, definitions, sources, sandboxes, plann
537
553
  return;
538
554
  }
539
555
  const refused = (0, run_plan_1.refuseArguments)(request, planned.plan, sandbox ? sandboxes.policy : planning.policy) ??
540
- (0, service_runs_1.refuseEndpoints)(request, planned.plan, config.runs.secretNetwork === 'open');
556
+ (0, service_runs_1.refuseEndpoints)(request, planned.plan, config.runs.secretNetwork === 'open') ??
557
+ (0, service_runs_1.refusePublicSecrets)(request, planned.plan);
541
558
  if (refused) {
542
559
  log(`refuse run iss=${principal.iss} sub=${principal.sub}: ${refused}`);
543
560
  (0, http_2.send)(res, 400, { error: refused });
@@ -614,18 +631,13 @@ async function startRun(config, registry, definitions, sources, sandboxes, plann
614
631
  }
615
632
  planned = pinned;
616
633
  }
617
- // a service run is named after its branch unless it says, and its endpoints after that
618
- const serviceName = request.services.length > 0
619
- ? request.name ??
620
- (0, service_runs_1.getServiceRunName)(request.source.type === 'ref' ? request.source.ref : sandbox?.ref)
621
- : '';
622
634
  const up = request.services.length > 0
623
635
  ? {
624
636
  services: request.services,
625
637
  ttl,
626
638
  ...(sleepTtl ? { sleepTtl } : {}),
627
639
  name: serviceName,
628
- endpoints: (0, service_runs_1.toRunEndpoints)(request.endpoints, (0, service_runs_1.getEndpointHosts)(serviceName, principal, request.endpoints), endpointUrl),
640
+ endpoints: (0, service_runs_1.toRunEndpoints)(request.endpoints, (0, service_runs_1.getEndpointHosts)(serviceName, principal, request.endpoints), endpointUrl, request.publicPaths),
629
641
  }
630
642
  : undefined;
631
643
  // a run that may sleep keeps what its owner is entitled by, for the check of a wake