@ship.zone/runner 3.0.0 → 4.0.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 (79) hide show
  1. package/.smartconfig.json +19 -1
  2. package/changelog.md +43 -0
  3. package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
  4. package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +4 -4
  5. package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
  6. package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +4 -4
  7. package/dist_ts/00_commitinfo_data.js +3 -3
  8. package/dist_ts/api-client.d.ts +2 -1
  9. package/dist_ts/api-client.js +10 -2
  10. package/dist_ts/artifact-manager.js +1 -1
  11. package/dist_ts/attempt-state.js +1 -1
  12. package/dist_ts/cache-manager.js +1 -1
  13. package/dist_ts/cli-entry.js +17 -3
  14. package/dist_ts/cli.js +39 -11
  15. package/dist_ts/config.js +70 -20
  16. package/dist_ts/egress-proxy.d.ts +99 -0
  17. package/dist_ts/egress-proxy.js +607 -0
  18. package/dist_ts/errors.js +1 -1
  19. package/dist_ts/filesystem.js +1 -1
  20. package/dist_ts/index.d.ts +5 -1
  21. package/dist_ts/index.js +6 -2
  22. package/dist_ts/interfaces.d.ts +93 -22
  23. package/dist_ts/interfaces.js +1 -1
  24. package/dist_ts/log-sender.js +1 -1
  25. package/dist_ts/microvm-executor.d.ts +90 -0
  26. package/dist_ts/microvm-executor.js +1045 -0
  27. package/dist_ts/node-version.d.ts +11 -0
  28. package/dist_ts/node-version.js +43 -0
  29. package/dist_ts/npm-grants.d.ts +9 -0
  30. package/dist_ts/npm-grants.js +44 -0
  31. package/dist_ts/oci-registry.d.ts +73 -0
  32. package/dist_ts/oci-registry.js +508 -0
  33. package/dist_ts/plugins.d.ts +6 -2
  34. package/dist_ts/plugins.js +7 -3
  35. package/dist_ts/protocol-validator.d.ts +3 -3
  36. package/dist_ts/protocol-validator.js +26 -21
  37. package/dist_ts/redactor.js +1 -1
  38. package/dist_ts/registration-state.js +1 -1
  39. package/dist_ts/runner.d.ts +6 -5
  40. package/dist_ts/runner.js +48 -18
  41. package/dist_ts/source-workspace.js +1 -1
  42. package/dist_ts/spec-version.js +1 -1
  43. package/dist_ts/staging-scavenger.js +1 -1
  44. package/dist_ts/state-owner.js +4 -2
  45. package/dist_ts/transfer-archive.js +1 -1
  46. package/dist_ts/validation.js +1 -1
  47. package/dist_ts/vsock-protocol.d.ts +130 -0
  48. package/dist_ts/vsock-protocol.js +336 -0
  49. package/dist_ts/wire-schema.js +1 -1
  50. package/package.json +9 -6
  51. package/readme.md +72 -61
  52. package/rust/Cargo.lock +1 -0
  53. package/rust/Cargo.toml +2 -1
  54. package/rust/src/cpio.rs +147 -0
  55. package/rust/src/extfs.rs +747 -0
  56. package/rust/src/guest.rs +2411 -0
  57. package/rust/src/lib.rs +41 -0
  58. package/rust/src/main.rs +6 -1
  59. package/rust/src/oci_tar.rs +842 -0
  60. package/ts/00_commitinfo_data.ts +2 -2
  61. package/ts/api-client.ts +19 -1
  62. package/ts/cli-entry.ts +15 -2
  63. package/ts/cli.ts +33 -11
  64. package/ts/config.ts +96 -23
  65. package/ts/egress-proxy.ts +649 -0
  66. package/ts/index.ts +5 -1
  67. package/ts/interfaces.ts +103 -21
  68. package/ts/microvm-executor.ts +1265 -0
  69. package/ts/node-version.ts +49 -0
  70. package/ts/npm-grants.ts +49 -0
  71. package/ts/oci-registry.ts +649 -0
  72. package/ts/plugins.ts +6 -2
  73. package/ts/protocol-validator.ts +29 -25
  74. package/ts/runner.ts +51 -17
  75. package/ts/state-owner.ts +8 -1
  76. package/ts/vsock-protocol.ts +437 -0
  77. package/dist_ts/oci-executor.d.ts +0 -155
  78. package/dist_ts/oci-executor.js +0 -2238
  79. package/ts/oci-executor.ts +0 -2989
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@ship.zone/runner',
6
- version: '3.0.0',
7
- description: 'The isolated OCI job runner for ship.zone CI/CD'
6
+ version: '4.0.0',
7
+ description: 'The Firecracker microVM OCI job runner for ship.zone CI/CD'
8
8
  }
package/ts/api-client.ts CHANGED
@@ -15,12 +15,14 @@ import type {
15
15
  ICompleteJobResponse,
16
16
  IDiscoveryResponse,
17
17
  IErrorResponse,
18
+ IImageRecord,
18
19
  IJobHeartbeatRequest,
19
20
  IJobHeartbeatResponse,
20
21
  IJobIdentity,
21
22
  IJobSource,
22
23
  ILogAcknowledgement,
23
24
  ILogChunk,
25
+ IRecordImageRequest,
24
26
  IRecoverAttemptRequest,
25
27
  IRegisterRunnerRequest,
26
28
  IRegisterRunnerResponse,
@@ -59,6 +61,7 @@ export interface IRunnerApiClientOptions {
59
61
 
60
62
  interface IJsonRequestOptions {
61
63
  requestSchema: TWireSchemaName;
64
+ method?: 'POST' | 'PUT';
62
65
  token?: string;
63
66
  signal?: AbortSignal;
64
67
  fenced?: boolean;
@@ -437,6 +440,21 @@ export class RunnerApiClient {
437
440
  );
438
441
  }
439
442
 
443
+ public async recordImage(
444
+ request: IRecordImageRequest,
445
+ signal?: AbortSignal,
446
+ ): Promise<IImageRecord> {
447
+ return validateWireMessage<IImageRecord>(
448
+ 'ImageRecord',
449
+ await this.requestJson(this.jobPath(request.identity, 'image'), request, {
450
+ method: 'PUT',
451
+ requestSchema: 'RecordImageRequest',
452
+ signal,
453
+ fenced: true,
454
+ }),
455
+ );
456
+ }
457
+
440
458
  public async completeJob(
441
459
  request: ICompleteJobRequest,
442
460
  signal?: AbortSignal,
@@ -632,7 +650,7 @@ export class RunnerApiClient {
632
650
  let response: Response;
633
651
  try {
634
652
  response = await this.fetchImplementation(new URL(path, this.baseUrl), {
635
- method: 'POST',
653
+ method: options.method ?? 'POST',
636
654
  headers: {
637
655
  authorization: `Bearer ${token}`,
638
656
  'content-type': 'application/json',
package/ts/cli-entry.ts CHANGED
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { runCli } from './cli.js';
2
+ import { assertSupportedNodeVersion } from './node-version.js';
3
3
 
4
- await runCli(process.argv.slice(2));
4
+ // The CLI's modules load only after the Node.js version check, so an unsupported release gets a
5
+ // clear refusal instead of a failure deep inside.
6
+ let supported = false;
7
+ try {
8
+ assertSupportedNodeVersion(process.versions.node);
9
+ supported = true;
10
+ } catch (error) {
11
+ console.error(error instanceof Error ? error.message : 'Runner failed');
12
+ process.exitCode = 1;
13
+ }
14
+ if (supported) {
15
+ const { runCli } = await import('./cli.js');
16
+ await runCli(process.argv.slice(2));
17
+ }
package/ts/cli.ts CHANGED
@@ -17,7 +17,7 @@ import type {
17
17
  IRunnerConfig,
18
18
  } from './interfaces.js';
19
19
  import { runnerVersion } from './interfaces.js';
20
- import { OciExecutor } from './oci-executor.js';
20
+ import { MicroVmExecutor } from './microvm-executor.js';
21
21
  import { RegistrationStateStore } from './registration-state.js';
22
22
  import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.js';
23
23
  import { runnerSpecVersion } from './spec-version.js';
@@ -31,10 +31,10 @@ interface IParsedArguments {
31
31
 
32
32
  const cliInvocation = 'ship-zone-runner';
33
33
 
34
- const usage = `ship.zone runner ${runnerVersion}
34
+ const usage = `ship.zone runner ${runnerVersion} (Firecracker microVM)
35
35
 
36
36
  Usage:
37
- ${cliInvocation} init --control-plane <url> [--config <path>] [--name <name>]
37
+ ${cliInvocation} init --control-plane <url> [--profile workload|builder] [--config <path>] [--name <name>] [--kernel-path <path>] [--builder-rootfs-path <path>] [--smartvm-socket <path>] [--allow-egress]
38
38
  ${cliInvocation} register [--config <path>]
39
39
  ${cliInvocation} run [--config <path>]
40
40
  ${cliInvocation} once [--config <path>]
@@ -123,17 +123,37 @@ const runInit = async (options: Map<string, string | true>): Promise<void> => {
123
123
  const config = defaultRunnerConfig();
124
124
  config.controlPlaneUrl = stringOption(options, 'control-plane') ?? '';
125
125
  config.name = stringOption(options, 'name') ?? config.name;
126
+ const profile = stringOption(options, 'profile');
127
+ if (profile !== undefined) {
128
+ if (profile !== 'workload' && profile !== 'builder') {
129
+ throw new ConfigurationError('--profile must be "workload" or "builder"');
130
+ }
131
+ config.oci.runnerProfile = profile;
132
+ }
126
133
  const labels = stringOption(options, 'labels');
127
134
  if (labels) config.labels = labels.split(',').map((entry) => entry.trim()).filter(Boolean);
128
- const runtimePath = stringOption(options, 'runtime-path');
129
- if (runtimePath) config.oci.runtimePath = runtimePath;
135
+ const kernelPath = stringOption(options, 'kernel-path');
136
+ if (kernelPath) config.oci.kernelPath = kernelPath;
137
+ const builderRootfsPath = stringOption(options, 'builder-rootfs-path');
138
+ if (builderRootfsPath) config.oci.builderRootfsPath = builderRootfsPath;
139
+ const smartvmSocket = stringOption(options, 'smartvm-socket');
140
+ if (smartvmSocket) config.oci.smartvmSocketPath = smartvmSocket;
141
+ const smartvmRuntimeDir = stringOption(options, 'smartvm-runtime-dir');
142
+ if (smartvmRuntimeDir) config.oci.smartvmRuntimeDir = smartvmRuntimeDir;
143
+ const smartvmBridgePath = stringOption(options, 'smartvm-bridge-path');
144
+ if (smartvmBridgePath) config.oci.smartvmBridgePath = smartvmBridgePath;
130
145
  const helperPath = stringOption(options, 'workspace-helper-path');
131
146
  if (helperPath) config.oci.workspaceHelperPath = helperPath;
132
147
  if (options.has('allow-insecure-loopback')) config.allowInsecureLoopback = true;
133
- if (options.has('allow-network')) {
134
- throw new ConfigurationError(
135
- '--allow-network is not supported: this runner does not enforce egress allowlists',
136
- );
148
+ if (options.has('allow-egress') || options.has('allow-network')) {
149
+ config.oci.allowedNetworks = ['none', 'egress'];
150
+ }
151
+ const blockedCidr = stringOption(options, 'egress-blocked-cidr');
152
+ if (blockedCidr) {
153
+ config.oci.egressBlockedCidrs = blockedCidr
154
+ .split(',')
155
+ .map((entry) => entry.trim())
156
+ .filter(Boolean);
137
157
  }
138
158
  validateRunnerConfig(config);
139
159
  const path = configPath(options);
@@ -148,9 +168,9 @@ const runRegister = async (options: Map<string, string | true>): Promise<void> =
148
168
  throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for registration');
149
169
  }
150
170
  const stateOwner = await acquireStateOwner(config);
171
+ const executor = new MicroVmExecutor(config, stateOwner);
151
172
  try {
152
173
  const api = apiFor(config);
153
- const executor = new OciExecutor(config, stateOwner);
154
174
  const runtime = await executor.verifyRuntime();
155
175
  const discovery = await api.discover();
156
176
  const capabilities = runnerCapabilities(config, runtime);
@@ -164,6 +184,7 @@ const runRegister = async (options: Map<string, string | true>): Promise<void> =
164
184
  });
165
185
  console.log(`Registered runner ${registered.runnerId}`);
166
186
  } finally {
187
+ await executor.close().catch(() => {});
167
188
  await stateOwner.release();
168
189
  }
169
190
  };
@@ -188,9 +209,9 @@ const runDaemon = async (
188
209
  const shutdownListener = (): void => shutdown.abort('runner_shutdown');
189
210
  const signals = ['SIGINT', 'SIGTERM'] as const;
190
211
  for (const signal of signals) process.on(signal, shutdownListener);
212
+ const executor = new MicroVmExecutor(config, stateOwner);
191
213
  try {
192
214
  const api = apiFor(config);
193
- const executor = new OciExecutor(config, stateOwner);
194
215
  const reportMessage = (message: string): void => console.error(message);
195
216
  const runner = new ShipRunner(config, {
196
217
  stateOwner,
@@ -210,6 +231,7 @@ const runDaemon = async (
210
231
  if (once) console.log(result.claimed ? `Job ${result.status}` : 'No job available');
211
232
  } finally {
212
233
  for (const signal of signals) process.off(signal, shutdownListener);
234
+ await executor.close().catch(() => {});
213
235
  await stateOwner.release();
214
236
  }
215
237
  };
package/ts/config.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as plugins from './plugins.js';
2
+ import { parseCidr } from './egress-proxy.js';
2
3
  import { ConfigurationError } from './errors.js';
3
4
  import {
4
5
  createNewWriteFlags,
@@ -30,9 +31,12 @@ const timestampPattern =
30
31
  /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-](\d{2}):(\d{2}))$/;
31
32
 
32
33
  const defaultOciConfig: IOciExecutorConfig = {
33
- runtime: 'docker',
34
- runtimePath: '/usr/bin/docker',
35
- requireRootless: true,
34
+ runnerProfile: 'workload',
35
+ kernelPath: '/var/lib/ship-zone-runner/vmlinux',
36
+ bootArgs: 'console=ttyS0 reboot=k panic=1 pci=off rdinit=/init',
37
+ maximumRootfsBytes: 4 * 1024 * 1024 * 1024,
38
+ guestMemoryOverheadBytes: 128 * 1024 * 1024,
39
+ egressBlockedCidrs: [],
36
40
  allowedNetworks: ['none'],
37
41
  containerUser: '65532:65532',
38
42
  defaultTimeoutMs: 30 * 60 * 1000,
@@ -182,28 +186,51 @@ const validTimestamp = (value: string): boolean => {
182
186
  };
183
187
 
184
188
  /**
185
- * The OCI executor enforces only the `none` network mode: every step container gets a new network
186
- * namespace with loopback only. `egress` needs a runner-provided resolver and per-attempt
187
- * connection filtering that this executor does not implement, so it can be neither configured nor
188
- * advertised.
189
+ * Network modes enforceable by the Firecracker microVM runner:
190
+ * - `none` (always required): isolated guest namespace with loopback only.
191
+ * - `egress` (opt-in): host-enforced DNS/SNI/Host allowlist proxy with non-global IP blocking.
189
192
  */
190
193
  const requireEnforceableNetworks = (networks: readonly string[]): void => {
191
- if (networks.length !== 1 || networks[0] !== 'none') {
194
+ if (
195
+ networks.length === 0 ||
196
+ !networks.includes('none') ||
197
+ networks.some((mode) => mode !== 'none' && mode !== 'egress')
198
+ ) {
192
199
  throw new ConfigurationError(
193
- 'oci.allowedNetworks must be ["none"]: this runner does not enforce egress allowlists',
200
+ 'oci.allowedNetworks must include "none" and contain only "none" or "egress"',
194
201
  );
195
202
  }
196
203
  };
197
204
 
205
+ const parseBlockedCidrs = (value: unknown, fallback: string[]): string[] => {
206
+ if (value === undefined) return [...fallback];
207
+ if (!Array.isArray(value) || value.length > 64 || value.some((entry) => typeof entry !== 'string')) {
208
+ throw new ConfigurationError('oci.egressBlockedCidrs must be an array of at most 64 CIDR strings');
209
+ }
210
+ for (const cidr of value) {
211
+ try {
212
+ parseCidr(cidr);
213
+ } catch {
214
+ throw new ConfigurationError(`oci.egressBlockedCidrs contains invalid CIDR: ${cidr}`);
215
+ }
216
+ }
217
+ return [...value];
218
+ };
219
+
198
220
  const parseOciConfig = (input: unknown, fallback: IOciExecutorConfig): IOciExecutorConfig => {
199
221
  const value = input === undefined ? {} : input;
200
222
  if (!isRecord(value)) throw new ConfigurationError('oci must be an object');
201
223
  if (Object.hasOwn(value, 'allowMutableImages')) {
202
224
  throw new ConfigurationError('oci.allowMutableImages is not supported by the runner protocol');
203
225
  }
204
- const runtime = value.runtime ?? fallback.runtime;
205
- if (runtime !== 'docker' && runtime !== 'podman') {
206
- throw new ConfigurationError('oci.runtime must be docker or podman');
226
+ if (Object.hasOwn(value, 'runtime') || Object.hasOwn(value, 'runtimePath')) {
227
+ throw new ConfigurationError(
228
+ 'oci.runtime and oci.runtimePath were removed in 4.0.0; this runner uses Firecracker microVMs exclusively',
229
+ );
230
+ }
231
+ const runnerProfile = value.runnerProfile ?? fallback.runnerProfile;
232
+ if (runnerProfile !== 'workload' && runnerProfile !== 'builder') {
233
+ throw new ConfigurationError('oci.runnerProfile must be "workload" or "builder"');
207
234
  }
208
235
  const allowedNetworks = stringArray(
209
236
  value.allowedNetworks,
@@ -213,14 +240,30 @@ const parseOciConfig = (input: unknown, fallback: IOciExecutorConfig): IOciExecu
213
240
  );
214
241
  requireEnforceableNetworks(allowedNetworks);
215
242
  return {
216
- runtime,
217
- runtimePath: stringValue(value.runtimePath, fallback.runtimePath, 'oci.runtimePath'),
218
- workspaceHelperPath: optionalString(value.workspaceHelperPath, 'oci.workspaceHelperPath'),
219
- requireRootless: booleanValue(
220
- value.requireRootless,
221
- fallback.requireRootless,
222
- 'oci.requireRootless',
243
+ runnerProfile,
244
+ kernelPath: stringValue(value.kernelPath, fallback.kernelPath, 'oci.kernelPath'),
245
+ builderRootfsPath: optionalString(value.builderRootfsPath, 'oci.builderRootfsPath'),
246
+ buildctlPath: optionalString(value.buildctlPath, 'oci.buildctlPath'),
247
+ smartvmSocketPath: optionalString(value.smartvmSocketPath, 'oci.smartvmSocketPath'),
248
+ smartvmRuntimeDir: optionalString(value.smartvmRuntimeDir, 'oci.smartvmRuntimeDir'),
249
+ smartvmBridgePath: optionalString(value.smartvmBridgePath, 'oci.smartvmBridgePath'),
250
+ bootArgs: stringValue(value.bootArgs, fallback.bootArgs, 'oci.bootArgs', 1024),
251
+ maximumRootfsBytes: integerValue(
252
+ value.maximumRootfsBytes,
253
+ fallback.maximumRootfsBytes,
254
+ 'oci.maximumRootfsBytes',
255
+ 16_777_216,
256
+ 1_099_511_627_776,
257
+ ),
258
+ guestMemoryOverheadBytes: integerValue(
259
+ value.guestMemoryOverheadBytes,
260
+ fallback.guestMemoryOverheadBytes,
261
+ 'oci.guestMemoryOverheadBytes',
262
+ 16_777_216,
263
+ 1_073_741_824,
223
264
  ),
265
+ egressBlockedCidrs: parseBlockedCidrs(value.egressBlockedCidrs, fallback.egressBlockedCidrs),
266
+ workspaceHelperPath: optionalString(value.workspaceHelperPath, 'oci.workspaceHelperPath'),
224
267
  allowedNetworks: allowedNetworks as IOciExecutorConfig['allowedNetworks'],
225
268
  containerUser: stringValue(value.containerUser, fallback.containerUser, 'oci.containerUser'),
226
269
  defaultTimeoutMs: integerValue(
@@ -627,16 +670,46 @@ export const validateRunnerConfig = (config: IRunnerConfig): void => {
627
670
  }
628
671
  numberValue(config.oci.defaultCpus, config.oci.defaultCpus, 'oci.defaultCpus', 0, 1024);
629
672
  numberValue(config.oci.maximumCpus, config.oci.maximumCpus, 'oci.maximumCpus', 0, 1024);
630
- if (config.oci.runtime !== 'docker' && config.oci.runtime !== 'podman') {
631
- throw new ConfigurationError('oci.runtime must be docker or podman');
673
+ if (config.oci.runnerProfile !== 'workload' && config.oci.runnerProfile !== 'builder') {
674
+ throw new ConfigurationError('oci.runnerProfile must be "workload" or "builder"');
632
675
  }
633
676
  requireEnforceableNetworks(config.oci.allowedNetworks);
634
- if (!isAbsolute(config.oci.runtimePath)) {
635
- throw new ConfigurationError('oci.runtimePath must be absolute');
677
+ parseBlockedCidrs(config.oci.egressBlockedCidrs, []);
678
+ if (!isAbsolute(config.oci.kernelPath)) {
679
+ throw new ConfigurationError('oci.kernelPath must be absolute');
680
+ }
681
+ if (config.oci.builderRootfsPath && !isAbsolute(config.oci.builderRootfsPath)) {
682
+ throw new ConfigurationError('oci.builderRootfsPath must be absolute');
683
+ }
684
+ if (config.oci.buildctlPath && !isAbsolute(config.oci.buildctlPath)) {
685
+ throw new ConfigurationError('oci.buildctlPath must be absolute');
686
+ }
687
+ if (config.oci.smartvmSocketPath && !isAbsolute(config.oci.smartvmSocketPath)) {
688
+ throw new ConfigurationError('oci.smartvmSocketPath must be absolute');
689
+ }
690
+ if (config.oci.smartvmRuntimeDir && !isAbsolute(config.oci.smartvmRuntimeDir)) {
691
+ throw new ConfigurationError('oci.smartvmRuntimeDir must be absolute');
692
+ }
693
+ if (config.oci.smartvmBridgePath && !isAbsolute(config.oci.smartvmBridgePath)) {
694
+ throw new ConfigurationError('oci.smartvmBridgePath must be absolute');
636
695
  }
637
696
  if (config.oci.workspaceHelperPath && !isAbsolute(config.oci.workspaceHelperPath)) {
638
697
  throw new ConfigurationError('oci.workspaceHelperPath must be absolute');
639
698
  }
699
+ integerValue(
700
+ config.oci.maximumRootfsBytes,
701
+ config.oci.maximumRootfsBytes,
702
+ 'oci.maximumRootfsBytes',
703
+ 16_777_216,
704
+ 1_099_511_627_776,
705
+ );
706
+ integerValue(
707
+ config.oci.guestMemoryOverheadBytes,
708
+ config.oci.guestMemoryOverheadBytes,
709
+ 'oci.guestMemoryOverheadBytes',
710
+ 16_777_216,
711
+ 1_073_741_824,
712
+ );
640
713
  const user = /^([1-9][0-9]*)(?::([1-9][0-9]*))?$/.exec(config.oci.containerUser);
641
714
  if (!user || [user[1], user[2] ?? user[1]].some((entry) => Number(entry) > 4_294_967_294)) {
642
715
  throw new ConfigurationError('oci.containerUser must be a numeric non-root UID[:GID]');