Repository navigation
ci: sign every Windows binary on a self-hosted token runner - #47
Merged
Merged
Conversation
The code-signing key lives on a SafeNet eToken that cannot leave its USB port, so the Windows package job moves to the self-hosted runner the token is plugged into (label `codesign`) and signs through jsign over PKCS#11. Every PE image is signed, not just the installer: electron-builder's sign hook covers each .exe (app, extraResources, uninstaller, installer) and afterPack batch-signs the DLLs and .pyd/.node modules. Files already carrying a valid third-party signature keep it. An audit step fails the job if any PE file in the app or the installer is not validly signed. The token locks after 5 wrong PINs, so a signing failure is never retried: it writes a halt file on the runner, and no later build logs in to the token until a human clears it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
models.dev split `kimi-for-coding` into `kimi-code-plan-cn` (kimi.com) and `kimi-code-plan-global` (kimi.ai). The packaging step validates every provider policy against the live catalog, so every build failed with "models.dev provider 'kimi-for-coding' is missing". `kimi-code-plan-cn` serves https://api.kimi.com/coding/v1, the base URL this policy already targets, and carries the same model IDs. The checked-in snapshot is regenerated too: the backend validates policies against it at import time and would not start otherwise. Installed clients are unaffected; they persist our provider id `kimi`, never the source id. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ensure-runtime-resources validates each staged runtime by running it with a 5s timeout. The first launch of a freshly downloaded binary waits on the antivirus scan: on the self-hosted Windows runner the 60 MB uv.exe took 4.3s when idle and exceeded 5s under build load, so a correct runtime was reported as "invalid". Hosted runners never showed it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
win-sign.cjs asks Windows PowerShell 5.1 which files still need signing. Every CI step runs under pwsh 7, and node hands the child pwsh 7's PSModulePath untouched, so 5.1 tried to load pwsh 7's Microsoft.PowerShell.Security and Get-AuthenticodeSignature was unavailable. The error still exited 0 with empty output, which read as "0 files need signing": the whole build went out unsigned (the audit step would have caught it, but only at the end). Drop PSModulePath for the child so 5.1 uses its own default, and set ErrorActionPreference to Stop so a failed check fails the build instead of skipping the signature. Reproduced and verified on the signing machine by starting 5.1 from pwsh 7 through Process.Start, as node does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Smart App Control stays on on the signing machine, and it blocks a freshly
built unsigned exe whenever it has no cloud reputation, which a new
PyInstaller build never has: the windowless smoke test could not launch
amphi-autostart.exe ("application control policy has blocked this file").
There is no allowlist for Smart App Control; a valid signature is the only
way through.
Sign dist/amphi right after PyInstaller, through a small CLI entry in
win-sign.cjs. prebuild-fetch-amphi copies the files as-is, so afterPack
later finds them validly signed and skips them. The signing-machine check
moves up with it, so a halt file stops the job before either signing pass.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Under the runner's service account Get-AuthenticodeSignature could not
confirm Microsoft's VCRUNTIME140.dll as Valid, so it was queued for
signing, and jsign rejected its existing certificate table ("Invalid data
directory (index=4)"). Sign only files that are NotSigned: publisher
signatures are kept, and the audit step still catches a broken one.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The cleanup step killed every amphi / Bridgic Agent process by name. On the
self-hosted runner another account runs its own Bridgic Agent, whose daemon
the non-admin runner account cannot stop ("access denied"), so the job failed
before checkout. Limit it to processes under the runner's workspace or its
own LOCALAPPDATA; processes of other accounts expose no Path and are left
alone.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…orts The signing runner doubles as a test machine. A Bridgic Agent running under another account keeps the daemon's default port 7421, and the installer scenarios would then fail, or pass against that daemon instead of the build under test. Check 7421 and 9123 first and fail with a clear message rather than kill a process that is not the runner's. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The VCRUNTIME140.dll and VCRUNTIME140_1.dll copies in the PyInstaller bundle end exactly where Microsoft's signature used to begin (size 103936, certificate table at 103936 + 20608), yet their header still points at it. Windows reports them NotSigned, so they are queued for signing, and jsign rejects them with "Invalid data directory (index=4)". Before signing, zero that one data-directory entry when it points past the end of the file. The entry is excluded from the Authenticode digest and ignored by the loader, so the file becomes a plain unsigned PE that jsign signs normally. Intact tables are never touched. Reproduced and verified locally with jsign 7.5 on a PE truncated the same way. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Every jsign failure wrote the halt file, including the two VCRUNTIME140 failures where the token had already signed a dozen files: the PIN was right, a retry could not cost an attempt, and a human still had to clear the file by hand. After a failure, check whether any file of that chunk is now signed. If so, the token accepted the PIN in this run, which also resets its wrong-PIN counter, so no halt is written. If nothing got signed, or that cannot be determined, the failure may be a wrong PIN and the halt is written as before. The error text is deliberately not parsed: a PIN error worded in an unexpected way would read as safe and let every later run spend an attempt. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…machine The first fully signed run reached a signed installer in ~35 min and then spent ~55 min in the installer smoke, where the 90-minute limit cancelled it during the ninth scenario (the first eight had passed). Antivirus scans every install on this laptop, so the scenarios run at about half the speed of a hosted runner. Raise the limit to 150. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A job signs in several separate jsign runs: the PyInstaller bundle, then one run per .exe during packaging. When the network dropped mid-packaging, signing uv.exe failed alone, nothing in that one-file run got signed, and the halt file was written, although the same PIN from the same secret had signed 128 files minutes earlier in that job. Record a successful login in RUNNER_TEMP, which every job starts empty, and treat it as proof for the rest of the job. Outside CI there is no proof and the conservative rule applies unchanged. jsign's output is now captured, still echoed to the log, and its tail is written into the halt file: that run's log never reached GitHub because the runner lost its connection, and the halt file said only "Command failed". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Only a real Release (tag push or release_tag) and a manual run with the new `sign` input go to the self-hosted token runner. Every other manual run builds Windows unsigned on windows-latest, so an internal build no longer needs the signing machine switched on. `meta` decides runner and signing together, and the signing-only steps and the token PIN follow that decision.
The Releasing section now opens with one table — tag push, release_tag, nightly, nightly with `sign` — showing the release shape, platforms, Windows runner, signing and smoke for each, so the rules the workflow's `meta` job enforces can be read in one place.
lynnlink
approved these changes
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Release builds of Windows are now Authenticode-signed, every PE image included, not just the installer. Nightlies stay unsigned and build on a hosted runner, so an internal build never needs the signing machine switched on.
The GlobalSign OV code-signing key lives on a SafeNet eToken that cannot leave its USB port, so a signed Windows
packagejob runs on a self-hosted runner ([self-hosted, windows, codesign]) that has the token plugged in.metasends a job there only for a real Release (tag push orrelease_tag) or when the newsigninput is ticked; every other manual run stays onwindows-latest. Signing goes through jsign over PKCS#11. signtool cannot run unattended here: the token's CSP raises a PIN dialog on every signature.First fully green signed run: 36684020671. It signed 128 + 51 files plus the executables, the audit reported 238 PE files checked, 0 without a valid signature, all 9 installer smoke scenarios passed, and it published
nightly-20260930-0729. I downloaded that installer and checked it independently: the signer is 北京比特天空科技有限公司 (cert SHA-17E6BB778…36 99, valid until 2027-09-23), it carries a GlobalSign RFC 3161 timestamp, andlatest.yml's sha512 and size match the file.Hosted path verified on 37918170649: the Windows job ran on
windows-latest, the three signing steps were skipped,win-sign.cjsleft 239 + 19 files unsigned by design, and it publishednightly-20261009-1032in 6 min 39 s without touching the signing machine.What changed
Signing
build/win-sign.cjs(new): signs through the token with jsign. It signs only files that areNotSigned, so third-party publisher signatures (Microsoft, PSF, OpenJS) are kept, and it signs in chunks of 100 so one JVM start and one token login cover each chunk. It is a no-op withoutWIN_SIGN_PIN, so local and fork builds still work.electron-builder.yml:signtoolOptions.signhook for every.exe(app, extraResources, uninstaller, installer), sha256 only.after-pack.cjs: batch-signs the DLL /.pyd/.nodeimages that the hook never sees.package.yml: signsdist/amphiright after PyInstaller. This is needed because Smart App Control on the runner blocks a freshly built unsigned exe, so the windowless smoke test could not launch it. A final audit step fails the job if any PE file in the app or the installer lacks a valid signature.Routing: signed releases, unsigned nightlies
package.yml:metaemitswindows_signedandwindows_runs_on. The Windows job takesruns-onfrom the latter throughfromJSON, and its timeout is 150 min on the signing machine, 45 on a hosted runner.Check the signing machine,Sign the amphi bundleandAudit Authenticode signaturesrun only when signed, andWIN_SIGN_PINis injected only then — a hosted runner never holds the token PIN, and withholding it is what makes the build unsigned, sincewin-sign.cjsalready skips without it. No change to the signing scripts.workflow_dispatchinputsign(default off) forces a nightly onto the signing machine, so the signing pipeline can be exercised without cutting a release.Releasingnow opens with a table of what each trigger produces: release shape, platforms, Windows runner, signing and smoke for tag push,release_tag, nightly and nightly withsign.Token safety. The token's user PIN (repository secret
WIN_TOKEN_PIN) allows 5 wrong attempts before the token locks and has to be reset; 5 wrong admin PINs brick it for good. Only the user PIN is ever used, and the job never retries a signature by itself.C:\actions-runner\signing-halted.txton the signing machine (codesign-win, the laptop the runner and the token live on — not in the repo, not in the job workspace, so it survives between runs).win-sign.cjswrites it when a jsign failure may have been a wrong PIN; it holds a timestamp and the last 40 lines of jsign's output.packagejob fails in seconds atCheck the signing machine, which prints the file's content into the job log, before anything is built;win-sign.cjsrefuses as well. No job logs in to the token.codesign-win; (2) fix it (an empty or wrongWIN_TOKEN_PIN, the token unplugged, the timestamp server unreachable, …); (3) deleteC:\actions-runner\signing-halted.txtoncodesign-win; (4) re-run the workflow. Re-running without deleting is harmless but pointless — it fails at the check. Never delete the file just to retry: if the PIN is wrong, every run spends one of the 5 attempts.%RUNNER_TEMP%\win-sign-pin-accepted, per-job temp — nothing to clean up), or any file of the failing chunk came out signed, the failure cannot be a wrong PIN and no halt is written. A successful login also resets the token's wrong-PIN counter, so a retry cannot lock it. The error text is deliberately not parsed: signed-or-not is observable, wording is not.Fixes the self-hosted runner surfaced
VCRUNTIME140*.dllin the Python runtime arrives truncated exactly where Microsoft's signature began, while its header still points at it, and jsign rejects it. The dangling certificate-table entry is zeroed before signing. Reproduced and verified locally with jsign 7.5.PSModulePathinherited from node, soGet-AuthenticodeSignaturefailed. That error exited 0, which read as "nothing to sign". Now the variable is dropped and the check fails loudly.Unrelated, but blocks every build on
maintodaykimi-for-codingtokimi-code-plan-cn/kimi-code-plan-global, and packaging validates provider policies against the live catalog. The policy now points atkimi-code-plan-cn(same base URLapi.kimi.com/coding/v1, same model IDs), and the checked-in snapshot is regenerated. Installed clients persist the provider idkimiand are unaffected.Runner prerequisites (not in the repo)
A signed Windows job depends on this machine setup:
codesign-winruns as the non-admin service account.\ghrunner, with delayed autostart and restart on failure. The account holdsSeCreateSymbolicLinkPrivilege, becausesetup-buncreates a symlink.C:\codesign\jre(Temurin 21) andC:\codesign\jsign.jar(7.5).C:\actions-runner\.env: proxy127.0.0.1:7890for GitHub/PyPI, npmmirror mirrors for npm / Electron / python-build-standalone, and a longer uv HTTP timeout and more retries.WIN_TOKEN_PIN, which holds the token's user PIN. The admin PIN is never used.Known limits
signis ticked.smokefinish in about 35 min on the signing machine; a hosted unsigned nightly took under 7 min.Test plan
latest.ymlsha512/sizeruns-onresolved towindows-latest, signing steps skipped, 239 + 19 files left unsigned,nightly-20261009-1032published with exe / blockmap /latest.ymlmetadecision exercised for tag push,-rctag,release_tag, nightly with and withoutsign; actionlint cleanmainlocally: pytest 1231 passed; desktop test 2573 passed, typecheck, lint,check:chineseplatform: allrun🤖 Generated with Claude Code