mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-04 06:57:55 +00:00
fix(deploy): correct the errSecInternalComponent advice
The previous revision told people to run 'security unlock-keychain' first, which cannot work from launchd's Background domain: the command cannot prompt for the passphrase there, and an unlocked keychain alone does not let a background process read the private key. It also guessed the session up front from `launchctl managername`, which flagged legitimate deploys (an SSH session that unlocked first signs fine). Detect nothing in advance: run codesign, and when it fails with errSecInternalComponent / "User interaction is not allowed", print the two remedies that actually work - run the deploy from a Terminal window on this machine, or allow the signing key for all applications in Keychain Access. Verified both paths with the pinned identity (real sign succeeds; a shim that returns errSecInternalComponent prints the guidance and exits 1). Also ignore .opencode/ (OpenCode's per-project scratch dir, ~60MB here).
This commit is contained in:
@@ -82,3 +82,6 @@ android/app/google-services.json
|
||||
|
||||
# HAPI team memory (local)
|
||||
.hapi/
|
||||
|
||||
# OpenCode's per-project scratch dir (local; can hold ~60MB of node_modules)
|
||||
.opencode/
|
||||
|
||||
@@ -101,13 +101,16 @@ permission:
|
||||
- with no Apple Development identity the scripts fall back to ad-hoc; that
|
||||
still runs, but expect TCC prompts to reappear after every deploy
|
||||
|
||||
Deploys must run in a GUI session (a Terminal window on the machine): codesign
|
||||
reads the private key from the login keychain, and only the Aqua session can
|
||||
reach it. Agents/daemons run in launchd's Background domain, where codesign
|
||||
fails with `errSecInternalComponent` even while Keychain Access shows the
|
||||
keychain unlocked (`launchctl managername` reports `Background` vs `Aqua`).
|
||||
`sign-build.sh` warns about this before failing; running the same script from
|
||||
Terminal (or `security unlock-keychain` first) fixes it.
|
||||
codesign reads the private key from the login keychain, and that key is
|
||||
reachable only from a GUI (Aqua) session: an agent or daemon shell runs in
|
||||
launchd's Background domain, where codesign fails with `errSecInternalComponent`
|
||||
(and `security` reports `User interaction is not allowed`) even while Keychain
|
||||
Access shows the keychain unlocked. `security unlock-keychain` does not help
|
||||
there - from that domain it cannot prompt for the passphrase either. Two ways
|
||||
out: run the deploy from a Terminal window on the machine, or allow the key for
|
||||
all applications (Keychain Access -> the `Apple Development: ...` key -> Access
|
||||
Control -> "Allow all applications to access this item", which asks for the
|
||||
password once). `sign-build.sh` prints exactly this when codesign fails.
|
||||
|
||||
Agent sessions should also avoid recursive `$HOME` sweeps (`find ~`,
|
||||
`du -sh ~`, ...) unless they prune TCC-protected folders (`~/Music`,
|
||||
|
||||
+23
-12
@@ -39,19 +39,30 @@ if [ -z "$identity" ]; then
|
||||
fi
|
||||
echo "signing identity: $identity"
|
||||
|
||||
# codesign reads the private key from the login keychain, and only a GUI
|
||||
# (Aqua) session can reach it: processes started by launchd/agents live in
|
||||
# the Background domain and fail with errSecInternalComponent even while
|
||||
# Keychain Access shows the keychain unlocked. Warn early with the fix
|
||||
# instead of surfacing a bare codesign error. Ad-hoc signing needs no key.
|
||||
if [ "$identity" != "-" ] && [ "$(launchctl managername 2>/dev/null || true)" != "Aqua" ]; then
|
||||
echo "warning: not running in a GUI (Aqua) session; codesign cannot reach the login keychain." >&2
|
||||
echo "warning: run the deploy from a Terminal window on this machine," >&2
|
||||
echo "warning: or run 'security unlock-keychain' first. (errSecInternalComponent)" >&2
|
||||
fi
|
||||
|
||||
# Bun's linker signature is not suitable after installation; re-sign once.
|
||||
codesign --remove-signature "$build" 2>/dev/null || true
|
||||
codesign --force --sign "$identity" --identifier run.hapi.cli "$build"
|
||||
|
||||
if ! sign_error=$(codesign --force --sign "$identity" --identifier run.hapi.cli "$build" 2>&1); then
|
||||
printf '%s\n' "$sign_error" >&2
|
||||
# codesign reads the private key from the login keychain, and that key is
|
||||
# reachable only from a GUI (Aqua) session: an agent or daemon shell runs in
|
||||
# launchd's Background domain and gets errSecInternalComponent even while
|
||||
# Keychain Access shows the keychain unlocked. 'security unlock-keychain' is
|
||||
# no fix there either - it cannot prompt for the passphrase from that
|
||||
# domain. Do not guess the session up front (an SSH deploy that unlocked
|
||||
# first signs fine); explain only what actually failed.
|
||||
if [ "$identity" != "-" ]; then
|
||||
case "$sign_error" in
|
||||
*errSecInternalComponent*|*"User interaction is not allowed"*)
|
||||
echo "error: codesign cannot read the private key for $identity from the login keychain." >&2
|
||||
echo "error: run the deploy from a Terminal window on this machine, or allow that key" >&2
|
||||
echo "error: for all applications: Keychain Access -> the 'Apple Development: ...' key" >&2
|
||||
echo "error: -> Access Control -> 'Allow all applications to access this item'." >&2
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
codesign --verify --deep --strict "$build"
|
||||
echo "signed build ok"
|
||||
|
||||
Reference in New Issue
Block a user