Skip to content

Commit dd2678d

Browse files
fix(ci): macOS PR previews no longer run the PR's bundle next to signing secrets (#36407)
1 parent 1219f62 commit dd2678d

6 files changed

Lines changed: 87 additions & 3 deletions

‎.github/workflows/desktop-macos-preview-publish.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ jobs:
316316
rust_target: aarch64-apple-darwin
317317
resource_key: darwin-arm64
318318
cli_archive: false
319+
untrusted_bundle: true
319320

320321
# Release assets download without a GitHub account, unlike workflow
321322
# artifacts. All preview DMGs live on one rolling prerelease tagged

‎.github/workflows/release-desktop.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ on:
7070
required: false
7171
default: false
7272
type: boolean
73+
# Whether the JS bundle came from a pull request. This job holds the
74+
# signing secrets, so packaging then skips every step that runs the bundle.
75+
untrusted_bundle:
76+
required: false
77+
default: false
78+
type: boolean
7379
# A runner of the target's own platform and architecture, for a `runner`
7480
# that cannot execute the target. The build job skips everything that
7581
# runs the packaged binaries, and a second job runs it there.
@@ -134,6 +140,14 @@ jobs:
134140
T3CODE_CLERK_CLI_OAUTH_CLIENT_ID: ${{ inputs.clerk_cli_oauth_client_id }}
135141
T3CODE_RELAY_URL: ${{ inputs.relay_url }}
136142
steps:
143+
# The launch check and the CLI archive smoke test both run the bundle.
144+
- name: Reject running an untrusted bundle
145+
if: inputs.untrusted_bundle && (inputs.launch_check || inputs.cli_archive)
146+
shell: bash
147+
run: |
148+
echo "::error::untrusted_bundle cannot be combined with launch_check or cli_archive, which run the bundle."
149+
exit 1
150+
137151
# This repository is public, so Git needs no credentials. checkout's
138152
# credential cleanup runs submodule foreach even with submodules disabled,
139153
# which fails on the orphaned gitlinks in our vendored .repos tree.
@@ -573,6 +587,7 @@ jobs:
573587
pnpm_config_prefer_offline: "true"
574588
T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR: true
575589
T3CODE_DESKTOP_REUSE_LINUX_CAPTURE_HELPERS: ${{ steps.capture_helper_cache.outputs.cache-hit == 'true' }}
590+
T3CODE_DESKTOP_UNTRUSTED_BUNDLE: ${{ inputs.untrusted_bundle }}
576591
CSC_LINK: ${{ secrets.CSC_LINK }}
577592
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
578593
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}

‎scripts/build-desktop-artifact.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as Sink from "effect/Sink";
1919
import * as Schema from "effect/Schema";
2020
import * as Stream from "effect/Stream";
2121
import { ChildProcess, ChildProcessSpawner } from "effect/process";
22+
import { fromYaml } from "@t3tools/shared/schemaYaml";
2223

2324
import {
2425
buildDesktopBundles,
@@ -1430,6 +1431,57 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
14301431
),
14311432
);
14321433

1434+
it.effect("never runs an untrusted macOS bundle", () =>
1435+
Effect.scoped(
1436+
Effect.gen(function* () {
1437+
const fs = yield* FileSystem.FileSystem;
1438+
const path = yield* Path.Path;
1439+
const marker = path.join(yield* fs.makeTempDirectoryScoped(), "ran");
1440+
const fixture = yield* makePackagedAppFixture({
1441+
serverEntrySource: `import { writeFileSync } from "node:fs";\nwriteFileSync(${JSON.stringify(marker)}, "");\n`,
1442+
});
1443+
yield* validateMacPackagedPayload({ stageDistDir: fixture.stageDistDir });
1444+
assert.isFalse(yield* fs.exists(marker));
1445+
}),
1446+
).pipe(
1447+
Effect.provide(
1448+
ConfigProvider.layer(
1449+
ConfigProvider.fromEnv({ env: { T3CODE_DESKTOP_UNTRUSTED_BUNDLE: "true" } }),
1450+
),
1451+
),
1452+
),
1453+
);
1454+
1455+
it.effect("packages the macOS preview's PR bundle as untrusted", () =>
1456+
Effect.gen(function* () {
1457+
const fs = yield* FileSystem.FileSystem;
1458+
const path = yield* Path.Path;
1459+
const workflow = yield* fs.readFileString(
1460+
yield* path.fromFileUrl(
1461+
new URL("../.github/workflows/desktop-macos-preview-publish.yml", import.meta.url),
1462+
),
1463+
);
1464+
const { jobs } = yield* Schema.decodeEffect(
1465+
fromYaml(
1466+
Schema.Struct({
1467+
jobs: Schema.Record(
1468+
Schema.String,
1469+
Schema.Struct({
1470+
uses: Schema.optional(Schema.String),
1471+
with: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
1472+
}),
1473+
),
1474+
}),
1475+
),
1476+
)(workflow);
1477+
const packaging = Object.values(jobs).filter(
1478+
(job) => job.uses === "./.github/workflows/release-desktop.yml",
1479+
);
1480+
assert.isNotEmpty(packaging);
1481+
for (const job of packaging) assert.strictEqual(job.with?.untrusted_bundle, true);
1482+
}),
1483+
);
1484+
14331485
it.effect("rejects a macOS stage without a packaged app", () =>
14341486
Effect.scoped(
14351487
Effect.gen(function* () {

‎scripts/build-desktop-artifact.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,13 @@ export const copyDirectoryPreservingSymlinks = Effect.fn("copyDirectoryPreservin
22122212

22132213
export const verifyPackagedBundleIsSelfContained = Effect.fn("verifyPackagedBundleIsSelfContained")(
22142214
function* (input: { readonly asarPath: string; readonly verbose: boolean }) {
2215+
// A PR preview's bundle is untrusted and this job may hold signing secrets, so never run it.
2216+
if (yield* Config.Boolean("T3CODE_DESKTOP_UNTRUSTED_BUNDLE").pipe(Config.withDefault(false))) {
2217+
yield* Effect.log(
2218+
"[desktop-artifact] Skipped the bundle self-check for an untrusted bundle.",
2219+
);
2220+
return;
2221+
}
22152222
const fs = yield* FileSystem.FileSystem;
22162223
const path = yield* Path.Path;
22172224

‎scripts/lib/server-compile-cache.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ it.each([
1010
{ platform: "freebsd", hostArch: "x64", arch: 1, reason: "unsupported target freebsd" },
1111
{ platform: "linux", hostArch: "x64", arch: 3, reason: "unexecutable target linux/arm64" },
1212
{ platform: "linux", hostArch: "arm64", arch: 1, reason: "unexecutable target linux/x64" },
13+
{ platform: "darwin", hostArch: "arm64", arch: 3, reason: "untrusted bundle", untrusted: true },
1314
])(
14-
"skips unsupported $platform/$hostArch cache generation",
15-
async ({ platform, hostArch, arch, reason }) => {
15+
"skips cache generation for $reason",
16+
async ({ platform, hostArch, arch, reason, untrusted }) => {
1617
const { spawnSync } = await import("node:child_process");
1718
const hook = NodeURL.fileURLToPath(
1819
new URL("../prepare-server-compile-cache.cjs", import.meta.url),
@@ -25,7 +26,10 @@ it.each([
2526
Object.defineProperty(process, "arch", { value: ${JSON.stringify(hostArch)} });
2627
require(${JSON.stringify(hook)})({ electronPlatformName: ${JSON.stringify(platform)}, arch: ${arch} }).catch(error => { console.error(error); process.exitCode = 1; });`,
2728
],
28-
{ encoding: "utf8" },
29+
{
30+
encoding: "utf8",
31+
env: { ...process.env, T3CODE_DESKTOP_UNTRUSTED_BUNDLE: untrusted ? "true" : "" },
32+
},
2933
);
3034
expect(result.status, result.stderr).toBe(0);
3135
expect(result.stdout).toContain(`Skipping ${reason}`);

‎scripts/prepare-server-compile-cache.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ module.exports = async ({ appOutDir, electronPlatformName, arch, packager }) =>
1010
console.log(`[server-compile-cache] Skipping unsupported target ${electronPlatformName}`);
1111
return;
1212
}
13+
// Generating the cache runs the bundle, and a PR preview's bundle must never run next to signing secrets.
14+
if (process.env.T3CODE_DESKTOP_UNTRUSTED_BUNDLE === "true") {
15+
console.log("[server-compile-cache] Skipping untrusted bundle");
16+
return;
17+
}
1318
const targetArch = ["ia32", "x64", "armv7l", "arm64", "universal"][arch];
1419
const runsWithRosetta =
1520
electronPlatformName === "darwin" &&

0 commit comments

Comments
 (0)