@ship.zone/runner 3.0.0 → 5.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 (80) hide show
  1. package/.smartconfig.json +19 -1
  2. package/changelog.md +61 -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.d.ts +7 -0
  15. package/dist_ts/cli.js +155 -35
  16. package/dist_ts/config.js +75 -22
  17. package/dist_ts/egress-proxy.d.ts +99 -0
  18. package/dist_ts/egress-proxy.js +607 -0
  19. package/dist_ts/errors.js +1 -1
  20. package/dist_ts/filesystem.js +1 -1
  21. package/dist_ts/index.d.ts +5 -1
  22. package/dist_ts/index.js +6 -2
  23. package/dist_ts/interfaces.d.ts +85 -31
  24. package/dist_ts/interfaces.js +1 -1
  25. package/dist_ts/log-sender.js +1 -1
  26. package/dist_ts/microvm-executor.d.ts +90 -0
  27. package/dist_ts/microvm-executor.js +1078 -0
  28. package/dist_ts/node-version.d.ts +11 -0
  29. package/dist_ts/node-version.js +43 -0
  30. package/dist_ts/npm-grants.d.ts +9 -0
  31. package/dist_ts/npm-grants.js +44 -0
  32. package/dist_ts/oci-registry.d.ts +73 -0
  33. package/dist_ts/oci-registry.js +508 -0
  34. package/dist_ts/plugins.d.ts +6 -2
  35. package/dist_ts/plugins.js +7 -3
  36. package/dist_ts/protocol-validator.d.ts +3 -5
  37. package/dist_ts/protocol-validator.js +27 -51
  38. package/dist_ts/redactor.js +1 -1
  39. package/dist_ts/registration-state.js +1 -1
  40. package/dist_ts/runner.d.ts +5 -5
  41. package/dist_ts/runner.js +47 -22
  42. package/dist_ts/source-workspace.js +1 -1
  43. package/dist_ts/spec-version.js +1 -1
  44. package/dist_ts/staging-scavenger.js +1 -1
  45. package/dist_ts/state-owner.js +4 -2
  46. package/dist_ts/transfer-archive.js +1 -1
  47. package/dist_ts/validation.js +1 -1
  48. package/dist_ts/vsock-protocol.d.ts +130 -0
  49. package/dist_ts/vsock-protocol.js +336 -0
  50. package/dist_ts/wire-schema.js +1 -1
  51. package/package.json +19 -15
  52. package/readme.md +106 -108
  53. package/rust/Cargo.lock +1 -0
  54. package/rust/Cargo.toml +2 -1
  55. package/rust/src/cpio.rs +147 -0
  56. package/rust/src/extfs.rs +747 -0
  57. package/rust/src/guest.rs +2411 -0
  58. package/rust/src/lib.rs +41 -0
  59. package/rust/src/main.rs +6 -1
  60. package/rust/src/oci_tar.rs +842 -0
  61. package/ts/00_commitinfo_data.ts +2 -2
  62. package/ts/api-client.ts +19 -1
  63. package/ts/cli-entry.ts +15 -2
  64. package/ts/cli.ts +172 -40
  65. package/ts/config.ts +100 -25
  66. package/ts/egress-proxy.ts +649 -0
  67. package/ts/index.ts +5 -1
  68. package/ts/interfaces.ts +97 -30
  69. package/ts/microvm-executor.ts +1310 -0
  70. package/ts/node-version.ts +49 -0
  71. package/ts/npm-grants.ts +49 -0
  72. package/ts/oci-registry.ts +649 -0
  73. package/ts/plugins.ts +6 -2
  74. package/ts/protocol-validator.ts +29 -58
  75. package/ts/runner.ts +48 -21
  76. package/ts/state-owner.ts +8 -1
  77. package/ts/vsock-protocol.ts +437 -0
  78. package/dist_ts/oci-executor.d.ts +0 -155
  79. package/dist_ts/oci-executor.js +0 -2238
  80. package/ts/oci-executor.ts +0 -2989
package/readme.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # @ship.zone/runner
2
2
 
3
- `@ship.zone/runner` is the outbound-only OCI execution agent for ship.zone CI/CD. It implements the
4
- runner protocol of `@ship.zone/ci-spec` (2.0.0) for the `oci` execution profile, validates leases
5
- and compiled jobs against the published schemas, and runs one fenced attempt at a time on a local
6
- Docker or Podman engine.
3
+ `@ship.zone/runner` is the outbound-only Firecracker microVM execution agent for ship.zone CI/CD.
4
+ It implements the runner protocol of `@ship.zone/ci-spec` (3.0.0) across all three execution profiles
5
+ (`oci`, `vm`, and `oci-image`) on one unified runner, validates leases and compiled jobs against the
6
+ published schemas, and runs one fenced attempt at a time inside a fresh disposable Firecracker
7
+ microVM managed via `@push.rocks/smartvm`.
8
+
9
+ No host Docker or Podman daemon is required or supported. Jobs still choose any digest-pinned
10
+ Linux Docker/OCI image; the runner pulls and verifies the image layers directly via OCI
11
+ Distribution v2, builds a deterministic read-only ext2 rootfs image, and boots a fresh Firecracker
12
+ microVM with that image attached read-only (`/dev/vda`) and the static Rust `runnerworkspace` guest
13
+ agent as PID 1 (`/init`). When configured with `--builder-rootfs-path` or `--builder-image`, the
14
+ exact same runner also advertises and executes `oci-image` builds via BuildKit (`buildctl`) inside
15
+ a fresh Firecracker microVM and records the produced image digest with the coordinator.
7
16
 
8
17
  The control plane owns workflow compilation, scheduling, authorization, secrets policy, and
9
18
  canonical run state. This package owns runner registration, lease handling, isolated execution,
@@ -19,30 +28,29 @@ Requests directly.
19
28
 
20
29
  ## Security Model
21
30
 
22
- - Only local Unix-socket Docker and Podman endpoints are accepted. Remote contexts and connections
23
- are rejected before capabilities are advertised.
24
- - Job images must be Linux images pinned by an exact SHA-256 digest. The image OS, architecture, and
25
- digest are checked before lease acceptance.
26
- - Every compiled step runs in a fresh container as a numeric non-root user with a read-only root,
27
- all capabilities dropped, `no-new-privileges`, private IPC, and CPU, memory, PID, shared-memory
28
- (`/dev/shm`), time, and writable-storage limits. The job's `resources` are these ceilings; omitted
29
- values take the runner defaults, and every value is bounded by the maximum the runner advertises.
30
- - The only network mode is `none`: every step container runs in a new network namespace whose only
31
- interface is its own loopback, so nothing leaves the sandbox and loopback ports never collide with
32
- another attempt. The runner exposes no service on that loopback. `egress` allowlists are not
33
- enforced by this runner, are never advertised, and cannot be configured.
34
- - Job containers receive no host paths, runtime sockets, devices, host namespaces, or arbitrary OCI
35
- arguments. Their only persistent writable mount is `/workspace`.
36
- - The shared workspace is an attempt-specific `nodev,nosuid` tmpfs with hard byte and entry
37
- ceilings. Imported executable files may run directly from it. A trusted static Rust helper imports
38
- source/cache staging, measures the workspace around every step, and exports only declared
39
- artifact/cache paths.
40
- - Helper containers use the exact job image only as an inert root filesystem. They override the
41
- entrypoint with the packaged static helper, have no network, and receive only the narrowly scoped
42
- `CHOWN` and `DAC_OVERRIDE` capabilities required for private staging ownership. Job containers do
43
- not receive those capabilities.
44
- - Step containers receive exactly the compiled step environment plus job secrets. Secret values are
45
- passed through the runtime environment rather than OCI command arguments.
31
+ - Every attempt runs inside its own jailed Firecracker microVM (`/dev/kvm`) managed via
32
+ `@push.rocks/smartvm` (`smartvm-helper`). No host Docker or Podman daemon is used or accepted.
33
+ - Job images must be Linux images pinned by an exact SHA-256 digest (or resolved from a
34
+ coordinator-supplied candidate binding). The runner pulls and verifies every manifest, config, and
35
+ layer digest directly via OCI Distribution v2, matching pull grants strictly by literal registry
36
+ and repository with redirect refusal and attempt-private caching for grant-backed images.
37
+ - In `oci` profile, every compiled step runs inside the microVM pivoted into the read-only OCI
38
+ rootfs (`/dev/vda`) as a numeric non-root user with all capabilities dropped, `no-new-privileges`,
39
+ private namespaces, and bounded vCPU, memory, PID, shared-memory (`/dev/shm`), time, and
40
+ writable-storage limits. In `vm` profile, steps run inside the microVM over an ephemeral writable
41
+ overlayfs above the read-only OCI rootfs and are torn down between steps via cgroup v2 kill.
42
+ - `oci-image` builds run on the same unified runner inside a fresh Firecracker microVM with
43
+ source-policy digest pinning, scoped `0400` secrets and push credentials, attestations disabled,
44
+ and digest-only push before calling `PUT /jobs/{jobId}/attempts/{attemptId}/image`.
45
+ - Network mode is `none` (Firecracker microVM with no external connectivity). The host egress policy
46
+ controller (`EgressAllowlistController`) is tested and ready for future guest network transport;
47
+ until that transport is wired into Firecracker/smartvm, the runner advertises `['none']` only.
48
+ - MicroVMs receive no host paths, runtime sockets, devices, or host namespaces. Their only
49
+ persistent writable workspace is `/workspace`, imported/exported by the static Rust
50
+ `runnerworkspace` guest PID 1 agent over vsock.
51
+ - `.npmrc` credentials from `npmGrants` are mounted read-only inside the guest and exposed via
52
+ `NPM_CONFIG_USERCONFIG`; every secret value and npm grant token is added to the attempt's
53
+ redaction set.
46
54
  - The attempt's redaction set holds every secret value, every npm grant token, and each line of a
47
55
  value containing a line terminator (CR LF, LF, or CR), leaving out members shorter than 8 UTF-8
48
56
  bytes; a short line of a multi-line value stays unmasked when printed on its own. Every member is
@@ -55,13 +63,12 @@ Requests directly.
55
63
 
56
64
  ## Requirements
57
65
 
58
- - Linux on x64 or arm64
66
+ - Linux on x64 or arm64 with `/dev/kvm`
67
+ - `smartvm-helper` (`@push.rocks/smartvm`) with Firecracker v1.17+ and a pinned Linux `vmlinux` kernel
59
68
  - For the npm package: Node.js 26.1 or later; the staging capacity check reads the filesystem
60
69
  fragment size, `statfs` `frsize`, which Node.js provides from 26.1 on. The executables embed
61
70
  Node.js 26.11.1.
62
71
  - pnpm 12
63
- - Docker or Podman on Linux
64
- - A rootless runtime by default
65
72
  - Rust and configured cross-compilers when building the packaged helpers from source
66
73
 
67
74
  ## Install
@@ -116,25 +123,11 @@ explicit absolute helper path for development or controlled deployments.
116
123
 
117
124
  Configured, packaged, and dependency-injected helper resolver paths are source files. Runtime
118
125
  verification reads the bounded regular source through one pinned file descriptor, hashes those exact
119
- bytes, and materializes an executable mode-`0755` copy below the private mode-`0700` runner state
120
- subdirectory as `workspace-helpers/runnerworkspace_<target>_musl_<sha256>`. Source permissions are
121
- not changed, so package managers may install the source without executable bits. The private parent
122
- directory is the host access boundary; mode `0755` lets capability-dropped helper containers execute
123
- the host-owned read-only bind mount. `IOciRuntimeFacts.helperPath` reports the validated
124
- materialized path used by host probes and OCI bind mounts, while `helperSha256` reports its content
125
- digest. Existing digest paths are reused only
126
- after their type, single-link status, mode, and digest are revalidated without mutating them; the
127
- runner retains a bounded set for rollback, reclaims stale incomplete temporary copies, and rejects
128
- excessive recent temporary residue. The sole immediate-recovery exception is a validated temporary
129
- name and exact digest destination that still reference the same two-link inode after interruption;
130
- the runner removes the temporary name, verifies the destination became single-link, and then reuses
131
- it. The advisory `.workspace-helper.lock` file of runner 2.x is no longer used and is removed.
132
-
133
- Runtime verification creates one private `.runtime-probe-owner_<id>` marker in the helper state.
134
- Host tmpfs probes include that owner in their exact directory names, and OCI runtime probe volumes
135
- carry the same `ship.zone.runner.runtime-probe-owner` label. This lets interrupted verification be
136
- cleaned by the same state owner without touching unowned probes or probes from another runner. The
137
- runner syncs both the helper-directory entry and a newly created owner marker before using them.
126
+ bytes, materializes an executable mode-`0755` copy below the private mode-`0700` runner state
127
+ subdirectory as `workspace-helpers/runnerworkspace_<target>_musl_<sha256>`, and packages it into a
128
+ deterministic initramfs (`initrd_<target>_<sha256>.cpio`) booted as PID 1 (`/init`) inside every
129
+ Firecracker microVM. `IOciRuntimeFacts.helperPath` reports the materialized host helper path while
130
+ `initrdPath` and `helperSha256` report the generated initrd and helper digest.
138
131
 
139
132
  ## State Directory Ownership
140
133
 
@@ -159,42 +152,55 @@ single in-process chain.
159
152
 
160
153
  ## Configure And Run
161
154
 
162
- Create a private runner configuration:
155
+ Enroll in a single step using a one-time bootstrap token minted on `console.ship.zone`, then start
156
+ the daemon:
163
157
 
164
158
  ```sh
165
- ship-zone-runner init \
166
- --control-plane https://foss.global \
167
- --runtime-path /usr/bin/docker
159
+ SHIP_RUNNER_BOOTSTRAP_TOKEN='<one-time token>' ship-zone-runner enroll \
160
+ --control-plane https://console.ship.zone
161
+ ship-zone-runner run
168
162
  ```
169
163
 
170
- Register with a one-time bootstrap token, then start the daemon:
164
+ Or initialize and register in two separate steps (`init` + `register`):
171
165
 
172
166
  ```sh
167
+ ship-zone-runner init \
168
+ --control-plane https://console.ship.zone \
169
+ --kernel-path /var/lib/ship-zone-runner/vmlinux
173
170
  SHIP_RUNNER_BOOTSTRAP_TOKEN='<one-time token>' ship-zone-runner register
174
171
  ship-zone-runner run
175
172
  ```
176
173
 
177
- The runner uses `/dev/shm` for fail-closed host tmpfs verification before registration and must be
178
- trusted with unrestricted subprocess execution for the configured OCI runtime.
174
+ Optional flags for `enroll` / `init`:
175
+
176
+ - `--builder-rootfs-path <path>` or `--builder-image <ref@sha256:...>`: enable `oci-image`
177
+ BuildKit image builds alongside `oci` and `vm` on the same unified runner (`['oci', 'vm', 'oci-image']`).
178
+ - `--labels <a,b>` (repeatable): customize advertised runner labels.
179
+ - `--name <name>`: override the default `runner-<hostname>` runner name.
180
+ - `--smartvm-socket <path>`: override the default `/run/smartvm/helper.sock` helper socket.
181
+
182
+ The runner verifies the Firecracker kernel and `smartvm-helper` (`@push.rocks/smartvm`) before
183
+ registration and boots a fresh per-attempt Firecracker microVM for every job.
179
184
 
180
185
  Replace `run` with `once` to claim at most one job or `config` to print the effective configuration
181
186
  with credentials masked. Within this repository, `pnpm build` followed by
182
187
  `node dist_ts/cli-entry.js <command>` is the equivalent development invocation.
183
188
  `SHIP_RUNNER_CONFIG` selects a config path; the default is `./runner.config.json`.
184
189
 
185
- `init` writes the config with mode `0600`. Registration verifies the runtime and protocol discovery
186
- document before advertising capabilities, durably journals the exact registration request without
187
- the bootstrap token, then atomically replaces the bootstrap token with the returned runner
188
- credential. An interrupted registration replays the journaled request and rejects configuration
189
- drift. Credential rotation from session and runner-heartbeat responses is persisted before the new
190
- credential becomes active.
190
+ `init` and `enroll` write the config with mode `0600`. Registration verifies the runtime and
191
+ protocol discovery document before advertising capabilities, durably journals the exact registration
192
+ request without the bootstrap token, then atomically replaces the bootstrap token with the returned
193
+ runner credential. An interrupted registration replays the journaled request and rejects
194
+ configuration drift. Credential rotation from session and runner-heartbeat responses is persisted
195
+ before the new credential becomes active.
191
196
 
192
197
  The default policy includes:
193
198
 
194
- - rootless Docker at `/usr/bin/docker`;
195
- - labels for Linux, the current architecture, and OCI;
199
+ - Firecracker microVM isolation via `@push.rocks/smartvm` (`oci` and `vm`, plus `oci-image` when a
200
+ builder rootfs or pinned builder image is configured);
201
+ - labels for Linux, the current architecture, and `microvm`;
196
202
  - network `none` only;
197
- - job user `65532:65532`;
203
+ - job user `65532:65532` (for `oci` steps);
198
204
  - a 4 GiB maximum logical workspace and 100,000 entries;
199
205
  - bounded source, artifact, cache, log, environment, and staging limits;
200
206
  - a 1 GiB free-space and 10,000-inode staging reserve.
@@ -209,30 +215,27 @@ For each claim, the runner:
209
215
  job schema and the specification version acceptance rule, the RFC 8785 `compiledPlanDigest`,
210
216
  internal job coherence, the lease coherence of `grants`, `bindings`, and `npmGrants`, fit against
211
217
  the immutable advertised capability snapshot, and all runner execution policy before image
212
- inspection or pull. A lease that fails any check, or that this runner does not execute, is
218
+ materialization. A lease that fails any check, or that this runner does not execute, is
213
219
  abandoned as `runner_error` before acceptance.
214
- 2. Pulls or locates the exact image digest, validates its Linux architecture, and probes it with the
215
- inert helper.
220
+ 2. Materializes the exact digest-pinned OCI image (or configured builder rootfs/image) into a
221
+ deterministic ext2 rootfs and validates its Linux architecture.
216
222
  3. Writes a private interrupted-attempt journal and sends the explicit fenced acceptance request.
217
223
  Source transfer and execution do not start before HTTP 204.
218
224
  4. Downloads and validates the source `tar.gz`, then restores readable caches in declaration order
219
225
  into private host staging.
220
- 5. Imports staging into the bounded tmpfs and runs compiled steps in declaration order, stopping at
221
- the first non-zero exit.
222
- 6. Publishes successful read-write caches and artifacts selected by their `when` policy as
223
- deterministic, replayable `tar.gz` transfers.
224
- 7. Cleans staging, helper/step containers, and the tmpfs volume before sending the idempotent
225
- terminal completion, then clears the recovery journal after the coordinator accepts it.
226
-
227
- An attempt-scoped inert holder container keeps Docker's local-driver tmpfs mounted while fresh step
228
- and helper containers come and go. It runs no image-provided command and is removed with the
229
- workspace.
230
-
231
- On restart, the runner first scavenges only its known host-staging directories, journal temporary
232
- files, and stale private copies of the state owner helper, right after it owns the state directory
233
- and before it verifies the runtime. A new session then removes stale labeled containers and volumes
234
- locally, reads the secret-free journal, and calls the recovery endpoint to revoke and reconcile the
235
- interrupted attempt. Work is never resumed, and a coordinator outage cannot retain prior staging.
226
+ 5. Boots a fresh Firecracker microVM, transfers the workspace over vsock into the guest's bounded
227
+ `/workspace`, and executes compiled steps (or `oci-image` BuildKit build) in order.
228
+ 6. Exports artifacts and read-write caches over vsock and publishes them as deterministic,
229
+ replayable `tar.gz` transfers.
230
+ 7. Destroys the Firecracker microVM and cleans host staging before sending the idempotent terminal
231
+ completion, then clears the recovery journal after the coordinator accepts it.
232
+
233
+ On restart, the runner first scavenges its known host-staging directories, journal temporary files,
234
+ and stale private copies of the state owner helper, right after it owns the state directory and
235
+ before it verifies the runtime. A new session then destroys any orphaned Firecracker VMs recorded
236
+ in `active-vms.json`, reads the secret-free journal, and calls the recovery endpoint to revoke and
237
+ reconcile the interrupted attempt. Work is never resumed, and a coordinator outage cannot retain
238
+ prior staging.
236
239
 
237
240
  ## Job Timeout
238
241
 
@@ -272,14 +275,15 @@ every coordinator of major version 2. A leased job is accepted only when its `sp
272
275
  major version and is not newer than the implemented version; any other job is abandoned as
273
276
  `runner_error`.
274
277
 
275
- The runner advertises the `oci` profile, `container` isolation, the native `linux/<arch>` platform
276
- of its verified OCI engine, the `none` network mode, its transfer limits, `resources` maxima for
277
- memory, CPUs, PIDs, and shared memory, an empty `leaseFeatures` list because it uses no image pull
278
- grants, candidate bindings, or npm read grants, and `maximumTimeoutMs`, its configured
279
- `oci.maximumTimeoutMs`. It refuses, by abandoning the lease as `runner_error` before acceptance,
280
- every lease it cannot execute as specified: the `vm` and `oci-image` profiles, `microvm` isolation,
281
- `egress` networks, candidate images with `bindings`, image `grants`, jobs with `npmRead` and their
282
- `npmGrants`, and jobs whose `timeoutMs` exceeds `oci.maximumTimeoutMs`.
278
+ The runner advertises `microvm` isolation, its native `linux/<arch>` platform, `executionProfiles`
279
+ of `['oci', 'vm']` for a `workload` runner or `['oci-image']` for a dedicated `builder` runner,
280
+ `networks` of `['none']` (or `['none', 'egress']` when `--allow-egress` is enabled), its transfer
281
+ limits, `resources` maxima for memory, CPUs, PIDs, and shared memory,
282
+ `leaseFeatures: ['image-pull-grants', 'candidate-bindings', 'npm-read-grants']`, and
283
+ `maximumTimeoutMs`, its configured `oci.maximumTimeoutMs`. It refuses, by abandoning the lease as
284
+ `runner_error` before acceptance, any lease outside its advertised capabilities (for example
285
+ `container` isolation, non-Linux platforms, mismatched execution profile, or `timeoutMs` exceeding
286
+ `oci.maximumTimeoutMs`).
283
287
 
284
288
  The reserved step environment names are `SHIPZONE_CI_MATRIX_JSON` and `SHIPZONE_CI_INPUTS_JSON`,
285
289
  each carrying canonical RFC 8785 JSON. A job whose step environment defines any other
@@ -305,6 +309,7 @@ published OpenAPI component before it is sent, and every response before it is u
305
309
  | Source | `GET sources/{sha256}` | Immutable attempt-bound digest |
306
310
  | Artifact | `PUT jobs/{jobId}/attempts/{attemptId}/artifacts/{name}` | `transferRequestId` and metadata |
307
311
  | Cache | `GET/PUT jobs/{jobId}/attempts/{attemptId}/caches/{name}` | Fenced declaration and transfer ID |
312
+ | Record image | `PUT jobs/{jobId}/attempts/{attemptId}/image` | Fenced produced OCI image digest |
308
313
 
309
314
  Transient retry statuses are 429, 502, 503, and 504. Exact retries reuse the same request ID and
310
315
  canonical body. Request, response, archive, extracted-data, entry, and stream sizes are bounded.
@@ -322,7 +327,8 @@ import {
322
327
  ArtifactManager,
323
328
  CacheManager,
324
329
  defaultRunnerConfig,
325
- OciExecutor,
330
+ EgressAllowlistController,
331
+ MicroVmExecutor,
326
332
  RunnerApiClient,
327
333
  ShipRunner,
328
334
  SourceWorkspaceManager,
@@ -334,11 +340,11 @@ verification, discovery, lifecycle, fencing, cleanup, and credential-persistence
334
340
  own the state directory first:
335
341
 
336
342
  ```ts
337
- import { OciExecutor, RunnerStateOwner, ShipRunner } from '@ship.zone/runner';
343
+ import { MicroVmExecutor, RunnerStateOwner, ShipRunner } from '@ship.zone/runner';
338
344
 
339
345
  const stateOwner = await RunnerStateOwner.acquire({ stateDirectory: config.stateDirectory });
340
346
  try {
341
- const executor = new OciExecutor(config, stateOwner);
347
+ const executor = new MicroVmExecutor(config, stateOwner);
342
348
  // new ShipRunner(config, { stateOwner, executor, ... }).run(...)
343
349
  } finally {
344
350
  await stateOwner.release();
@@ -354,18 +360,10 @@ pnpm test
354
360
  pnpm pack --dry-run
355
361
  ```
356
362
 
357
- `pnpm test` builds first: the tests take real state ownership with the host helper in `dist_rust/`.
358
- The real Docker integration is opt-in and requires a locally available digest-pinned Linux image:
359
-
360
- ```sh
361
- SHIP_RUNNER_OCI_TEST=1 \
362
- SHIP_RUNNER_OCI_IMAGE='alpine@sha256:<digest>' \
363
- pnpm exec tstest test/test.oci-executor.node.ts --verbose
364
- ```
365
-
366
- It verifies direct execution of an imported workspace file, shared multi-step state, helper
367
- ownership, selected export, hardlink rejection, inode exhaustion, and container/volume cleanup
368
- against the real runtime.
363
+ `pnpm test` builds first: the tests take real state ownership with the host helper in `dist_rust/`,
364
+ run the TypeScript unit/E2E suites (`test/test.*.node.ts`, including Firecracker microVM, OCI
365
+ registry, egress allowlist proxy, and dedicated `oci-image` builder tests), and run `cargo test`
366
+ for the static Rust `runnerworkspace` helper and guest PID 1 agent.
369
367
 
370
368
  ## License and Legal Information
371
369
 
package/rust/Cargo.lock CHANGED
@@ -88,6 +88,7 @@ dependencies = [
88
88
  name = "runnerworkspace"
89
89
  version = "0.1.0"
90
90
  dependencies = [
91
+ "libc",
91
92
  "nix",
92
93
  "serde",
93
94
  "serde_json",
package/rust/Cargo.toml CHANGED
@@ -6,9 +6,10 @@ license = "MIT"
6
6
  publish = false
7
7
 
8
8
  [dependencies]
9
+ libc = "0.2.189"
9
10
  nix = { version = "0.30.1", default-features = false, features = ["fs", "process", "signal", "user"] }
10
11
  serde = { version = "1.0.229", features = ["derive"] }
11
- serde_json = "1.0.149"
12
+ serde_json = { version = "1.0.149" }
12
13
 
13
14
  [target.'cfg(not(target_env = "msvc"))'.dependencies]
14
15
  tikv-jemallocator = { version = "0.7.0", features = ["background_threads"] }
@@ -0,0 +1,147 @@
1
+ use crate::Error;
2
+ use std::fs::{self, OpenOptions};
3
+ use std::io::{self, Write};
4
+ use std::os::unix::fs::OpenOptionsExt;
5
+ use std::path::Path;
6
+
7
+ const NEWC_MAGIC: &[u8; 6] = b"070701";
8
+ const MAXIMUM_INITRD_BINARY_BYTES: u64 = 64 * 1024 * 1024;
9
+
10
+ fn align4(len: usize) -> usize {
11
+ (4 - (len % 4)) % 4
12
+ }
13
+
14
+ fn write_newc_entry<W: Write>(
15
+ writer: &mut W,
16
+ ino: u32,
17
+ mode: u32,
18
+ nlink: u32,
19
+ name: &str,
20
+ data: &[u8],
21
+ ) -> io::Result<()> {
22
+ let name_bytes = name.as_bytes();
23
+ let namesize = name_bytes.len() + 1;
24
+ let filesize = data.len();
25
+ let header = format!(
26
+ "{}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}{:08x}",
27
+ std::str::from_utf8(NEWC_MAGIC).unwrap_or("070701"),
28
+ ino,
29
+ mode,
30
+ 0u32, // uid
31
+ 0u32, // gid
32
+ nlink,
33
+ 0u32, // mtime (deterministic)
34
+ filesize as u32,
35
+ 0u32, // devmajor
36
+ 0u32, // devminor
37
+ 0u32, // rdevmajor
38
+ 0u32, // rdevminor
39
+ namesize as u32,
40
+ 0u32, // check
41
+ );
42
+ writer.write_all(header.as_bytes())?;
43
+ writer.write_all(name_bytes)?;
44
+ writer.write_all(&[0u8])?;
45
+ let header_pad = align4(110 + namesize);
46
+ if header_pad > 0 {
47
+ writer.write_all(&[0u8; 4][..header_pad])?;
48
+ }
49
+ if !data.is_empty() {
50
+ writer.write_all(data)?;
51
+ let data_pad = align4(filesize);
52
+ if data_pad > 0 {
53
+ writer.write_all(&[0u8; 4][..data_pad])?;
54
+ }
55
+ }
56
+ Ok(())
57
+ }
58
+
59
+ /// Builds a deterministic Linux `newc` CPIO initramfs containing `/init` (the static guest binary)
60
+ /// and the minimal mountpoint directories required during Firecracker guest boot.
61
+ pub fn build_initrd(binary_path: &Path, output_path: &Path) -> Result<u64, Error> {
62
+ if !binary_path.is_absolute() || !output_path.is_absolute() {
63
+ return Err(Error::new("initrd paths must be absolute"));
64
+ }
65
+ let metadata = fs::symlink_metadata(binary_path)
66
+ .map_err(|_| Error::new("unable to inspect guest binary for initrd"))?;
67
+ if !metadata.file_type().is_file() {
68
+ return Err(Error::new("guest binary must be a regular file"));
69
+ }
70
+ if metadata.len() == 0 || metadata.len() > MAXIMUM_INITRD_BINARY_BYTES {
71
+ return Err(Error::new("guest binary size is out of bounds"));
72
+ }
73
+ let binary_bytes =
74
+ fs::read(binary_path).map_err(|_| Error::new("unable to read guest binary for initrd"))?;
75
+
76
+ let mut buffer = Vec::with_capacity(binary_bytes.len() + 4096);
77
+ let dirs = [
78
+ "dev",
79
+ "proc",
80
+ "sys",
81
+ "tmp",
82
+ "workspace",
83
+ "oci-rootfs",
84
+ "run",
85
+ "mnt",
86
+ ];
87
+ let mut ino: u32 = 1;
88
+ for dir in dirs {
89
+ write_newc_entry(&mut buffer, ino, 0o040755, 2, dir, &[])
90
+ .map_err(|_| Error::new("unable to write initrd directory entry"))?;
91
+ ino += 1;
92
+ }
93
+ write_newc_entry(&mut buffer, ino, 0o100755, 1, "init", &binary_bytes)
94
+ .map_err(|_| Error::new("unable to write initrd /init entry"))?;
95
+ write_newc_entry(&mut buffer, 0, 0, 1, "TRAILER!!!", &[])
96
+ .map_err(|_| Error::new("unable to write initrd trailer"))?;
97
+
98
+ // Pad to 512-byte boundary for clean initrd loading.
99
+ let rem = buffer.len() % 512;
100
+ if rem != 0 {
101
+ buffer.resize(buffer.len() + (512 - rem), 0);
102
+ }
103
+
104
+ let mut out = OpenOptions::new()
105
+ .write(true)
106
+ .create(true)
107
+ .truncate(true)
108
+ .mode(0o600)
109
+ .open(output_path)
110
+ .map_err(|_| Error::new("unable to create initrd output file"))?;
111
+ out.write_all(&buffer)
112
+ .map_err(|_| Error::new("unable to write initrd output file"))?;
113
+ out.sync_all()
114
+ .map_err(|_| Error::new("unable to sync initrd output file"))?;
115
+ Ok(buffer.len() as u64)
116
+ }
117
+
118
+ #[cfg(test)]
119
+ mod tests {
120
+ use super::*;
121
+
122
+ #[test]
123
+ fn builds_deterministic_newc_initrd() {
124
+ let dir = std::env::temp_dir().join(format!(
125
+ "runnerworkspace-cpio-test-{}",
126
+ std::process::id()
127
+ ));
128
+ let _ = fs::remove_dir_all(&dir);
129
+ fs::create_dir_all(&dir).unwrap();
130
+ let bin = dir.join("fake-init");
131
+ let out1 = dir.join("initrd1.cpio");
132
+ let out2 = dir.join("initrd2.cpio");
133
+ fs::write(&bin, b"#!/bin/sh\necho hi\n").unwrap();
134
+
135
+ let size1 = build_initrd(&bin, &out1).unwrap();
136
+ let size2 = build_initrd(&bin, &out2).unwrap();
137
+ assert_eq!(size1, size2);
138
+ let bytes1 = fs::read(&out1).unwrap();
139
+ let bytes2 = fs::read(&out2).unwrap();
140
+ assert_eq!(bytes1, bytes2);
141
+ assert!(bytes1.starts_with(b"070701"));
142
+ assert!(bytes1.windows(10).any(|w| w == b"TRAILER!!!"));
143
+ assert_eq!(bytes1.len() % 512, 0);
144
+
145
+ let _ = fs::remove_dir_all(&dir);
146
+ }
147
+ }