Skip to content

Commit 456b7bd

Browse files
authored
Merge pull request #85 from radroid/t3x/mac-signing
fix(t3x): sign the macOS build with a stable identity so permission grants survive updates (#70)
2 parents 4e1f44d + a47c41a commit 456b7bd

13 files changed

Lines changed: 2535 additions & 11 deletions

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

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,86 @@ jobs:
241241
# ci.yml, release.yml and t3x-weekly-verify.yml, which all scope it the same way.
242242
run: vp run --filter @t3tools/desktop ensure:electron
243243

244+
# Issue #70: WITHOUT this step the mac artifact is ad-hoc signed, its designated requirement
245+
# is the binary's cdhash, and macOS re-requests every permission (Screen Recording,
246+
# Accessibility, Microphone, Files & Folders, Local Network) after every single update.
247+
#
248+
# The identity is a self-signed certificate created by scripts/t3x/setup-mac-signing.sh; the
249+
# private key reaches CI as a p12 in T3X_MAC_CSC_P12_BASE64. It buys stability, not trust:
250+
# the app is still not notarized, and does not need to be, because the requirement only has to
251+
# stop MOVING for the grants to stick.
252+
#
253+
# No edit to build-desktop-artifact.ts (an upstream-owned file) is needed for any of this.
254+
# That file forces CSC_IDENTITY_AUTO_DISCOVERY=false for unsigned builds, but electron-builder
255+
# checks the flag only when NO identity was named — app-builder-lib's findIdentity() reads
256+
# `qualifier || process.env.CSC_NAME` first and, when that is non-empty, goes straight to
257+
# `security find-identity`. So exporting CSC_NAME on the build step is enough, and the fork's
258+
# zero-seam property survives. Do not "simplify" this by passing --signed instead: that takes
259+
# the macOS passkey path, which demands T3CODE_CLERK_PUBLISHABLE_KEY and a provisioning
260+
# profile, and turns on notarization expectations a self-signed certificate cannot satisfy.
261+
- name: Import the macOS signing identity
262+
id: signing
263+
if: ${{ matrix.platform == 'mac' }}
264+
shell: bash
265+
env:
266+
CSC_P12_BASE64: ${{ secrets.T3X_MAC_CSC_P12_BASE64 }}
267+
CSC_P12_PASSWORD: ${{ secrets.T3X_MAC_CSC_PASSWORD }}
268+
IDENTITY_NAME: T3X Code Signing
269+
run: |
270+
set -euo pipefail
271+
272+
if [[ -z "${CSC_P12_BASE64:-}" || -z "${CSC_P12_PASSWORD:-}" ]]; then
273+
echo "::warning::No macOS signing secrets set, so this build is ad-hoc signed and will re-request every macOS permission once installed. See docs/t3x/mac-signing-runbook.md."
274+
{
275+
echo "signed=false"
276+
echo "identity="
277+
} >> "$GITHUB_OUTPUT"
278+
exit 0
279+
fi
280+
281+
keychain="$RUNNER_TEMP/t3x-signing.keychain-db"
282+
keychain_password="$(openssl rand -base64 24)"
283+
p12="$RUNNER_TEMP/t3x-signing.p12"
284+
printf '%s' "$CSC_P12_BASE64" | base64 --decode > "$p12"
285+
286+
security create-keychain -p "$keychain_password" "$keychain"
287+
# No -t: the default 300-second idle lock would expire during a 30-minute build and the
288+
# signing step would fail with "no identity found" long after this step went green.
289+
security set-keychain-settings "$keychain"
290+
security unlock-keychain -p "$keychain_password" "$keychain"
291+
security import "$p12" -k "$keychain" -P "$CSC_P12_PASSWORD" \
292+
-T /usr/bin/codesign -T /usr/bin/security
293+
# -T above is not sufficient on its own since macOS 10.12: without the partition list,
294+
# codesign gets a GUI authorisation prompt, which on a runner means a hung job.
295+
security set-key-partition-list -S apple-tool:,apple:,codesign: -s \
296+
-k "$keychain_password" "$keychain" >/dev/null
297+
298+
# electron-builder calls `security find-identity -v` with NO keychain argument, so the
299+
# keychain has to be in the search list. Re-passing the existing entries is required:
300+
# `-s` REPLACES the list. Unquoted on purpose — runner keychain paths contain no spaces.
301+
# shellcheck disable=SC2046
302+
security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"')
303+
304+
# A self-signed certificate is not "valid for code signing" until it is trusted, and `-v`
305+
# means valid. Skip this and find-identity lists nothing, electron-builder logs
306+
# "skipped macOS application code signing" as a WARNING, and the release goes green with
307+
# exactly the bundle this whole step exists to prevent.
308+
sudo security add-trusted-cert -d -r trustRoot -p codeSign \
309+
-k /Library/Keychains/System.keychain docs/t3x/mac-signing/certificate.pem
310+
311+
rm -f "$p12"
312+
313+
if ! security find-identity -v -p codesigning | grep -Fq "$IDENTITY_NAME"; then
314+
echo "::error::'$IDENTITY_NAME' is not a valid code-signing identity after import." >&2
315+
security find-identity -v >&2 || true
316+
exit 1
317+
fi
318+
echo "Signing identity available: $IDENTITY_NAME"
319+
{
320+
echo "signed=true"
321+
echo "identity=$IDENTITY_NAME"
322+
} >> "$GITHUB_OUTPUT"
323+
244324
# Installed unconditionally by upstream for Windows, separate from the signing block — the
245325
# staged `vp install --prod` still runs native lifecycle scripts (node-pty, sharp,
246326
# msgpackr-extract) and recent MSVC + node-gyp wants the Spectre-mitigated libs.
@@ -335,6 +415,18 @@ jobs:
335415
# upstream edits. The verify step below asserts it.
336416
GITHUB_REPOSITORY: ""
337417
T3CODE_DESKTOP_UPDATE_REPOSITORY: ""
418+
# Issue #70, and the only line that makes the mac build signed. Empty on Windows and
419+
# whenever no signing secret is configured, which is the same as absent: the build script
420+
# scrubs empty variables, and electron-builder's findIdentity() treats an empty CSC_NAME as
421+
# "not specified" and falls back to the ad-hoc path. The verify step below is what turns
422+
# that silent fallback into a visible one.
423+
CSC_NAME: ${{ steps.signing.outputs.identity }}
424+
# The other half of #70. macOS stores one permission row per (service, bundle id), and this
425+
# fork's app shared `com.t3tools.t3code` with upstream's nightly — so whichever was launched
426+
# last owned the grants and the other got re-prompted, however well either was signed.
427+
# Keep this in step with DESKTOP_BUNDLE_IDENTIFIER in scripts/t3x/mac-signature.ts; a test
428+
# asserts the two agree, and the verify step below fails an artifact carrying the wrong id.
429+
T3X_DESKTOP_APP_ID: dev.curlycloud.coil
338430
run: |
339431
set -euo pipefail
340432
node scripts/build-desktop-artifact.ts \
@@ -359,6 +451,50 @@ jobs:
359451
fi
360452
echo "No app-update.yml packaged."
361453
454+
# The machine-checkable form of "this update will not re-ask for permissions" (issue #70),
455+
# made against the .app inside the shipped .dmg rather than a staging copy.
456+
#
457+
# It exists because electron-builder does not fail when it cannot find an identity — it warns
458+
# and produces an ad-hoc bundle. Without this step the regression is invisible until the user
459+
# is clicking through five system dialogs again, days later, with a green release behind them.
460+
#
461+
# A CHANGED-but-valid identity is failed too, not just a missing one: a different certificate
462+
# is still one full round of prompts, and the recorded requirement is the only thing that can
463+
# tell the difference.
464+
- name: Verify the macOS artifact keeps its permission grants
465+
if: ${{ matrix.platform == 'mac' }}
466+
shell: bash
467+
env:
468+
SIGNED: ${{ steps.signing.outputs.signed }}
469+
IDENTITY: ${{ steps.signing.outputs.identity }}
470+
run: |
471+
set -euo pipefail
472+
dmg="$(find release -maxdepth 1 -name '*.dmg' -print -quit)"
473+
if [[ -z "$dmg" ]]; then
474+
echo "::error::No .dmg in release/ to verify." >&2
475+
exit 1
476+
fi
477+
478+
args=(
479+
--artifact "$dmg"
480+
--expect-requirement-file docs/t3x/mac-signing/designated-requirement.txt
481+
)
482+
if [[ "$SIGNED" == "true" ]]; then
483+
args+=(--expect-authority "$IDENTITY")
484+
else
485+
# Downgrade to a warning ONLY when this job knowingly had no identity to sign with.
486+
args+=(--allow-unsigned)
487+
fi
488+
489+
node scripts/t3x/verify-mac-signature.ts "${args[@]}"
490+
491+
- name: Delete the signing keychain
492+
if: ${{ always() && matrix.platform == 'mac' && steps.signing.outputs.signed == 'true' }}
493+
shell: bash
494+
run: |
495+
security delete-keychain "$RUNNER_TEMP/t3x-signing.keychain-db" 2>/dev/null || true
496+
rm -f "$RUNNER_TEMP/t3x-signing.p12"
497+
362498
- name: Collect and rename
363499
id: collect
364500
shell: bash

0 commit comments

Comments
 (0)