Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(ci): build a pinned pigz and keep signing keys away from packaging tools

Cursor Agent95e91fab310b
diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.yml
index 913caa367..db087d09b 100644
--- a/.github/workflows/desktop-release.yml
+++ b/.github/workflows/desktop-release.yml
@@ -402,17 +402,31 @@ jobs:
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
RUST_TARGET_TRIPLE: ${{ matrix.settings.target }}
+ - name: Build pinned pigz
+ if: ${{ runner.os == 'macOS' }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ dir="$RUNNER_TEMP/pigz"
+ mkdir -p "$dir"
+ curl -fsSL --retry 3 -o "$dir/pigz.tar.gz" "https://zlib.net/pigz/pigz-$PIGZ_VERSION.tar.gz"
+ echo "$PIGZ_SHA256 $dir/pigz.tar.gz" | shasum -a 256 -c -
+ tar -xzf "$dir/pigz.tar.gz" -C "$dir"
+ make -C "$dir/pigz-$PIGZ_VERSION" CC=cc
+ "$dir/pigz-$PIGZ_VERSION/pigz" --version
+ echo "$dir/pigz-$PIGZ_VERSION" >> "$GITHUB_PATH"
+ env:
+ PIGZ_VERSION: "2.8"
+ PIGZ_SHA256: eb872b4f0e1f0ebe59c9f7bd8c506c4204893ba6a8492de31df416f0d5170fd0
+
# Same bytes, smaller downloads: zopfli for the updater archive, which
# every install (0.6.0's Tauri updater included) still unpacks as gzip,
# and LZMA for the disk image, which macOS 10.15+ mounts natively.
- name: Shrink macOS packages
if: ${{ runner.os == 'macOS' }}
shell: bash
- run: |
- brew install pigz
- node scripts/finalize-macos-packages.mjs "$CAP_BUNDLE"
+ run: node scripts/finalize-macos-packages.mjs "$CAP_BUNDLE"
env:
- HOMEBREW_NO_AUTO_UPDATE: "1"
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_KEYCHAIN: ${{ format('{0}/build.keychain', runner.temp) }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
diff --git a/scripts/finalize-linux-appimage.mjs b/scripts/finalize-linux-appimage.mjs
index b3e503e79..63c836932 100644
--- a/scripts/finalize-linux-appimage.mjs
+++ b/scripts/finalize-linux-appimage.mjs
@@ -411,6 +411,19 @@ export async function relativizeDirIcon(appDir) {
await symlink(name, icon);
}
+const updaterSecrets = [
+ "TAURI_SIGNING_PRIVATE_KEY",
+ "TAURI_SIGNING_PRIVATE_KEY_PASSWORD",
+ "TAURI_PRIVATE_KEY",
+ "TAURI_PRIVATE_KEY_PASSWORD",
+];
+
+export function withoutUpdaterSecrets(env) {
+ const tools = { ...env };
+ for (const name of updaterSecrets) delete tools[name];
+ return tools;
+}
+
export async function signUpdaterArtifact(
filename,
{ env = process.env, run = runCommand } = {},
@@ -461,10 +474,11 @@ export async function finalizeLinuxAppImage(
const work = await mkdtemp(path.join(path.dirname(image), ".cap-appimage-"));
let retainWork = false;
try {
- const runtime = await copyRuntime(image, work, env, run);
+ const tools = withoutUpdaterSecrets(env);
+ const runtime = await copyRuntime(image, work, tools, run);
await run(image, ["--appimage-extract"], {
cwd: work,
- env,
+ env: tools,
stdio: ["ignore", "ignore", "inherit"],
});
const appDir = path.join(work, "squashfs-root");
@@ -474,7 +488,9 @@ export async function finalizeLinuxAppImage(
if (webview) {
await selectAppImageGtkBackend(appDir);
} else {
- excluded.push(...(await removeWebviewRuntime(appDir, { env, run })));
+ excluded.push(
+ ...(await removeWebviewRuntime(appDir, { env: tools, run })),
+ );
}
await relativizeDirIcon(appDir);
await preserveAppImageWorkingDirectory(appDir);
@@ -484,7 +500,7 @@ export async function finalizeLinuxAppImage(
["--appimage-extract-and-run", "--appdir", appDir],
{
env: {
- ...env,
+ ...tools,
APPIMAGE_EXTRACT_AND_RUN: "1",
OUTPUT: output,
LDAI_OUTPUT: output,
diff --git a/scripts/finalize-linux-appimage.test.mjs b/scripts/finalize-linux-appimage.test.mjs
index 38f0bd30c..a9f92995d 100644
--- a/scripts/finalize-linux-appimage.test.mjs
+++ b/scripts/finalize-linux-appimage.test.mjs
@@ -816,6 +816,15 @@ test("webview-free finalization hands the pruned AppDir to the output plugin", a
const { image, plugin } = await fixture(t);
let extracted;
const run = async (command, args, options) => {
+ assert.equal(options.env.PATH, "/usr/bin");
+ for (const name of [
+ "TAURI_SIGNING_PRIVATE_KEY",
+ "TAURI_SIGNING_PRIVATE_KEY_PASSWORD",
+ "TAURI_PRIVATE_KEY",
+ "TAURI_PRIVATE_KEY_PASSWORD",
+ ]) {
+ assert.equal(options.env[name], undefined, `${command} saw ${name}`);
+ }
if (command === image) {
if (args[0] === "--appimage-signature") return { stdout: "" };
if (args[0] === "--appimage-offset") {
@@ -850,7 +859,13 @@ test("webview-free finalization hands the pruned AppDir to the output plugin", a
outputPlugin: plugin,
unsigned: true,
webview: false,
- env: {},
+ env: {
+ PATH: "/usr/bin",
+ TAURI_SIGNING_PRIVATE_KEY: "key",
+ TAURI_SIGNING_PRIVATE_KEY_PASSWORD: "password",
+ TAURI_PRIVATE_KEY: "legacy",
+ TAURI_PRIVATE_KEY_PASSWORD: "legacy-password",
+ },
run,
});
assert.ok(excluded.includes("usr/lib/libwebkit2gtk-4.1.so.0"));
diff --git a/scripts/finalize-linux-gpui-packages.mjs b/scripts/finalize-linux-gpui-packages.mjs
index 7609fbe0c..f06dab0e9 100644
--- a/scripts/finalize-linux-gpui-packages.mjs
+++ b/scripts/finalize-linux-gpui-packages.mjs
@@ -11,7 +11,11 @@ import {
} from "node:fs/promises";
import path from "node:path";
import { pathToFileURL } from "node:url";
-import { runCommand, signUpdaterArtifact } from "./finalize-linux-appimage.mjs";
+import {
+ runCommand,
+ signUpdaterArtifact,
+ withoutUpdaterSecrets,
+} from "./finalize-linux-appimage.mjs";
export const webviewDebPackages = new Set([
"libwebkit2gtk-4.1-0",
@@ -254,10 +258,11 @@ export async function finalizeGpuiDeb(
const deb = path.resolve(filename);
if (!deb.endsWith(".deb")) throw new Error("Expected a .deb artifact");
requireSigningKey(unsigned, env);
+ const tools = withoutUpdaterSecrets(env);
const work = await mkdtemp(path.join(path.dirname(deb), ".cap-deb-"));
try {
const root = path.join(work, "root");
- await run("dpkg-deb", ["--raw-extract", deb, root], { env });
+ await run("dpkg-deb", ["--raw-extract", deb, root], { env: tools });
const linked = await linkDuplicateLibraries(
path.join(root, "usr", "lib", "cap"),
);
@@ -283,11 +288,11 @@ export async function finalizeGpuiDeb(
await run(
"dpkg-deb",
["--root-owner-group", "-Znone", "--build", root, uncompressed],
- { env },
+ { env: tools },
);
const output = path.join(work, path.basename(deb));
await recompressDebData(uncompressed, output, path.join(work, "members"), {
- env,
+ env: tools,
run,
});
await replaceArtifact(output, deb, { unsigned, env, run });
@@ -322,7 +327,8 @@ export async function finalizeGpuiRpm(
const rpm = path.resolve(filename);
if (!rpm.endsWith(".rpm")) throw new Error("Expected an .rpm artifact");
requireSigningKey(unsigned, env);
- if ((await queryRpm(rpm, ["--scripts"], env, run)).trim()) {
+ const tools = withoutUpdaterSecrets(env);
+ if ((await queryRpm(rpm, ["--scripts"], tools, run)).trim()) {
throw new Error(`${rpm} has install scripts that cannot be carried over`);
}
const tags = {};
@@ -336,10 +342,10 @@ export async function finalizeGpuiRpm(
"URL",
"DESCRIPTION",
]) {
- tags[tag] = await queryTag(rpm, tag, env, run);
+ tags[tag] = await queryTag(rpm, tag, tools, run);
}
const requires = withoutWebviewRpmRequirements(
- (await queryRpm(rpm, ["--requires"], env, run))
+ (await queryRpm(rpm, ["--requires"], tools, run))
.split("\n")
.map((line) => line.trim()),
);
@@ -350,7 +356,7 @@ export async function finalizeGpuiRpm(
"--queryformat",
"[%{FILEMODES} %{FILEFLAGS} %{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\\n]",
],
- env,
+ tools,
run,
),
);
@@ -370,7 +376,7 @@ export async function finalizeGpuiRpm(
]) {
await mkdir(path.join(top, directory), { recursive: true });
}
- await run("bsdtar", ["-xf", rpm, "-C", staging], { env });
+ await run("bsdtar", ["-xf", rpm, "-C", staging], { env: tools });
const linked = new Set(
(
await linkDuplicateLibraries(path.join(staging, "usr", "lib", "cap"))
@@ -419,7 +425,7 @@ export async function finalizeGpuiRpm(
"--define",
"__os_install_post %{nil}",
],
- { env: { ...env, LC_ALL: "C" } },
+ { env: { ...tools, LC_ALL: "C" } },
);
await replaceArtifact(path.join(output, path.basename(rpm)), rpm, {
unsigned,
diff --git a/scripts/finalize-linux-gpui-packages.test.mjs b/scripts/finalize-linux-gpui-packages.test.mjs
index 396b9bf24..1fae997d7 100644
--- a/scripts/finalize-linux-gpui-packages.test.mjs
+++ b/scripts/finalize-linux-gpui-packages.test.mjs
@@ -222,11 +222,30 @@ for (const [name, listing, expected] of [
await writeFile(deb, "original");
await writeFile(`${deb}.sig`, "original signature");
const calls = [];
- const env = { TAURI_SIGNING_PRIVATE_KEY: "key" };
+ const env = {
+ PATH: "/usr/bin",
+ TAURI_SIGNING_PRIVATE_KEY: "key",
+ TAURI_SIGNING_PRIVATE_KEY_PASSWORD: "password",
+ };
const operation = finalizeGpuiDeb(deb, {
env,
run: async (command, args, options) => {
calls.push(command === "ar" ? `ar ${args[0]}` : command);
+ if (command !== "bun") {
+ assert.equal(options.env.PATH, "/usr/bin");
+ for (const name of [
+ "TAURI_SIGNING_PRIVATE_KEY",
+ "TAURI_SIGNING_PRIVATE_KEY_PASSWORD",
+ "TAURI_PRIVATE_KEY",
+ "TAURI_PRIVATE_KEY_PASSWORD",
+ ]) {
+ assert.equal(
+ options.env[name],
+ undefined,
+ `${command} saw ${name}`,
+ );
+ }
+ }
if (command === "dpkg-deb" && args[0] === "--raw-extract") {
await mkdir(path.join(args[2], "DEBIAN"), { recursive: true });
await writeFile(
@@ -310,6 +329,71 @@ for (const [name, listing, expected] of [
});
}
+test("rpm tools never see the updater signing key", async (t) => {
+ const root = await workspace(t);
+ const rpm = path.join(root, "Cap.rpm");
+ await writeFile(rpm, "original");
+ await writeFile(`${rpm}.sig`, "original signature");
+ const tags = {
+ NAME: "cap",
+ VERSION: "0.6.1",
+ RELEASE: "1",
+ ARCH: "x86_64",
+ SUMMARY: "Cap",
+ LICENSE: "AGPL-3.0",
+ URL: "",
+ DESCRIPTION: "Cap",
+ };
+ await finalizeGpuiRpm(rpm, {
+ env: {
+ PATH: "/usr/bin",
+ TAURI_SIGNING_PRIVATE_KEY: "key",
+ TAURI_SIGNING_PRIVATE_KEY_PASSWORD: "password",
+ },
+ run: async (command, args, options) => {
+ if (command === "bun") {
+ assert.equal(options.env.TAURI_PRIVATE_KEY, "key");
+ assert.equal(options.env.TAURI_PRIVATE_KEY_PASSWORD, "password");
+ await writeFile(`${args[4]}.sig`, "rebuilt signature");
+ return {};
+ }
+ assert.equal(options.env.PATH, "/usr/bin");
+ for (const name of [
+ "TAURI_SIGNING_PRIVATE_KEY",
+ "TAURI_SIGNING_PRIVATE_KEY_PASSWORD",
+ "TAURI_PRIVATE_KEY",
+ "TAURI_PRIVATE_KEY_PASSWORD",
+ ]) {
+ assert.equal(options.env[name], undefined, `${command} saw ${name}`);
+ }
+ if (command === "rpm" && args.includes("--scripts"))
+ return { stdout: "" };
+ if (command === "rpm" && args.includes("--requires"))
+ return { stdout: "libva\n" };
+ if (command === "rpm" && args.some((arg) => arg.includes("FILEMODES"))) {
+ return { stdout: "33188 0 root root /usr/bin/Cap\n" };
+ }
+ if (command === "rpm") {
+ const tag = args.find((arg) => arg.startsWith("%{"));
+ return { stdout: `${tags[tag.slice(2, -1)]}\n` };
+ }
+ if (command === "rpmbuild") {
+ const rpmdir = args
+ .find((arg) => arg.startsWith("_rpmdir "))
+ .slice("_rpmdir ".length);
+ const filename = args
+ .find((arg) => arg.startsWith("_rpmfilename "))
+ .slice("_rpmfilename ".length);
+ await mkdir(rpmdir, { recursive: true });
+ await writeFile(path.join(rpmdir, filename), "rebuilt");
+ }
+ return {};
+ },
+ });
+ assert.equal(await readFile(rpm, "utf8"), "rebuilt");
+ assert.equal(await readFile(`${rpm}.sig`, "utf8"), "rebuilt signature");
+});
+
test("package finalization requires a signing key unless unsigned", async (t) => {
const root = await workspace(t);
const deb = path.join(root, "Cap.deb");
diff --git a/scripts/finalize-macos-packages.mjs b/scripts/finalize-macos-packages.mjs
index 340841d1c..f5eebdc82 100644
--- a/scripts/finalize-macos-packages.mjs
+++ b/scripts/finalize-macos-packages.mjs
@@ -2,7 +2,11 @@ import { mkdtemp, readdir, rename, rm, stat } from "node:fs/promises";
import path from "node:path";
import { setTimeout as wait } from "node:timers/promises";
import { pathToFileURL } from "node:url";
-import { runCommand, signUpdaterArtifact } from "./finalize-linux-appimage.mjs";
+import {
+ runCommand,
+ signUpdaterArtifact,
+ withoutUpdaterSecrets,
+} from "./finalize-linux-appimage.mjs";
const captured = (env) => ({
env: { ...env, LC_ALL: "C" },
@@ -39,6 +43,7 @@ export async function recompressUpdaterArchive(
"TAURI_SIGNING_PRIVATE_KEY is required to sign the updater archive",
);
}
+ const tools = withoutUpdaterSecrets(env);
const work = await mkdtemp(path.join(path.dirname(archive), ".cap-update-"));
try {
const output = path.join(work, path.basename(archive));
@@ -51,11 +56,11 @@ export async function recompressUpdaterArchive(
archive,
output,
],
- { env },
+ { env: tools },
);
if (
- (await tarDigest(archive, env, run)) !==
- (await tarDigest(output, env, run))
+ (await tarDigest(archive, tools, run)) !==
+ (await tarDigest(output, tools, run))
) {
throw new Error("The recompressed updater archive changed its contents");
}
@@ -114,15 +119,16 @@ export async function convertDiskImage(
"APPLE_SIGNING_IDENTITY is required to sign the disk image",
);
}
+ const tools = withoutUpdaterSecrets(env);
const work = await mkdtemp(path.join(path.dirname(dmg), ".cap-dmg-"));
try {
const output = path.join(work, path.basename(dmg));
try {
await run("hdiutil", ["convert", dmg, "-format", "ULMO", "-o", output], {
- env,
+ env: tools,
});
- await run("hdiutil", ["verify", output], { env });
- await signDiskImage(output, env, run, delay);
+ await run("hdiutil", ["verify", output], { env: tools });
+ await signDiskImage(output, tools, run, delay);
} catch (error) {
warn(
`::warning::Keeping the zlib disk image; LZMA conversion failed: ${error instanceof Error ? error.message : error}`,
diff --git a/scripts/finalize-macos-packages.test.mjs b/scripts/finalize-macos-packages.test.mjs
index 5aaf43d3f..d8feea9af 100644
--- a/scripts/finalize-macos-packages.test.mjs
+++ b/scripts/finalize-macos-packages.test.mjs
@@ -196,6 +196,60 @@ test("disk image conversion needs a signing identity before touching the image",
assert.equal(await readFile(dmg, "utf8"), "original");
});
+test("only the updater signer sees the updater signing key", async (t) => {
+ const root = await workspace(t);
+ await mkdir(path.join(root, "macos"));
+ await mkdir(path.join(root, "dmg"));
+ await writeFile(path.join(root, "macos/Cap.app.tar.gz"), "original archive");
+ await writeFile(path.join(root, "dmg/Cap.dmg"), Buffer.alloc(100, 7));
+ const calls = [];
+ const result = await finalizeMacosPackages(root, {
+ env: {
+ PATH: "/usr/bin",
+ APPLE_SIGNING_IDENTITY: "Developer ID Application: Cap",
+ TAURI_SIGNING_PRIVATE_KEY: "key",
+ TAURI_SIGNING_PRIVATE_KEY_PASSWORD: "password",
+ },
+ run: async (command, args, options) => {
+ calls.push({ command, env: options.env });
+ if (command === "bash" && args[1].includes("pigz -11")) {
+ await writeFile(args[4], "smaller");
+ } else if (command === "bash") {
+ return { stdout: `${"a".repeat(64)} -\n` };
+ } else if (command === "bun") {
+ await writeFile(`${args[4]}.sig`, "signature");
+ } else if (command === "hdiutil" && args[0] === "convert") {
+ await writeFile(args[5], Buffer.alloc(10, 1));
+ }
+ return {};
+ },
+ });
+ assert.deepEqual(result, {
+ archive: { before: 16, after: 7 },
+ dmg: { before: 100, after: 10 },
+ });
+ const tools = calls.filter((call) => call.command !== "bun");
+ assert.deepEqual(
+ [...new Set(tools.map((call) => call.command))],
+ ["bash", "hdiutil", "codesign"],
+ );
+ for (const call of tools) {
+ assert.equal(call.env.PATH, "/usr/bin");
+ for (const name of [
+ "TAURI_SIGNING_PRIVATE_KEY",
+ "TAURI_SIGNING_PRIVATE_KEY_PASSWORD",
+ "TAURI_PRIVATE_KEY",
+ "TAURI_PRIVATE_KEY_PASSWORD",
+ ]) {
+ assert.equal(call.env[name], undefined, `${call.command} saw ${name}`);
+ }
+ }
+ const signer = calls.filter((call) => call.command === "bun");
+ assert.equal(signer.length, 1);
+ assert.equal(signer[0].env.TAURI_PRIVATE_KEY, "key");
+ assert.equal(signer[0].env.TAURI_PRIVATE_KEY_PASSWORD, "password");
+});
+
test("macOS packages are located once each inside the bundle", async (t) => {
const root = await workspace(t);
await mkdir(path.join(root, "macos"));