hammerkit 1.27.0-next.9 → 2.0.0-next.10

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 (141) hide show
  1. package/build.schema.json +176 -6
  2. package/dist/cache/backends/local-cache-backend.js +6 -0
  3. package/dist/cache/backends/registry/registry-client.js +1 -0
  4. package/dist/cache/cache-sync.js +1 -1
  5. package/dist/cache/explain.js +23 -4
  6. package/dist/cli.js +2 -0
  7. package/dist/dashboard/assets/graph-canvas-DLioOiRN.css +1 -0
  8. package/dist/dashboard/assets/graph-canvas-HmkW_-XJ.js +8 -0
  9. package/dist/dashboard/assets/index-gIBDC_m8.css +2 -0
  10. package/dist/dashboard/assets/index-vE22S5E_.js +17 -0
  11. package/dist/dashboard/index.html +15 -0
  12. package/dist/dashboard/logo.png +0 -0
  13. package/dist/docker/item-network.js +13 -5
  14. package/dist/executer/archive-task-entry.js +4 -2
  15. package/dist/executer/deadline.js +17 -3
  16. package/dist/executer/deferred-restore.js +36 -0
  17. package/dist/executer/docker-service.js +30 -8
  18. package/dist/executer/docker-task.js +24 -1
  19. package/dist/executer/execute-work-service.js +2 -0
  20. package/dist/executer/execute-work-task.js +14 -5
  21. package/dist/executer/execution-steps.js +25 -4
  22. package/dist/executer/local-task.js +3 -0
  23. package/dist/executer/reset-work-tree.js +4 -0
  24. package/dist/executer/scheduler/enqueue-next.js +63 -7
  25. package/dist/executer/scheduler/state-key.js +89 -15
  26. package/dist/executer/watch-loop.js +22 -6
  27. package/dist/file/get-file-context.js +5 -1
  28. package/dist/harness/connect.js +20 -6
  29. package/dist/harness/mcp-command.js +22 -6
  30. package/dist/harness/mcp.js +63 -114
  31. package/dist/harness/opencode.js +158 -50
  32. package/dist/harness/pi.js +29 -0
  33. package/dist/harness/sandbox-client.js +194 -23
  34. package/dist/harness/service-tools.js +141 -0
  35. package/dist/harness/task-tools.js +221 -0
  36. package/dist/kubernetes/apply.js +49 -1
  37. package/dist/kubernetes/await-running-state.js +241 -18
  38. package/dist/kubernetes/claim-layout.js +10 -1
  39. package/dist/kubernetes/cluster-state.js +245 -0
  40. package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +142 -9
  41. package/dist/kubernetes/ensure-kubernetes-service-exists.js +2 -0
  42. package/dist/kubernetes/ensure-persistent-data.js +305 -12
  43. package/dist/kubernetes/follow-pod-logs.js +281 -0
  44. package/dist/kubernetes/job-placement.js +36 -12
  45. package/dist/kubernetes/kept-claims.js +16 -1
  46. package/dist/kubernetes/kubernetes-instance.js +1 -0
  47. package/dist/kubernetes/network-policy.js +6 -5
  48. package/dist/kubernetes/quota-wait.js +97 -0
  49. package/dist/kubernetes/remove-stale-items.js +46 -0
  50. package/dist/kubernetes/restore-kubernetes-data.js +35 -8
  51. package/dist/kubernetes/sandbox-runner.js +628 -0
  52. package/dist/kubernetes/service-rollouts.js +74 -0
  53. package/dist/kubernetes/store-kubernetes-data.js +18 -4
  54. package/dist/kubernetes/volumes.js +124 -12
  55. package/dist/main.js +2 -0
  56. package/dist/optimizer/calculate-checksum.js +49 -5
  57. package/dist/optimizer/check-key.js +94 -0
  58. package/dist/optimizer/check-keys.js +66 -0
  59. package/dist/optimizer/get-work-cache-stats.js +53 -27
  60. package/dist/optimizer/work-task-cache-description.js +49 -1
  61. package/dist/parser/read-build-file.js +8 -3
  62. package/dist/planner/service-definition.js +9 -4
  63. package/dist/planner/utils/append-work-dependencies.js +5 -3
  64. package/dist/planner/utils/append-work-service.js +18 -1
  65. package/dist/planner/utils/append-work-task.js +13 -3
  66. package/dist/planner/utils/get-work-runtime.js +6 -1
  67. package/dist/planner/utils/normalize-path.js +19 -1
  68. package/dist/planner/utils/parse-work-mount.js +7 -1
  69. package/dist/planner/utils/parse-work-port.js +4 -1
  70. package/dist/planner/utils/template-value.js +20 -4
  71. package/dist/planner/validate.js +22 -0
  72. package/dist/planner/work-item-executions.js +27 -0
  73. package/dist/planner/work-network.js +3 -1
  74. package/dist/planner/work-runtime-aggregate.js +32 -0
  75. package/dist/planner/work-runtime-kubernetes.js +204 -53
  76. package/dist/planner/work-task.js +6 -1
  77. package/dist/program.js +27 -9
  78. package/dist/remote/device-login.js +7 -2
  79. package/dist/remote/host-config.js +69 -3
  80. package/dist/remote/remote-commands.js +33 -7
  81. package/dist/remote/remote-status.js +112 -0
  82. package/dist/remote/remote-work-commands.js +571 -45
  83. package/dist/remote/server-client.js +15 -2
  84. package/dist/remote/token-source.js +64 -26
  85. package/dist/run-program.js +9 -0
  86. package/dist/schema/build-file-base-task-schema.js +3 -3
  87. package/dist/schema/build-file-container-service-schema.js +10 -0
  88. package/dist/schema/build-file-container-task-schema.js +16 -1
  89. package/dist/schema/build-file-include-schema.js +18 -4
  90. package/dist/schema/build-file-kubernetes-service-schema.js +2 -0
  91. package/dist/schema/build-file-task-schema.js +5 -1
  92. package/dist/schema/capabilities-schema.js +56 -0
  93. package/dist/schema/reference-parser.js +119 -11
  94. package/dist/schema/removed-properties.js +20 -0
  95. package/dist/schema/schema-parser.js +140 -43
  96. package/dist/schema/work-scope-parser.js +33 -10
  97. package/dist/secrets/command-secret-provider.js +3 -1
  98. package/dist/secrets/github-app-token-command.js +3 -1
  99. package/dist/secrets/secret-catalog.js +43 -19
  100. package/dist/server/accounts-api.js +4 -1
  101. package/dist/server/approvals-api.js +1 -1
  102. package/dist/server/capacity-format.js +36 -0
  103. package/dist/server/capacity.js +330 -0
  104. package/dist/server/checks-api.js +83 -0
  105. package/dist/server/checks.js +116 -0
  106. package/dist/server/dashboard.js +214 -0
  107. package/dist/server/definitions-api.js +66 -3
  108. package/dist/server/endpoints.js +803 -0
  109. package/dist/server/executor.js +216 -30
  110. package/dist/server/kubernetes-backend.js +415 -48
  111. package/dist/server/kubernetes-sandbox-storage.js +60 -6
  112. package/dist/server/oauth.js +16 -1
  113. package/dist/server/overview.js +340 -0
  114. package/dist/server/plan.js +186 -124
  115. package/dist/server/policy.js +42 -4
  116. package/dist/server/proposals-api.js +17 -8
  117. package/dist/server/repo-access.js +5 -0
  118. package/dist/server/run-logs.js +4 -0
  119. package/dist/server/run-plan.js +38 -4
  120. package/dist/server/run-request.js +58 -3
  121. package/dist/server/run-worker.js +307 -17
  122. package/dist/server/runs.js +1036 -42
  123. package/dist/server/sandbox-files.js +107 -16
  124. package/dist/server/sandbox-patch.js +43 -17
  125. package/dist/server/sandbox-pod.js +28 -0
  126. package/dist/server/sandbox-storage.js +23 -0
  127. package/dist/server/sandboxes.js +65 -23
  128. package/dist/server/server-config.js +250 -11
  129. package/dist/server/server.js +465 -33
  130. package/dist/server/service-runs.js +89 -0
  131. package/dist/server/sources.js +68 -11
  132. package/dist/server/timings.js +152 -0
  133. package/dist/server/wait-reason.js +21 -0
  134. package/dist/utils/buffer-context.js +30 -20
  135. package/dist/utils/limit.js +30 -0
  136. package/dist/utils/read-lines.js +65 -0
  137. package/dist/utils/tar.js +28 -1
  138. package/dist/utils/terminal-prompt.js +53 -0
  139. package/dist/utils/units.js +36 -1
  140. package/dist/utils/web-links.js +34 -0
  141. package/package.json +8 -2
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectPlatform = exports.getSecretCatalog = exports.readServerConfig = exports.getSourceAccounts = exports.getSandboxRuntimes = exports.serverConfigSchema = exports.sourceSchema = exports.entitlementSchema = 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 net_1 = require("net");
5
5
  const zod_1 = require("zod");
6
6
  const yaml_1 = require("yaml");
@@ -8,6 +8,7 @@ const log_1 = require("../log");
8
8
  const units_1 = require("../utils/units");
9
9
  const version_1 = require("../version");
10
10
  const network_schema_1 = require("../schema/network-schema");
11
+ const capabilities_schema_1 = require("../schema/capabilities-schema");
11
12
  const build_file_secret_provider_schema_1 = require("../schema/build-file-secret-provider-schema");
12
13
  const repo_1 = require("./repo");
13
14
  const work_network_1 = require("../planner/work-network");
@@ -44,7 +45,10 @@ exports.issuerSchema = zod_1.z
44
45
  scope: zod_1.z.string().min(1).default('openid'),
45
46
  })
46
47
  .strict();
47
- const subjectSchema = zod_1.z.object({ iss: zod_1.z.string().min(1), sub: zod_1.z.string().min(1) }).strict();
48
+ // `name`: how pages name a subject whose tokens name nobody, such as a service account's
49
+ const subjectSchema = zod_1.z
50
+ .object({ iss: zod_1.z.string().min(1), sub: zod_1.z.string().min(1), name: zod_1.z.string().trim().min(1).max(100).optional() })
51
+ .strict();
48
52
  const groupSchema = zod_1.z.object({ iss: zod_1.z.string().min(1), name: zod_1.z.string().min(1) }).strict();
49
53
  const claimsSchema = zod_1.z.object({ iss: zod_1.z.string().min(1), match: zod_1.z.record(zod_1.z.string()) }).strict();
50
54
  // Who: the person or client (`subject`), everyone in a group of an issuer
@@ -117,12 +121,24 @@ exports.accountSchema = zod_1.z
117
121
  });
118
122
  }
119
123
  });
124
+ // The capabilities (`capAdd`) a task of a run may add, and the sandboxed runtime its
125
+ // container then runs in, so they hold in the sandbox's own kernel and never in the host's
126
+ const capabilitiesAllowSchema = zod_1.z
127
+ .array(zod_1.z.enum(capabilities_schema_1.LINUX_CAPABILITIES))
128
+ .min(1)
129
+ .refine((names) => new Set(names).size === names.length, 'a capability is listed twice');
120
130
  // The tasks of runs execute on this machine, with its docker daemon and local tools.
121
131
  const hostBackendSchema = zod_1.z
122
132
  .object({
123
133
  type: zod_1.z.literal('host'),
124
134
  // what this machine offers; detected when left out
125
135
  platform: exports.serverPlatformSchema.optional(),
136
+ // `runtime` is a runtime of the docker daemon (`runtimes` in its daemon.json), such as
137
+ // runsc of gVisor
138
+ capabilities: zod_1.z
139
+ .object({ allow: capabilitiesAllowSchema, runtime: zod_1.z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]*$/) })
140
+ .strict()
141
+ .optional(),
126
142
  })
127
143
  .strict();
128
144
  const tolerationSchema = zod_1.z
@@ -188,8 +204,12 @@ const kubernetesSandboxesSchema = zod_1.z
188
204
  // when left out. With a class of their own, a ResourceQuota on that class in each
189
205
  // caller's namespace holds `sandboxes.limits`.
190
206
  storageClass: zod_1.z.string().min(1).optional(),
191
- // how long the pod of a sandbox's files stays after the last request
207
+ // how long the pod of a sandbox's files stays after the last request; the runner of the
208
+ // sandbox goes with it
192
209
  idle: duration.default('1m'),
210
+ // exec the commands of a task shaped like a shell (it mounts the sandbox only, has no
211
+ // needs, outputs or secrets) into one pod per sandbox, in place of a Job each
212
+ runner: zod_1.z.boolean().default(true),
193
213
  // of the pod of a sandbox's files, which runs git and ripgrep over all of them
194
214
  resources: zod_1.z
195
215
  .object({ requests: quantitiesSchema.optional(), limits: quantitiesSchema.optional() })
@@ -278,6 +298,9 @@ const kubernetesBackendSchema = zod_1.z
278
298
  // build file's environment does: hammerkit can't tell from the API, and without it a
279
299
  // task with a limited network fails rather than runs open
280
300
  networkPolicy: zod_1.z.literal('enforced').optional(),
301
+ // `runtimeClass` is a RuntimeClass of a sandbox, such as gvisor; the pods of tasks that
302
+ // add capabilities run in it
303
+ capabilities: zod_1.z.object({ allow: capabilitiesAllowSchema, runtimeClass: kubernetesNameSchema }).strict().optional(),
281
304
  })
282
305
  .strict();
283
306
  // the most a task's claim may request on a server whose operator states no maxVolumeSize
@@ -323,6 +346,11 @@ exports.sandboxGrantSchema = zod_1.z
323
346
  .refine((branches) => Object.keys(branches).length > 0, 'name the branches a sandbox may start from'),
324
347
  })
325
348
  .strict();
349
+ // `open`: open the endpoints of the service runs of a repository, whoever started them, and
350
+ // extend those runs; `publish`: also name endpoints in one's own service runs.
351
+ exports.endpointLevelSchema = zod_1.z.enum(['open', 'publish']);
352
+ // One repository (`host/path` pattern) whose endpoints an entitlement opens or publishes.
353
+ exports.endpointGrantSchema = zod_1.z.object({ repo: repoPatternSchema, level: exports.endpointLevelSchema }).strict();
326
354
  exports.entitlementSchema = zod_1.z
327
355
  .object({
328
356
  ...whoShape,
@@ -332,19 +360,38 @@ exports.entitlementSchema = zod_1.z
332
360
  // the repositories (`host/path` patterns) the caller may run from a git ref
333
361
  repos: zod_1.z.array(repoPatternSchema).default([]),
334
362
  builds: exports.buildsLevelSchema.optional(),
363
+ // `read`: may look up which tasks runs passed for files of the `repos` (remote verify),
364
+ // and nothing more; a builds level includes it
365
+ checks: zod_1.z.literal('read').optional(),
335
366
  // the repositories the caller may keep sandboxes of, checkouts on the server that runs
336
367
  // work on: a list of its own, the `repos` above are for runs from a ref
337
368
  sandboxes: zod_1.z.array(exports.sandboxGrantSchema).optional(),
369
+ // the repositories whose service runs' endpoints the caller may open, or publish
370
+ endpoints: zod_1.z.array(exports.endpointGrantSchema).optional(),
371
+ // sees every run of the server in full, who started it, its tasks and its log, in
372
+ // `remote status`, `remote runs --all` and the dashboard: for operators, it stops,
373
+ // extends and approves nothing
374
+ observe: zod_1.z.literal(true).optional(),
338
375
  })
339
376
  .strict()
340
377
  .superRefine((entitlement, ctx) => {
341
378
  checkWho(entitlement, ctx);
342
379
  if (Object.keys(entitlement.accounts).length === 0 &&
343
380
  entitlement.builds === undefined &&
344
- !entitlement.sandboxes?.length) {
381
+ entitlement.checks === undefined &&
382
+ !entitlement.sandboxes?.length &&
383
+ !entitlement.endpoints?.length &&
384
+ !entitlement.observe) {
345
385
  ctx.addIssue({
346
386
  code: zod_1.z.ZodIssueCode.custom,
347
- message: 'name accounts to use or request, a builds level or sandboxes',
387
+ message: 'name accounts to use or request, a builds level, checks, sandboxes, endpoints or observe',
388
+ });
389
+ }
390
+ if (entitlement.checks && entitlement.repos.length === 0) {
391
+ ctx.addIssue({
392
+ code: zod_1.z.ZodIssueCode.custom,
393
+ path: ['repos'],
394
+ message: 'checks are read for repositories: name them in repos',
348
395
  });
349
396
  }
350
397
  });
@@ -429,6 +476,10 @@ exports.serverConfigSchema = zod_1.z
429
476
  maxConcurrent: zod_1.z.number().int().min(1).default(4),
430
477
  // finished runs that are kept for their state and logs
431
478
  keep: zod_1.z.number().int().min(1).default(200),
479
+ // who sees the runs of others: `everyone` with an entitlement sees who runs what,
480
+ // where it stands and how long it took, never its arguments, error or log;
481
+ // `involved` only sees the runs they decide about or may open the endpoints of
482
+ activity: zod_1.z.enum(['everyone', 'involved']).default('everyone'),
432
483
  // what one caller (issuer and subject) may have at a time, so a single
433
484
  // caller can not take the whole machine; over it a request gets 429
434
485
  limits: zod_1.z
@@ -472,6 +523,40 @@ exports.serverConfigSchema = zod_1.z
472
523
  // which tasks take arguments: `any` but those that say `args: false`, or
473
524
  // `declared`, only those that say `args: true`
474
525
  args: zod_1.z.enum(['any', 'declared']).default('any'),
526
+ // runs of services (`services` in a run), kept up until their ttl ends
527
+ up: zod_1.z
528
+ .object({
529
+ // how long the services stay once ready, when the run names no ttl; then they are removed
530
+ ttl: duration.default('8h'),
531
+ // how long the services stay up without a request to an endpoint before they sleep,
532
+ // when the run names none: the next request wakes them. Unset, they never sleep.
533
+ sleepTtl: duration.optional(),
534
+ // the furthest a run, or an extend, sets the end from now
535
+ maxTtl: duration.default('72h'),
536
+ limits: zod_1.z
537
+ .object({
538
+ // service runs one caller has starting or up at a time; one more is 429
539
+ up: zod_1.z.number().int().min(1).default(3),
540
+ // service runs one caller has asleep, which take no place of `up`; a new run
541
+ // when there are this many is 429
542
+ asleep: zod_1.z.number().int().min(1).default(10),
543
+ })
544
+ .strict()
545
+ .default({}),
546
+ // service runs starting or up on the whole server; one more is 503
547
+ total: zod_1.z.number().int().min(1).default(20),
548
+ // on a Kubernetes backend, the ResourceQuota of the namespace of each service
549
+ // run; backend.quota when left out
550
+ quota: zod_1.z.record(zod_1.z.union([zod_1.z.string().min(1), zod_1.z.number()]).transform(String)).optional(),
551
+ // the volumes of a run's services stay while it sleeps, and are mounted again when
552
+ // it wakes; they go when the run ends. false for a server short on disk: a woken
553
+ // run starts from nothing.
554
+ keepVolumes: zod_1.z.boolean().default(true),
555
+ })
556
+ .strict()
557
+ .default({}),
558
+ // how long a passed check stays for `remote verify` to find (see checks.ts)
559
+ checksKeep: duration.default('30d'),
475
560
  })
476
561
  .strict()
477
562
  .default({}),
@@ -496,6 +581,9 @@ exports.serverConfigSchema = zod_1.z
496
581
  .object({ allow: zod_1.z.array(zod_1.z.string().regex(/^[A-Za-z_][A-Za-z0-9_()]*$/)).default([]) })
497
582
  .strict()
498
583
  .default({}),
584
+ // the capabilities of `backend.capabilities.allow` a task of a run on a sandbox may
585
+ // add: none by default, a sandbox holds code nobody reviewed
586
+ capabilities: zod_1.z.array(zod_1.z.enum(capabilities_schema_1.LINUX_CAPABILITIES)).default([]),
499
587
  // what one caller may keep; a sandbox over it can't be created
500
588
  limits: zod_1.z
501
589
  .object({
@@ -509,6 +597,59 @@ exports.serverConfigSchema = zod_1.z
509
597
  })
510
598
  .strict()
511
599
  .default({}),
600
+ // ports of service runs published at hosts of their own below `domain`, behind the
601
+ // server's sign-in. Absent, a run naming endpoints is refused.
602
+ endpoints: zod_1.z
603
+ .object({
604
+ // `run.example.com`: an endpoint is https://<label>.run.example.com, all of them
605
+ // pointing at this server with one wildcard DNS record
606
+ domain: zod_1.z
607
+ .string()
608
+ .regex(/^(?=.{1,200}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/, 'expected a domain name in lower case, such as run.example.com'),
609
+ // a wildcard certificate for *.<domain>, served for the hosts of endpoints; left out
610
+ // behind a TLS proxy, which holds it
611
+ tls: zod_1.z
612
+ .object({ cert: zod_1.z.string().min(1), key: zod_1.z.string().min(1) })
613
+ .strict()
614
+ .optional(),
615
+ // how a person signs in with a browser: the authorization code flow of an issuer of
616
+ // `issuers`, with a client of its own; without it only tokens open endpoints
617
+ login: zod_1.z
618
+ .object({
619
+ issuer: zod_1.z.string().min(1),
620
+ clientId: zod_1.z.string().min(1),
621
+ // for providers whose web clients need one (Google): read as an account no
622
+ // entitlement may name, as the secret of a source is
623
+ clientSecret: zod_1.z
624
+ .object({
625
+ from: zod_1.z.string().regex(/^[A-Za-z][A-Za-z0-9_-]*:.+$/, 'expected provider:reference'),
626
+ account: accountNameSchema,
627
+ })
628
+ .strict()
629
+ .optional(),
630
+ scope: zod_1.z.string().min(1).default('openid'),
631
+ })
632
+ .strict()
633
+ .optional(),
634
+ // how long a sign-in at one endpoint lasts, at most until its run ends: the groups and
635
+ // claims of the sign-in hold that long, a change at the issuer counts at the next one
636
+ session: duration.default('1h'),
637
+ // the host of the dashboard below the domain, `hammerkit.<domain>`, signed in at like an
638
+ // endpoint (it needs `login`); false for none
639
+ dashboard: zod_1.z
640
+ .union([
641
+ zod_1.z.literal(false),
642
+ zod_1.z
643
+ .string()
644
+ .regex(/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/, 'expected a host label, such as hammerkit')
645
+ .refine((label) => label !== 'login', 'login is the host of the sign-in')
646
+ // the hosts of endpoints end in -<port>-<12 hex>
647
+ .refine((label) => !/-\d+-[0-9a-f]{12}$/.test(label), 'that is how the hosts of endpoints are named'),
648
+ ])
649
+ .default('hammerkit'),
650
+ })
651
+ .strict()
652
+ .optional(),
512
653
  backend: zod_1.z.discriminatedUnion('type', [hostBackendSchema, kubernetesBackendSchema]).default({ type: 'host' }),
513
654
  })
514
655
  .strict()
@@ -576,7 +717,7 @@ exports.serverConfigSchema = zod_1.z
576
717
  });
577
718
  }
578
719
  });
579
- const readers = getSourceAccounts(config);
720
+ const readers = getServerAccounts(config);
580
721
  config.entitlements.forEach((entitlement, index) => {
581
722
  for (const account of Object.keys(entitlement.accounts)) {
582
723
  if (readers.includes(account)) {
@@ -588,6 +729,16 @@ exports.serverConfigSchema = zod_1.z
588
729
  }
589
730
  }
590
731
  });
732
+ const allowed = config.backend.capabilities?.allow ?? [];
733
+ config.sandboxes.capabilities.forEach((capability, index) => {
734
+ if (!allowed.includes(capability)) {
735
+ ctx.addIssue({
736
+ code: zod_1.z.ZodIssueCode.custom,
737
+ path: ['sandboxes', 'capabilities', index],
738
+ message: `the capability ${capability} is not in backend.capabilities.allow, no run may add it`,
739
+ });
740
+ }
741
+ });
591
742
  const sandboxNetwork = (0, work_network_1.parseWorkNetwork)(config.sandboxes.network);
592
743
  const runsNetwork = (0, work_network_1.parseWorkNetwork)(config.runs.network);
593
744
  if ((0, work_network_1.exceedsNetwork)(sandboxNetwork, runsNetwork)) {
@@ -659,7 +810,7 @@ exports.serverConfigSchema = zod_1.z
659
810
  });
660
811
  // the secrets of tasks are read in their Job, with the image of the provider; the
661
812
  // ones of the sources are read by the server, which checks the code out itself
662
- const readers = getSourceAccounts(config);
813
+ const readers = getServerAccounts(config);
663
814
  for (const [name, account] of Object.entries(config.accounts)) {
664
815
  if (readers.includes(name)) {
665
816
  continue;
@@ -745,6 +896,87 @@ exports.serverConfigSchema = zod_1.z
745
896
  message: 'the network of a local task can not be limited, allow only the docker runtime with runs.network',
746
897
  });
747
898
  }
899
+ if ((0, units_1.parseDuration)(config.runs.up.ttl) > (0, units_1.parseDuration)(config.runs.up.maxTtl)) {
900
+ ctx.addIssue({
901
+ code: zod_1.z.ZodIssueCode.custom,
902
+ path: ['runs', 'up', 'ttl'],
903
+ message: `a ttl of ${config.runs.up.ttl} is more than maxTtl of ${config.runs.up.maxTtl}`,
904
+ });
905
+ }
906
+ const endpoints = config.endpoints;
907
+ if (endpoints) {
908
+ if (endpoints.tls && config.behindTlsProxy) {
909
+ ctx.addIssue({
910
+ code: zod_1.z.ZodIssueCode.custom,
911
+ path: ['endpoints', 'tls'],
912
+ message: 'behind a TLS proxy the proxy holds the certificate of the endpoints, leave out endpoints.tls',
913
+ });
914
+ }
915
+ if (endpoints.tls && !config.tls) {
916
+ ctx.addIssue({
917
+ code: zod_1.z.ZodIssueCode.custom,
918
+ path: ['endpoints', 'tls'],
919
+ message: 'the certificate of the endpoints is served next to the one of the server, set tls as well',
920
+ });
921
+ }
922
+ if (!endpoints.tls && !config.behindTlsProxy && (config.tls || !LOOPBACK_HOSTS.includes(config.listen.host))) {
923
+ ctx.addIssue({
924
+ code: zod_1.z.ZodIssueCode.custom,
925
+ path: ['endpoints', 'tls'],
926
+ message: `name the certificate of *.${endpoints.domain} in endpoints.tls, or set behindTlsProxy: true when a proxy in front holds it`,
927
+ });
928
+ }
929
+ const login = endpoints.login;
930
+ if (login && !config.issuers.some((issuer) => issuer.issuer === login.issuer)) {
931
+ ctx.addIssue({
932
+ code: zod_1.z.ZodIssueCode.custom,
933
+ path: ['endpoints', 'login', 'issuer'],
934
+ message: `issuer ${login.issuer} is not one of the accepted issuers`,
935
+ });
936
+ }
937
+ if (login?.clientSecret) {
938
+ const { from, account } = login.clientSecret;
939
+ const kind = from.substring(0, from.indexOf(':'));
940
+ const where = ['endpoints', 'login', 'clientSecret'];
941
+ if (!config.accounts[account]) {
942
+ ctx.addIssue({
943
+ code: zod_1.z.ZodIssueCode.custom,
944
+ path: [...where, 'account'],
945
+ message: `unknown account ${account}`,
946
+ });
947
+ }
948
+ else if (!config.accounts[account].providers[kind]) {
949
+ ctx.addIssue({
950
+ code: zod_1.z.ZodIssueCode.custom,
951
+ path: [...where, 'from'],
952
+ message: `account ${account} has no credentials for the provider ${kind}`,
953
+ });
954
+ }
955
+ if (!config.secretProviders[kind]) {
956
+ ctx.addIssue({
957
+ code: zod_1.z.ZodIssueCode.custom,
958
+ path: [...where, 'from'],
959
+ message: `secret provider ${kind} is not declared in secretProviders`,
960
+ });
961
+ }
962
+ }
963
+ // only the server is to reach the services behind endpoints, which the NetworkPolicy of
964
+ // a service run says: without it, any pod of the cluster would get past the sign-in
965
+ if (backend.type === 'kubernetes' && backend.networkPolicy !== 'enforced') {
966
+ ctx.addIssue({
967
+ code: zod_1.z.ZodIssueCode.custom,
968
+ path: ['backend', 'networkPolicy'],
969
+ message: 'endpoints keep the services of a run to the server with a NetworkPolicy, set networkPolicy: enforced once the network plugin of the cluster enforces them',
970
+ });
971
+ }
972
+ if (backend.type === 'kubernetes' && backend.kubeconfig) {
973
+ ctx.addIssue({
974
+ code: zod_1.z.ZodIssueCode.custom,
975
+ path: ['endpoints'],
976
+ message: 'endpoints reach the services of runs at their Service in the cluster, run the server in the cluster rather than with a kubeconfig',
977
+ });
978
+ }
979
+ }
748
980
  if (!config.tls && !config.behindTlsProxy && !LOOPBACK_HOSTS.includes(config.listen.host)) {
749
981
  ctx.addIssue({
750
982
  code: zod_1.z.ZodIssueCode.custom,
@@ -760,11 +992,18 @@ function getSandboxRuntimes(config) {
760
992
  return config.sandboxes.runtimes ?? config.runtimes.filter((runtime) => runtime === 'docker');
761
993
  }
762
994
  exports.getSandboxRuntimes = getSandboxRuntimes;
763
- // The accounts that read repositories: no caller uses them and no build file names them.
764
- function getSourceAccounts(config) {
765
- return [...new Set(config.sources.flatMap((source) => (source.secret ? [source.secret.account] : [])))];
995
+ // The accounts only the server reads secrets as: those that read the repositories of
996
+ // `sources`, and the one of the client secret of `endpoints.login`. No caller uses them and
997
+ // no build file names them.
998
+ function getServerAccounts(config) {
999
+ return [
1000
+ ...new Set([
1001
+ ...config.sources.flatMap((source) => (source.secret ? [source.secret.account] : [])),
1002
+ ...(config.endpoints?.login?.clientSecret ? [config.endpoints.login.clientSecret.account] : []),
1003
+ ]),
1004
+ ];
766
1005
  }
767
- exports.getSourceAccounts = getSourceAccounts;
1006
+ exports.getServerAccounts = getServerAccounts;
768
1007
  async function readServerConfig(environment, path) {
769
1008
  if (!(await environment.file.exists(path))) {
770
1009
  throw new Error(`unable to read ${path}: no such file`);