Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat: ship signed Lima in macOS builds

ogsamratf4ca4c78257b
diff --git a/apps/desktop/build/entitlements.lima.plist b/apps/desktop/build/entitlements.lima.plist
new file mode 100644
index 00000000..a7fb08be
--- /dev/null
+++ b/apps/desktop/build/entitlements.lima.plist
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.security.virtualization</key>
+ <true/>
+</dict>
+</plist>
diff --git a/apps/desktop/electron-builder.base.yml b/apps/desktop/electron-builder.base.yml
index c6adbb97..7cc50b4c 100644
--- a/apps/desktop/electron-builder.base.yml
+++ b/apps/desktop/electron-builder.base.yml
@@ -63,6 +63,11 @@ mac:
notarize: false
entitlements: build/entitlements.mac.plist
entitlementsInherit: build/entitlements.mac.plist
+ # The OmniRush VM's limactl is signed on its own (scripts/sign-lima.cjs, from afterPack):
+ # Developer ID, hardened runtime and build/entitlements.lima.plist (com.apple.security.virtualization,
+ # which Apple's Virtualization.framework requires). The inherited entitlements would replace it.
+ signIgnore:
+ - /Contents/Resources/sidecars/lima/bin/limactl$
extendInfo:
NSMicrophoneUsageDescription: omnirush uses the microphone when you allow a page to access audio input.
extraResources:
@@ -76,6 +81,11 @@ mac:
- versions.json-x86_64-apple-darwin
- box/darwin-*/boxsh
- box/linux-*/boxd
+ # The OmniRush VM (backends/lima.ts): boxrun runs boxes inside it; Lima runs the VM.
+ - box/linux-*/boxrun
+ - lima/bin/limactl
+ - lima/share/lima/lima-guestagent.Linux-*.gz
+ - lima/LICENSE
- from: resources/helpers
to: helpers
filter:
diff --git a/apps/desktop/electron/lima-packaging.test.mjs b/apps/desktop/electron/lima-packaging.test.mjs
new file mode 100644
index 00000000..74f8890a
--- /dev/null
+++ b/apps/desktop/electron/lima-packaging.test.mjs
@@ -0,0 +1,132 @@
+// The OmniRush VM in the macOS build: the linux boxrun and Lima ship in sidecars
+// (electron-builder.base.yml), limactl is left out of electron-builder's signing
+// (signIgnore) and signed on its own with the virtualization entitlement, the
+// hardened runtime and the Developer ID (scripts/sign-lima.cjs, from afterPack),
+// checked again in afterSign. No signed build runs here: the codesign calls are
+// recorded and their arguments checked.
+import assert from "node:assert/strict";
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { createRequire } from "node:module";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import { describe, it } from "node:test";
+import { fileURLToPath } from "node:url";
+import YAML from "yaml";
+
+const require = createRequire(import.meta.url);
+const dirname = path.dirname(fileURLToPath(import.meta.url));
+const desktop = path.resolve(dirname, "..");
+const sign = require("../scripts/sign-lima.cjs");
+
+const config = () => YAML.parse(readFileSync(path.join(desktop, "electron-builder.base.yml"), "utf8"));
+const DEV_ID = " 1) 0123456789ABCDEF0123456789ABCDEF01234567 \"Developer ID Application: Example (2KFG4BXC8K)\"\n 1 valid identities found\n";
+
+function fakeApp() {
+ const root = mkdtempSync(path.join(tmpdir(), "lima-app-"));
+ const app = path.join(root, "omnirush.app");
+ const limactl = sign.limactlPath(app);
+ mkdirSync(path.dirname(limactl), { recursive: true });
+ writeFileSync(limactl, "limactl");
+ return { root, app, limactl };
+}
+
+function recorder(answers = {}) {
+ const calls = [];
+ const run = (command, args) => {
+ calls.push([command, ...args]);
+ const key = `${command} ${args[0]}`;
+ const answer = typeof answers[key] === "function" ? answers[key](args) : answers[key];
+ return { status: 0, stdout: "", stderr: "", ...(answer ?? {}) };
+ };
+ return { calls, run };
+}
+
+describe("macOS build: the OmniRush VM ships", () => {
+ it("the sidecars hold the linux boxrun, limactl, the Linux guest agent and Lima's licence", () => {
+ const sidecars = config().mac.extraResources.find((resource) => resource.to === "sidecars");
+ for (const entry of ["box/darwin-*/boxsh", "box/linux-*/boxd", "box/linux-*/boxrun", "lima/bin/limactl", "lima/share/lima/lima-guestagent.Linux-*.gz", "lima/LICENSE"]) {
+ assert.ok(sidecars.filter.includes(entry), `${entry} is not packaged`);
+ }
+ assert.ok(!sidecars.filter.some((entry) => /Darwin|libexec|templates/.test(entry)), "nothing else of the Lima release ships");
+ });
+
+ it("limactl alone is left out of electron-builder's signing (the inherited entitlements would replace its own)", () => {
+ const { mac } = config();
+ assert.equal(mac.hardenedRuntime, true);
+ const ignore = mac.signIgnore.map((pattern) => new RegExp(pattern));
+ const res = "/x/dist-electron/mac-arm64/omnirush.app/Contents/Resources";
+ assert.ok(ignore.some((re) => re.test(`${res}/sidecars/lima/bin/limactl`)));
+ for (const other of [`${res}/sidecars/opencode-aarch64-apple-darwin`, `${res}/sidecars/box/darwin-arm64/boxsh`, `${res}/sidecars/lima/share/lima/lima-guestagent.Linux-aarch64.gz`, `${res}/../MacOS/omnirush`, `${res}/sidecars/lima/bin/limactl.bak`]) {
+ assert.ok(!ignore.some((re) => re.test(other)), `${other} must still be signed by electron-builder`);
+ }
+ });
+
+ it("limactl's entitlements are exactly Apple's virtualization one; the app's own entitlements are unchanged", () => {
+ const lima = readFileSync(path.join(desktop, "build", "entitlements.lima.plist"), "utf8");
+ assert.deepEqual([...lima.matchAll(/<key>([^<]+)<\/key>/g)].map((m) => m[1]), ["com.apple.security.virtualization"]);
+ const app = readFileSync(path.join(desktop, "build", "entitlements.mac.plist"), "utf8");
+ assert.ok(!app.includes("com.apple.security.virtualization"), "the app and its other binaries do not get it");
+ });
+});
+
+describe("sign-lima.cjs", () => {
+ it("identity: a named one, else the Developer ID in MACOS_SIGNING_KEYCHAIN (CI), else one electron-builder would find, else ad hoc", () => {
+ const { run } = recorder({ "security find-identity": { stdout: DEV_ID } });
+ assert.deepEqual(sign.limaIdentity({ env: { CSC_NAME: "Example (2KFG4BXC8K)", MACOS_SIGNING_KEYCHAIN: "/k" }, run }), { identity: "Example (2KFG4BXC8K)", keychain: "/k" });
+ assert.deepEqual(sign.limaIdentity({ env: { MACOS_SIGNING_KEYCHAIN: "/k" }, run }), { identity: "0123456789ABCDEF0123456789ABCDEF01234567", keychain: "/k" });
+ assert.deepEqual(sign.limaIdentity({ env: {}, run }), { identity: "0123456789ABCDEF0123456789ABCDEF01234567", keychain: null });
+ assert.deepEqual(sign.limaIdentity({ env: { CSC_IDENTITY_AUTO_DISCOVERY: "false" }, run }), { identity: "-", keychain: null });
+ assert.equal(sign.developerIdHash(" 1) ABCDEF0123456789ABCDEF0123456789ABCDEF01 \"Apple Development: x\""), null);
+ });
+
+ it("afterPack: limactl signed with the virtualization entitlement, the hardened runtime and a timestamp; a notarized build never ad hoc", (t) => {
+ const { root, app, limactl } = fakeApp();
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const { calls, run } = recorder({ "security find-identity": { stdout: DEV_ID } });
+ const signed = sign.signLimactl(app, { env: { MACOS_SIGNING_KEYCHAIN: "/k", MACOS_NOTARIZE: "true" }, run, log: () => {} });
+ assert.equal(signed.signed, true);
+ const codesign = calls.find((c) => c[0] === "codesign");
+ assert.deepEqual(codesign, ["codesign", "--force", "--sign", "0123456789ABCDEF0123456789ABCDEF01234567", "--options", "runtime", "--timestamp", "--keychain", "/k", "--entitlements", sign.LIMA_ENTITLEMENTS, limactl]);
+ assert.throws(() => sign.signLimactl(app, { env: { MACOS_NOTARIZE: "true", CSC_IDENTITY_AUTO_DISCOVERY: "false" }, run: recorder().run, log: () => {} }), /no Developer ID identity/);
+ const adHoc = recorder();
+ sign.signLimactl(app, { env: { CSC_IDENTITY_AUTO_DISCOVERY: "false" }, run: adHoc.run, log: () => {} });
+ assert.deepEqual(adHoc.calls[0].slice(1, 7), ["--force", "--sign", "-", "--options", "runtime", "--timestamp=none"]);
+ assert.deepEqual(sign.signLimactl(path.join(root, "none.app"), { run: recorder().run }), { signed: false, reason: "no bundled limactl" });
+ });
+
+ it("afterSign (no Developer ID): after the deep ad-hoc signature limactl gets its entitlement back, then the app is sealed again, not deep", (t) => {
+ const { root, app, limactl } = fakeApp();
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const { calls, run } = recorder();
+ assert.equal(sign.resignLimaAdHoc(app, { run }), true);
+ assert.equal(calls[0].at(-1), limactl);
+ assert.ok(calls[0].includes(sign.LIMA_ENTITLEMENTS));
+ assert.equal(calls[1].at(-1), app);
+ assert.ok(!calls[1].includes("--deep"), "every other signature stays");
+ });
+
+ it("verify: the entitlement and the hardened runtime always; Developer ID and a timestamp when notarized", (t) => {
+ const { root, app } = fakeApp();
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const good = {
+ "codesign -d": { stdout: "<plist><dict><key>com.apple.security.virtualization</key><true/></dict></plist>" },
+ "codesign -dv": { stderr: "Authority=Developer ID Application: Example (2KFG4BXC8K)\nTimestamp=22 Oct 2026\nCodeDirectory v=20500 size=1 flags=0x10000(runtime) hashes=1\n" },
+ };
+ assert.deepEqual(sign.verifyLimactl(app, { requireDeveloperId: true, run: recorder(good).run }), { present: true });
+ assert.throws(() => sign.verifyLimactl(app, { run: recorder({ ...good, "codesign -d": { stdout: "<plist/>" } }).run }), /com\.apple\.security\.virtualization/);
+ assert.throws(() => sign.verifyLimactl(app, { run: recorder({ ...good, "codesign -dv": { stderr: "CodeDirectory v=20500 flags=0x2(adhoc)\n" } }).run }), /hardened runtime/);
+ const adHoc = { ...good, "codesign -dv": { stderr: "Signature=adhoc\nCodeDirectory v=20500 flags=0x10002(adhoc,runtime)\n" } };
+ assert.deepEqual(sign.verifyLimactl(app, { run: recorder(adHoc).run }), { present: true });
+ assert.throws(() => sign.verifyLimactl(app, { requireDeveloperId: true, run: recorder(adHoc).run }), /not Developer ID signed/);
+ assert.deepEqual(sign.verifyLimactl(path.join(root, "none.app"), { run: recorder().run }), { present: false });
+ });
+
+ it("the hooks: afterPack signs limactl before electron-builder signs the app; afterSign re-signs it after an ad-hoc deep signature and checks it", () => {
+ const pack = readFileSync(path.join(desktop, "scripts", "electron-after-pack.cjs"), "utf8");
+ const body = pack.slice(pack.indexOf("async function afterPack"));
+ assert.ok(body.indexOf("signLimactl(") > 0 && body.indexOf("signLimactl(") < body.indexOf("targetTriple("), "signed for every darwin pack, before anything can return early");
+ const after = readFileSync(path.join(desktop, "scripts", "electron-after-sign.cjs"), "utf8");
+ assert.match(after, /if \(adHocSignIfUnsigned\(appPath\)\) resignLimaAdHoc\(appPath\);/);
+ assert.ok(after.indexOf("verifyLimactl(") < after.indexOf("notarizeFile("), "checked before notarization");
+ });
+});
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 13d25592..eceed3b5 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -27,7 +27,7 @@
"prepare:sidecar": "node ./scripts/prepare-sidecar.mjs",
"pretest": "pnpm --filter @omnirush/headless-threads build",
"test:omnirush-account": "node --test electron/omnirush-account.test.mjs",
- "test": "node --test scripts/prepare-server-constants.test.mjs scripts/prepare-box-helpers.test.mjs scripts/verify-update-manifest.test.mjs electron/after-pack-paths.test.mjs electron/agent-context-diagnostics-fetch.test.mjs electron/automation-runner.test.mjs electron/binary-transfer.test.mjs electron/blank-slate-profile.test.mjs electron/blank-slate-profile-isolation.test.mjs electron/brand-app-name.test.mjs electron/brand-icon-darwin.test.mjs electron/brand-icon-windows.test.mjs electron/browser-login-sync.test.mjs electron/browser-panel.test.mjs electron/browser-task.test.mjs electron/background-rendering.test.mjs electron/connect-link.test.mjs electron/desktop-distribution.test.mjs electron/dev-profile.test.mjs electron/electron-builder-config.test.mjs electron/linux-desktop-integration.test.mjs electron/linux-password-store.test.mjs electron/logs-folder.test.mjs electron/media-permissions.test.mjs electron/no-bare-external-fetch.test.mjs electron/nuke.test.mjs electron/omnirush-account.test.mjs electron/omnirush-ui-mcp.test.mjs electron/open-external.test.mjs electron/open-local-path.test.mjs electron/process-resilience.test.mjs electron/runtime.test.mjs electron/runtime-ca.test.mjs electron/system-ca-trust.test.mjs electron/external-fetch.test.mjs electron/runtime-chain-repair.test.mjs electron/sentry.test.mjs electron/server-dependency-mirror.test.mjs electron/skill-folder.test.mjs electron/secure-vault-key.test.mjs electron/stdio-errors.test.mjs electron/terminal-sessions.test.mjs electron/ui-control-server.test.mjs electron/updater.test.mjs electron/update-gate.test.mjs electron/window-size.test.mjs electron/quality.test.mjs electron/buildathon.test.mjs electron/build-variant.test.mjs electron/placements-desktop.test.mjs electron/feedback-desktop.test.mjs electron/turn-guard.test.mjs electron/keep-awake.test.mjs electron/computer-use-answers.test.mjs electron/computer-use-agent-browser.test.mjs electron/remote-workspace.test.mjs electron/workspace-archive.test.mjs electron/workspace-store.test.mjs electron/start-report.test.mjs electron/start-reset.test.mjs electron/start-store-check.test.mjs electron/app-request-secret.test.mjs electron/disk-cleanup.test.mjs",
+ "test": "node --test scripts/prepare-server-constants.test.mjs scripts/prepare-box-helpers.test.mjs scripts/verify-update-manifest.test.mjs electron/after-pack-paths.test.mjs electron/agent-context-diagnostics-fetch.test.mjs electron/automation-runner.test.mjs electron/binary-transfer.test.mjs electron/blank-slate-profile.test.mjs electron/blank-slate-profile-isolation.test.mjs electron/brand-app-name.test.mjs electron/brand-icon-darwin.test.mjs electron/brand-icon-windows.test.mjs electron/browser-login-sync.test.mjs electron/browser-panel.test.mjs electron/browser-task.test.mjs electron/background-rendering.test.mjs electron/connect-link.test.mjs electron/desktop-distribution.test.mjs electron/dev-profile.test.mjs electron/electron-builder-config.test.mjs electron/linux-desktop-integration.test.mjs electron/linux-password-store.test.mjs electron/logs-folder.test.mjs electron/media-permissions.test.mjs electron/no-bare-external-fetch.test.mjs electron/nuke.test.mjs electron/omnirush-account.test.mjs electron/omnirush-ui-mcp.test.mjs electron/open-external.test.mjs electron/open-local-path.test.mjs electron/process-resilience.test.mjs electron/runtime.test.mjs electron/runtime-ca.test.mjs electron/system-ca-trust.test.mjs electron/external-fetch.test.mjs electron/runtime-chain-repair.test.mjs electron/sentry.test.mjs electron/server-dependency-mirror.test.mjs electron/skill-folder.test.mjs electron/secure-vault-key.test.mjs electron/stdio-errors.test.mjs electron/terminal-sessions.test.mjs electron/ui-control-server.test.mjs electron/updater.test.mjs electron/update-gate.test.mjs electron/window-size.test.mjs electron/quality.test.mjs electron/buildathon.test.mjs electron/build-variant.test.mjs electron/placements-desktop.test.mjs electron/feedback-desktop.test.mjs electron/turn-guard.test.mjs electron/keep-awake.test.mjs electron/computer-use-answers.test.mjs electron/computer-use-agent-browser.test.mjs electron/remote-workspace.test.mjs electron/workspace-archive.test.mjs electron/workspace-store.test.mjs electron/start-report.test.mjs electron/start-reset.test.mjs electron/start-store-check.test.mjs electron/app-request-secret.test.mjs electron/disk-cleanup.test.mjs electron/lima-packaging.test.mjs",
"test:core": "node --test scripts/prepare-server-constants.test.mjs electron/workspace-store.test.mjs electron/workspace-archive.test.mjs electron/connect-link.test.mjs electron/open-external.test.mjs electron/open-local-path.test.mjs electron/secure-vault-key.test.mjs electron/process-resilience.test.mjs electron/stdio-errors.test.mjs electron/runtime-ca.test.mjs electron/system-ca-trust.test.mjs electron/external-fetch.test.mjs electron/runtime-chain-repair.test.mjs electron/automation-runner.test.mjs",
"pretest:core": "pnpm --filter @omnirush/headless-threads build"
},
diff --git a/apps/desktop/scripts/electron-after-pack.cjs b/apps/desktop/scripts/electron-after-pack.cjs
index 00d5c489..bd252dc5 100644
--- a/apps/desktop/scripts/electron-after-pack.cjs
+++ b/apps/desktop/scripts/electron-after-pack.cjs
@@ -3,6 +3,7 @@ const path = require("node:path");
const { spawnSync } = require("node:child_process");
const asar = require("@electron/asar");
const { verifyBundledUiMcp } = require("./ui-mcp-bundle.cjs");
+const { signLimactl } = require("./sign-lima.cjs");
const computerUseHelperAppName = "OmniRush.ai Computer Use.app";
@@ -143,6 +144,11 @@ function signComputerUseHelper(context) {
async function afterPack(context) {
verifyRuntimeDependencies(context);
verifyUiControlMcpBundle(context);
+ // The OmniRush VM's limactl: its own signature (virtualization entitlement), before the app is signed around it.
+ if (context.electronPlatformName === "darwin") {
+ const appPath = resolveMacAppPath(context);
+ if (appPath) signLimactl(appPath);
+ }
const triple = targetTriple(context.electronPlatformName, context.arch);
if (!triple) return;
diff --git a/apps/desktop/scripts/electron-after-sign.cjs b/apps/desktop/scripts/electron-after-sign.cjs
index e9a7c206..e4c2a46c 100644
--- a/apps/desktop/scripts/electron-after-sign.cjs
+++ b/apps/desktop/scripts/electron-after-sign.cjs
@@ -1,6 +1,7 @@
const { spawnSync } = require("node:child_process");
const { existsSync, mkdtempSync, rmSync } = require("node:fs");
const { notaryCredentials, notarizeFile, runWithRetry, staple } = require("./macos-notarize.cjs");
+const { resignLimaAdHoc, verifyLimactl } = require("./sign-lima.cjs");
const { tmpdir } = require("node:os");
const path = require("node:path");
@@ -63,7 +64,10 @@ async function afterSign(context) {
const appName = `${context.packager.appInfo.productFilename}.app`;
const appPath = path.join(context.appOutDir, appName);
- adHocSignIfUnsigned(appPath);
+ // The deep ad-hoc signature replaces limactl's own: it gets its entitlement back and the app is sealed again.
+ if (adHocSignIfUnsigned(appPath)) resignLimaAdHoc(appPath);
+ // The bundled limactl as it ships: the virtualization entitlement, the hardened runtime (Developer ID when notarized).
+ verifyLimactl(appPath, { requireDeveloperId: process.env.MACOS_NOTARIZE === "true" });
if (process.env.MACOS_NOTARIZE !== "true") {
console.warn("[electron-after-sign] MACOS_NOTARIZE is not true; skipping notarization.");
diff --git a/apps/desktop/scripts/prepare-box-helpers.mjs b/apps/desktop/scripts/prepare-box-helpers.mjs
index 7a1ec9d0..8d780d06 100644
--- a/apps/desktop/scripts/prepare-box-helpers.mjs
+++ b/apps/desktop/scripts/prepare-box-helpers.mjs
@@ -2,9 +2,10 @@
// The Linux sandbox's helpers (apps/server/src/box), next to the engine in
// the sidecars folder: box/<goos>-<goarch>/boxsh[.exe] (the shell the engine
// runs its shell tool with), box/linux-<arch>/boxd (run inside each
-// project's box) and, for Linux and Windows builds, box/linux-<arch>/boxrun
-// (the bubblewrap backend on Linux; copied into the OmniRush WSL distro on
-// Windows). Built from box/go, a copy of the CLI's box/go (omnirush-cli
+// project's box) and box/linux-<arch>/boxrun (the bubblewrap backend on
+// Linux; copied into the OmniRush WSL distro on Windows and into the OmniRush
+// VM on macOS). macOS builds also ship the VM's Lima (prepare-lima.mjs:
+// sidecars/lima, the pinned release, sha256-checked). Built from box/go, a copy of the CLI's box/go (omnirush-cli
// feat/local-box-backends), with Go >= 1.22 (GO=/path/to/go), or copied from
// OMNIRUSH_BOX_PREBUILT_DIR (a folder with the same layout). Linux builds also
// ship box/linux-<arch>/bwrap: the static bubblewrap the CLI ships (box/bwrap,
@@ -22,6 +23,8 @@ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync } from "no
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
+import { prepareLima } from "./prepare-lima.mjs";
+
const here = dirname(fileURLToPath(import.meta.url));
const source = resolve(here, "..", "box", "go");
// The same folder prepare-sidecar.mjs fills (OMNIRUSH_SIDECAR_DIR or --outdir).
@@ -58,8 +61,9 @@ const { goos, goarch } = target();
const files = [
{ cmd: "boxsh", goos, goarch, name: goos === "windows" ? "boxsh.exe" : "boxsh" },
{ cmd: "boxd", goos: "linux", goarch, name: "boxd" },
- // The bubblewrap backend (Linux) and the OmniRush WSL distro's runner (Windows copies it in).
- ...(goos === "linux" || goos === "windows" ? [{ cmd: "boxrun", goos: "linux", goarch, name: "boxrun", optional: true }] : []),
+ // The bubblewrap backend (Linux), the OmniRush WSL distro's runner (Windows copies it in) and the
+ // OmniRush VM's (macOS copies it in).
+ { cmd: "boxrun", goos: "linux", goarch, name: "boxrun", optional: true },
];
const go = process.env.GO?.trim() || "go";
@@ -81,7 +85,7 @@ for (const file of files) {
} else if (prebuilt && existsSync(join(prebuilt, `${file.goos}-${file.goarch}`, file.name))) {
copyFileSync(join(prebuilt, `${file.goos}-${file.goarch}`, file.name), dest);
} else {
- if (file.optional) console.warn(`Sandbox helper linux-${file.goarch}/${file.name} missing: the bubblewrap / WSL distro backends are unavailable in this build.`);
+ if (file.optional) console.warn(`Sandbox helper linux-${file.goarch}/${file.name} missing: the bubblewrap / WSL distro / VM backends are unavailable in this build.`);
else missing += 1;
continue;
}
@@ -111,3 +115,8 @@ if (goos === "linux") {
console.log(`Sandbox helper linux-${goarch}/bwrap ready${fromPrebuilt ? " (prebuilt)" : ""}.`);
}
if (missing) console.warn("Sandbox helpers missing (no Go and no OMNIRUSH_BOX_PREBUILT_DIR): the Linux sandbox will report itself unavailable.");
+// macOS: the OmniRush VM's Lima (bin/limactl, the Linux guest agent, its licence) in sidecars/lima.
+if (goos === "darwin") {
+ const lima = await prepareLima({ goos, goarch, out: sidecarDir });
+ console.log(lima.ok ? `Sandbox VM Lima ${lima.version} ready (${lima.source}).` : `Sandbox VM Lima not bundled (${lima.reason}): the app downloads the pinned release on first use.`);
+}
diff --git a/apps/desktop/scripts/prepare-box-helpers.test.mjs b/apps/desktop/scripts/prepare-box-helpers.test.mjs
index 407d6a0c..a53d296d 100644
--- a/apps/desktop/scripts/prepare-box-helpers.test.mjs
+++ b/apps/desktop/scripts/prepare-box-helpers.test.mjs
@@ -1,12 +1,14 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
-import { mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
+import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
+import { limaFiles, limaPin, prepareLima } from "./prepare-lima.mjs";
+
const here = dirname(fileURLToPath(import.meta.url));
const script = join(here, "prepare-box-helpers.mjs");
const vendored = resolve(here, "..", "box", "bwrap");
@@ -35,7 +37,7 @@ test("macOS and Windows builds ship no bubblewrap", (t) => {
const out = mkdtempSync(join(tmpdir(), "omnirush-box-helpers-"));
t.after(() => rmSync(out, { recursive: true, force: true }));
for (const triple of ["aarch64-apple-darwin", "x86_64-pc-windows-msvc"]) {
- const res = spawnSync(process.execPath, [script, "--outdir", out], { env: { ...process.env, GO: "/nonexistent/go", TAURI_ENV_TARGET_TRIPLE: triple, OMNIRUSH_BOX_PREBUILT_DIR: "" }, encoding: "utf8" });
+ const res = spawnSync(process.execPath, [script, "--outdir", out], { env: { ...process.env, GO: "/nonexistent/go", TAURI_ENV_TARGET_TRIPLE: triple, OMNIRUSH_BOX_PREBUILT_DIR: "", OMNIRUSH_LIMA: "0" }, encoding: "utf8" });
assert.equal(res.status, 0, res.stderr);
}
assert.throws(() => statSync(join(out, "box", "linux-arm64", "bwrap")));
@@ -45,3 +47,53 @@ test("macOS and Windows builds ship no bubblewrap", (t) => {
test("the vendored files are the ones SHA256SUMS pins (the CLI's box/bwrap, byte for byte)", () => {
for (const [name, digest] of Object.entries(sums())) assert.equal(sha(join(vendored, name)), digest, name);
});
+
+// --- the OmniRush VM's Lima (macOS builds) ---------------------------------------------
+
+/** A Lima release tree like the real one (bin, libexec, share/lima with both guest agents and templates, share/doc). */
+function limaTree() {
+ const dir = mkdtempSync(join(tmpdir(), "omnirush-lima-tree-"));
+ for (const f of ["bin/limactl", "bin/lima", "libexec/lima/lima-driver-qemu", "share/lima/lima-guestagent.Linux-aarch64.gz", "share/lima/lima-guestagent.Linux-x86_64.gz", "share/lima/lima-guestagent.Darwin-aarch64.gz", "share/lima/templates/default.yaml", "share/doc/lima/LICENSE"]) {
+ mkdirSync(dirname(join(dir, f)), { recursive: true });
+ writeFileSync(join(dir, f), f);
+ }
+ return dir;
+}
+
+test("the Lima pin comes from the shared rules (apps/server/src/box/required.json), per arch", () => {
+ const rules = JSON.parse(readFileSync(resolve(here, "..", "..", "server", "src", "box", "required.json"), "utf8"));
+ assert.deepEqual(limaPin("arm64"), { version: rules.setup.darwin.lima.version, url: rules.setup.darwin.lima.assets.arm64.url, sha256: rules.setup.darwin.lima.assets.arm64.sha256, agent: "lima-guestagent.Linux-aarch64.gz" });
+ assert.equal(limaPin("amd64").agent, "lima-guestagent.Linux-x86_64.gz");
+ assert.deepEqual(limaFiles("a.gz").map(([from]) => from), ["bin/limactl", "share/lima/a.gz", "share/doc/lima/LICENSE"]);
+});
+
+test("a macOS build ships limactl, this arch's Linux guest agent and the licence, nothing else of the release; never on Linux/Windows", async (t) => {
+ const tree = limaTree();
+ const out = mkdtempSync(join(tmpdir(), "omnirush-lima-out-"));
+ t.after(() => { rmSync(tree, { recursive: true, force: true }); rmSync(out, { recursive: true, force: true }); });
+ const got = await prepareLima({ goos: "darwin", goarch: "arm64", out, env: { OMNIRUSH_LIMA_DIR: tree } });
+ assert.equal(got.ok, true);
+ const list = (d) => readdirSync(d, { recursive: true }).filter((f) => statSync(join(d, f)).isFile()).sort();
+ assert.deepEqual(list(join(out, "lima")), ["LICENSE", "bin/limactl", "share/lima/lima-guestagent.Linux-aarch64.gz"]);
+ assert.equal(statSync(join(out, "lima", "bin", "limactl")).mode & 0o111, 0o111);
+ assert.deepEqual(await prepareLima({ goos: "linux", goarch: "arm64", out, env: {} }), { ok: false, reason: "not a macOS build" });
+ assert.deepEqual(await prepareLima({ goos: "darwin", goarch: "arm64", out, env: { OMNIRUSH_LIMA: "0" } }), { ok: false, reason: "OMNIRUSH_LIMA=0" });
+});
+
+test("the release download is checked against the pinned sha256: a different file stops the build", async (t) => {
+ const tree = limaTree();
+ const out = mkdtempSync(join(tmpdir(), "omnirush-lima-out-"));
+ const tarball = join(mkdtempSync(join(tmpdir(), "omnirush-lima-tgz-")), "lima.tar.gz");
+ t.after(() => { for (const d of [tree, out, dirname(tarball)]) rmSync(d, { recursive: true, force: true }); });
+ spawnSync("tar", ["-czf", tarball, "-C", tree, "bin", "libexec", "share"]);
+ const body = readFileSync(tarball);
+ const sha256 = createHash("sha256").update(body).digest("hex");
+ const rules = { setup: { darwin: { lima: { version: "9.9.9", assets: { arm64: { url: "https://example.invalid/lima.tar.gz", sha256 } } } } } };
+ const asked = [];
+ const fetchImpl = async (url) => { asked.push(url); return new Response(body, { status: 200 }); };
+ assert.deepEqual(await prepareLima({ goos: "darwin", goarch: "arm64", out, env: {}, fetchImpl, rules }), { ok: true, source: "release", version: "9.9.9" });
+ assert.deepEqual(asked, ["https://example.invalid/lima.tar.gz"]);
+ assert.equal(readFileSync(join(out, "lima", "bin", "limactl"), "utf8"), "bin/limactl");
+ const wrong = { setup: { darwin: { lima: { version: "9.9.9", assets: { arm64: { url: "https://example.invalid/lima.tar.gz", sha256: "0".repeat(64) } } } } } };
+ await assert.rejects(prepareLima({ goos: "darwin", goarch: "arm64", out, env: {}, fetchImpl, rules: wrong }), /is not the pinned/);
+});
diff --git a/apps/desktop/scripts/prepare-lima.mjs b/apps/desktop/scripts/prepare-lima.mjs
new file mode 100644
index 00000000..30f3a5de
--- /dev/null
+++ b/apps/desktop/scripts/prepare-lima.mjs
@@ -0,0 +1,84 @@
+#!/usr/bin/env node
+// The OmniRush VM's Lima (macOS builds only), next to the engine in the sidecars
+// folder: lima/bin/limactl, lima/share/lima/lima-guestagent.Linux-<arch>.gz (the
+// guest agent for the VM, of this build's architecture) and lima/LICENSE
+// (Apache 2.0). The pinned release from the shared rules
+// (apps/server/src/box/required.json setup.darwin.lima: url + sha256 per
+// arch), downloaded and checked here, or a prepared tree from OMNIRUSH_LIMA_DIR
+// (the CLI's build reads the same variable). Nothing else of the release ships
+// (the vz driver is built into limactl). limactl is signed with the
+// virtualization entitlement at packaging (electron-after-pack.cjs, sign-lima.cjs).
+// OMNIRUSH_LIMA=0 skips it; without it the app downloads the same pinned
+// release on first use (backends/lima.ts).
+import { spawnSync } from "node:child_process";
+import { createHash } from "node:crypto";
+import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const here = dirname(fileURLToPath(import.meta.url));
+export const RULES = resolve(here, "..", "..", "server", "src", "box", "required.json");
+
+/** The pinned release for a Go arch: { version, url, sha256, agent } (agent: the guest agent's file name). */
+export function limaPin(goarch, rules = JSON.parse(readFileSync(RULES, "utf8"))) {
+ const lima = rules?.setup?.darwin?.lima;
+ const asset = lima?.assets?.[goarch === "arm64" ? "arm64" : "x64"];
+ if (!lima?.version || !asset?.url || !/^[0-9a-f]{64}$/.test(String(asset.sha256 || ""))) return null;
+ return { version: lima.version, url: asset.url, sha256: asset.sha256, agent: `lima-guestagent.Linux-${goarch === "arm64" ? "aarch64" : "x86_64"}.gz` };
+}
+
+/** The files that ship, from a release tree to sidecars/lima. */
+export function limaFiles(agent) {
+ return [["bin/limactl", "bin/limactl"], [`share/lima/${agent}`, `share/lima/${agent}`], ["share/doc/lima/LICENSE", "LICENSE"]];
+}
+
+async function download(url, dest, sha256, fetchImpl) {
+ const res = await fetchImpl(url, { redirect: "follow", headers: { "user-agent": "omnirush-build" } });
+ if (!res.ok) throw new Error(`Lima download: HTTP ${res.status} (${url})`);
+ const body = Buffer.from(await res.arrayBuffer());
+ const got = createHash("sha256").update(body).digest("hex");
+ if (got !== sha256) throw new Error(`Lima download: sha256 ${got} is not the pinned ${sha256}`);
+ writeFileSync(dest, body);
+}
+
+/**
+ * Put Lima under <out>/lima for a darwin build. Returns { ok, source, version }
+ * or { ok: false, reason } (skipped, not pinned); throws on a wrong download.
+ */
+export async function prepareLima({ goos, goarch, out, env = process.env, fetchImpl = globalThis.fetch, rules } = {}) {
+ if (goos !== "darwin") return { ok: false, reason: "not a macOS build" };
+ if (env.OMNIRUSH_LIMA === "0") return { ok: false, reason: "OMNIRUSH_LIMA=0" };
+ const pin = limaPin(goarch, rules);
+ if (!pin) return { ok: false, reason: "no Lima pinned for this arch" };
+ const dest = join(out, "lima");
+ rmSync(dest, { recursive: true, force: true });
+ let tree = String(env.OMNIRUSH_LIMA_DIR || "").trim() || null;
+ let tmp = null;
+ try {
+ if (!tree) {
+ tmp = mkdtempSync(join(tmpdir(), "omnirush-lima-"));
+ const tarball = join(tmp, "lima.tar.gz");
+ await download(pin.url, tarball, pin.sha256, fetchImpl);
+ tree = join(tmp, "tree");
+ mkdirSync(tree);
+ const res = spawnSync("tar", ["-xzf", tarball, "-C", tree], { stdio: "inherit" });
+ if (res.status !== 0) throw new Error("Lima download: could not unpack the release");
+ }
+ for (const [from, to] of limaFiles(pin.agent)) {
+ const src = join(tree, from);
+ if (!existsSync(src)) throw new Error(`Lima: ${from} is missing from ${env.OMNIRUSH_LIMA_DIR ? "OMNIRUSH_LIMA_DIR" : "the release"}`);
+ mkdirSync(dirname(join(dest, to)), { recursive: true });
+ copyFileSync(src, join(dest, to));
+ }
+ chmodSync(join(dest, "bin", "limactl"), 0o755);
+ } finally {
+ if (tmp) rmSync(tmp, { recursive: true, force: true });
+ }
+ return { ok: true, source: env.OMNIRUSH_LIMA_DIR ? "dir" : "release", version: pin.version };
+}
+
+if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ const [goos = "darwin", goarch = "arm64", out = resolve(here, "..", "resources", "sidecars")] = process.argv.slice(2);
+ prepareLima({ goos, goarch, out }).then((res) => console.log(res.ok ? `Lima ${res.version} ready (${res.source}).` : `Lima skipped: ${res.reason}.`), (error) => { console.error(error.message); process.exit(1); });
+}
diff --git a/apps/desktop/scripts/sign-lima.cjs b/apps/desktop/scripts/sign-lima.cjs
new file mode 100644
index 00000000..4d2ef467
--- /dev/null
+++ b/apps/desktop/scripts/sign-lima.cjs
@@ -0,0 +1,122 @@
+// The OmniRush VM's limactl (sidecars/lima/bin/limactl, prepare-lima.mjs) needs
+// Apple's virtualization entitlement (com.apple.security.virtualization) to run a
+// VM through Virtualization.framework. electron-builder signs every nested binary
+// with the one inherited entitlements file, so limactl is left out of its signing
+// (mac.signIgnore in electron-builder.base.yml) and signed here instead, from
+// afterPack (before electron-builder signs and seals the app around it): the same
+// Developer ID, the hardened runtime, a secure timestamp and
+// build/entitlements.lima.plist. An unsigned build gets an ad-hoc signature with
+// the entitlement (after afterSign's deep ad-hoc signature, limactl is signed again
+// and the app sealed again). Nothing hashes limactl before this runs: any stamp of
+// its bytes must come after signing.
+const { spawnSync } = require("node:child_process");
+const { existsSync } = require("node:fs");
+const path = require("node:path");
+
+const LIMACTL = ["Contents", "Resources", "sidecars", "lima", "bin", "limactl"];
+const ENTITLEMENT = "com.apple.security.virtualization";
+const LIMA_ENTITLEMENTS = path.join(__dirname, "..", "build", "entitlements.lima.plist");
+const APP_ENTITLEMENTS = path.join(__dirname, "..", "build", "entitlements.mac.plist");
+
+function defaultRun(command, args) {
+ const result = spawnSync(command, args, { encoding: "utf8" });
+ return { status: result.status ?? -1, stdout: result.stdout || "", stderr: result.stderr || "", error: result.error };
+}
+
+function limactlPath(appPath) {
+ return path.join(appPath, ...LIMACTL);
+}
+
+/** The Developer ID identity in `security find-identity -v -p codesigning` output: its SHA-1, or null. */
+function developerIdHash(output) {
+ for (const line of String(output || "").split("\n")) {
+ const match = /^\s*\d+\)\s+([0-9A-F]{40})\s+"Developer ID Application: /.exec(line);
+ if (match) return match[1];
+ }
+ return null;
+}
+
+/**
+ * Who signs limactl: OMNIRUSH_LIMA_CODESIGN_IDENTITY, CSC_NAME or
+ * APPLE_CODESIGN_IDENTITY; else the Developer ID in MACOS_SIGNING_KEYCHAIN (the
+ * release and the build-electron-desktop smoke import it there:
+ * scripts/release/macos-signing-env.sh); else one electron-builder would find
+ * itself (unless CSC_IDENTITY_AUTO_DISCOVERY=false); else ad hoc ("-").
+ * { identity, keychain }.
+ */
+function limaIdentity({ env = process.env, run = defaultRun } = {}) {
+ const keychain = String(env.MACOS_SIGNING_KEYCHAIN || "").trim() || null;
+ const named = [env.OMNIRUSH_LIMA_CODESIGN_IDENTITY, env.CSC_NAME, env.APPLE_CODESIGN_IDENTITY].map((v) => String(v || "").trim()).find(Boolean);
+ if (named) return { identity: named, keychain };
+ if (keychain) {
+ const hash = developerIdHash(run("security", ["find-identity", "-v", "-p", "codesigning", keychain]).stdout);
+ if (hash) return { identity: hash, keychain };
+ }
+ if (env.CSC_IDENTITY_AUTO_DISCOVERY !== "false") {
+ const hash = developerIdHash(run("security", ["find-identity", "-v", "-p", "codesigning"]).stdout);
+ if (hash) return { identity: hash, keychain: null };
+ }
+ return { identity: "-", keychain: null };
+}
+
+/** codesign's arguments for limactl: the hardened runtime and the virtualization entitlement; a timestamp unless ad hoc. */
+function limaCodesignArgs({ identity, keychain = null, file, entitlements = LIMA_ENTITLEMENTS }) {
+ return ["--force", "--sign", identity, "--options", "runtime", ...(identity === "-" ? ["--timestamp=none"] : ["--timestamp"]), ...(keychain ? ["--keychain", keychain] : []), "--entitlements", entitlements, file];
+}
+
+function must(res, what) {
+ if (res.error) throw res.error;
+ if (res.status !== 0) throw new Error(`${what} failed (${res.status}): ${String(res.stderr || res.stdout).trim().split("\n").pop()}`);
+ return res;
+}
+
+/**
+ * Sign the bundled limactl (afterPack). No limactl in this build: nothing (the app
+ * downloads Lima's own signed release on first use). A notarized build
+ * (MACOS_NOTARIZE=true) refuses an ad-hoc limactl.
+ */
+function signLimactl(appPath, { env = process.env, run = defaultRun, log = console.log } = {}) {
+ const file = limactlPath(appPath);
+ if (!existsSync(file)) return { signed: false, reason: "no bundled limactl" };
+ const { identity, keychain } = limaIdentity({ env, run });
+ if (identity === "-" && env.MACOS_NOTARIZE === "true") throw new Error("MACOS_NOTARIZE is true but no Developer ID identity was found to sign limactl (set MACOS_SIGNING_KEYCHAIN or CSC_NAME)");
+ must(run("codesign", limaCodesignArgs({ identity, keychain, file })), "codesign of limactl");
+ log(`[sign-lima] limactl signed (${identity === "-" ? "ad hoc" : "Developer ID"}) with ${ENTITLEMENT} and the hardened runtime`);
+ return { signed: true, identity, keychain };
+}
+
+/**
+ * After afterSign's deep ad-hoc signature (a build with no Developer ID): limactl
+ * signed again with its entitlement, then the app sealed again around it (not deep:
+ * every other signature stays as it is).
+ */
+function resignLimaAdHoc(appPath, { run = defaultRun } = {}) {
+ const file = limactlPath(appPath);
+ if (!existsSync(file)) return false;
+ must(run("codesign", limaCodesignArgs({ identity: "-", file })), "ad-hoc codesign of limactl");
+ must(run("codesign", ["--force", "--sign", "-", "--timestamp=none", "--options", "runtime", "--entitlements", APP_ENTITLEMENTS, appPath]), "ad-hoc seal of the app");
+ return true;
+}
+
+/**
+ * Check the bundled limactl as shipped: the virtualization entitlement and the
+ * hardened runtime; for a notarized build also the Developer ID and a timestamp.
+ * Throws with what is wrong.
+ */
+function verifyLimactl(appPath, { requireDeveloperId = false, run = defaultRun } = {}) {
+ const file = limactlPath(appPath);
+ if (!existsSync(file)) return { present: false };
+ must(run("codesign", ["--verify", "--strict", "--verbose=2", file]), "codesign --verify of limactl");
+ const entitlements = must(run("codesign", ["-d", "--entitlements", "-", "--xml", file]), "codesign -d --entitlements of limactl");
+ if (!`${entitlements.stdout}${entitlements.stderr}`.includes(ENTITLEMENT)) throw new Error(`limactl is not signed with ${ENTITLEMENT}`);
+ const details = must(run("codesign", ["-dv", "--verbose=4", file]), "codesign -dv of limactl");
+ const info = `${details.stdout}${details.stderr}`;
+ if (!/flags=0x[0-9a-f]*\([^)]*runtime/.test(info)) throw new Error("limactl is not signed with the hardened runtime");
+ if (requireDeveloperId) {
+ if (!/^Authority=Developer ID Application/m.test(info)) throw new Error("limactl is not Developer ID signed");
+ if (!/^Timestamp=/m.test(info)) throw new Error("limactl's signature has no secure timestamp");
+ }
+ return { present: true };
+}
+
+module.exports = { ENTITLEMENT, LIMA_ENTITLEMENTS, developerIdHash, limaCodesignArgs, limaIdentity, limactlPath, resignLimaAdHoc, signLimactl, verifyLimactl };
diff --git a/scripts/release/verify-macos-signing.sh b/scripts/release/verify-macos-signing.sh
index 17125b64..f5c25ae1 100755
--- a/scripts/release/verify-macos-signing.sh
+++ b/scripts/release/verify-macos-signing.sh
@@ -15,6 +15,22 @@ gatekeeper() {
grep -q 'source=Notarized Developer ID' <<<"$out" || { echo "Gatekeeper source is not Notarized Developer ID" >&2; return 1; }
}
+# The OmniRush VM's limactl (sidecars/lima/bin/limactl): its own signature with Apple's
+# virtualization entitlement (apps/desktop/scripts/sign-lima.cjs), Developer ID, hardened runtime.
+check_lima() {
+ local app="$1" lima details
+ lima="$app/Contents/Resources/sidecars/lima/bin/limactl"
+ [ -e "$lima" ] || { echo "no bundled limactl in $app" >&2; return 1; }
+ codesign --verify --strict --verbose=2 "$lima"
+ details=$(codesign -dv --verbose=4 "$lima" 2>&1)
+ grep -E '^(Identifier|Authority|TeamIdentifier|Timestamp|CodeDirectory)' <<<"$details"
+ grep -q '^Authority=Developer ID Application' <<<"$details" || { echo "limactl is not Developer ID signed" >&2; return 1; }
+ grep -q '^Timestamp=' <<<"$details" || { echo "limactl's signature has no secure timestamp" >&2; return 1; }
+ grep -Eq '^CodeDirectory .*flags=0x[0-9a-f]*\(.*runtime' <<<"$details" || { echo "limactl: hardened runtime is off" >&2; return 1; }
+ codesign -d --entitlements - --xml "$lima" 2>/dev/null | grep -q 'com.apple.security.virtualization' || { echo "limactl lacks com.apple.security.virtualization" >&2; return 1; }
+ "$lima" --version
+}
+
check_app() {
local app="$1" details
echo "== $app"
@@ -26,6 +42,7 @@ check_app() {
codesign -d --entitlements - --xml "$app" 2>/dev/null | plutil -p - || true
gatekeeper -a -vv -t exec "$app"
xcrun stapler validate "$app"
+ check_lima "$app"
}
apps=("$dist"/mac*/*.app)