hammerkit 2.1.0-next.9 → 2.1.1

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 +53 -12
  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
@@ -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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mayPublishEndpoints = exports.mayOpenEndpoints = exports.getRunRepo = exports.toRunEndpoints = exports.refuseEndpoints = exports.getEndpointHosts = exports.getServiceRunName = void 0;
3
+ exports.mayPublishEndpoints = exports.mayOpenEndpoints = exports.getRunRepo = exports.toRunEndpoints = exports.refusePublicPaths = exports.refusePublicSecrets = exports.refuseEndpoints = exports.getEndpointHosts = exports.getServiceRunName = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  const plan_1 = require("./plan");
6
6
  const policy_1 = require("./policy");
@@ -73,6 +73,28 @@ function refuseEndpoints(request, plan, secretNetworkOpen) {
73
73
  return null;
74
74
  }
75
75
  exports.refuseEndpoints = refuseEndpoints;
76
+ /**
77
+ * Why the public paths of a run can not be served, or null. A public path is open without a
78
+ * sign-in, so a service with one may not read a secret or a credential, directly or through
79
+ * what it is made from or needs, whatever `runs.secretNetwork` says: the way out refuseEndpoints
80
+ * allows for a signed-in page does not hold for a path anybody may request.
81
+ */
82
+ function refusePublicSecrets(request, plan) {
83
+ for (const { service } of request.publicPaths) {
84
+ for (const { name, path } of reachedFrom(service, plan)) {
85
+ const reads = (0, plan_1.getCredentialReads)(plan[name]);
86
+ if (reads.length === 0) {
87
+ continue;
88
+ }
89
+ // the way from the service to what reads it: `web needs api, which needs vault`
90
+ const way = path.map((step, index) => `${index === 0 ? '' : ', which '}${step.relation} ${step.name}`).join('');
91
+ const from = path.length === 0 ? `${service} reads` : `${service} ${way}, which reads`;
92
+ return `${from} ${reads.join(', ')}: it can not have public paths on this server, a path open without a sign-in could show it`;
93
+ }
94
+ }
95
+ return null;
96
+ }
97
+ exports.refusePublicSecrets = refusePublicSecrets;
76
98
  function reachedFrom(service, plan) {
77
99
  if (!plan[service]) {
78
100
  return [];
@@ -96,13 +118,24 @@ function reachedFrom(service, plan) {
96
118
  }
97
119
  return reached;
98
120
  }
99
- function toRunEndpoints(endpoints, hosts, url) {
100
- return endpoints.map((endpoint, index) => ({
101
- service: endpoint.service,
102
- port: endpoint.port,
103
- host: hosts[index],
104
- url: url(hosts[index]),
105
- }));
121
+ // The public paths of a run must name the run they start: a run that gets another name than the
122
+ // one the paths were written for would publish them at endpoints the operator did not mean.
123
+ function refusePublicPaths(request, name) {
124
+ const other = request.publicPaths.find((entry) => entry.run !== name);
125
+ return other ? `the public paths name the run ${other.run}, but this run is ${name}` : null;
126
+ }
127
+ exports.refusePublicPaths = refusePublicPaths;
128
+ function toRunEndpoints(endpoints, hosts, url, publicPaths = []) {
129
+ return endpoints.map((endpoint, index) => {
130
+ const paths = publicPaths.find((entry) => entry.service === endpoint.service && entry.port === endpoint.port);
131
+ return {
132
+ service: endpoint.service,
133
+ port: endpoint.port,
134
+ host: hosts[index],
135
+ url: url(hosts[index]),
136
+ ...(paths ? { publicPaths: paths.paths } : {}),
137
+ };
138
+ });
106
139
  }
107
140
  exports.toRunEndpoints = toRunEndpoints;
108
141
  // The repository of a run's source, which the endpoints grants are written for.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hammerkit",
3
3
  "description": "Containerized build tool with incremental caching that runs the same build file locally, in Docker and on Kubernetes.",
4
- "version": "2.1.0-next.9",
4
+ "version": "2.1.1",
5
5
  "keywords": [
6
6
  "build",
7
7
  "build-tool",