Skip to content

Commit 8363787

Browse files
committed
fix(release): restore account home for Apple tools
1 parent e6b863b commit 8363787

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

scripts/codesign-macos.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ for tool in codesign ditto mktemp mv plutil xcrun; do
5757
}
5858
done
5959

60+
# Go builds use an isolated HOME for reproducibility, but Apple security tools
61+
# resolve Keychain identities and notary profiles through the login account.
62+
# Restore only the system-owned account home inside this signing hook.
63+
release_user=$(/usr/bin/id -un)
64+
release_uid=$(/usr/bin/id -u)
65+
release_home=$(/usr/bin/dscl . -read "/Users/$release_user" NFSHomeDirectory | /usr/bin/sed 's/^NFSHomeDirectory: //')
66+
[[ "$release_home" == /* && "$release_home" != *$'\n'* && -d "$release_home" && "$(/usr/bin/stat -f %u "$release_home")" == "$release_uid" ]] || {
67+
echo "codesign: cannot resolve the trusted release account home" >&2
68+
exit 1
69+
}
70+
HOME=$release_home
71+
export HOME
72+
6073
binary_dir=$(cd "$(dirname "$binary")" && pwd)
6174
binary_name=$(basename "$binary")
6275
work_dir=$(mktemp -d "$binary_dir/.gog-notary.XXXXXX")

scripts/test-codesign-macos.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ EOF
1616
cat > "$tmp/bin/codesign" <<'EOF'
1717
#!/usr/bin/env bash
1818
set -euo pipefail
19+
printf 'codesign-home %s\n' "$HOME" >> "$RELEASE_TEST_LOG"
1920
printf 'codesign %s\n' "$*" >> "$RELEASE_TEST_LOG"
2021
if [[ " $* " == *' --display '* ]]; then
2122
{
@@ -61,6 +62,7 @@ EOF
6162
cat > "$tmp/bin/xcrun" <<'EOF'
6263
#!/usr/bin/env bash
6364
set -euo pipefail
65+
printf 'xcrun-home %s\n' "$HOME" >> "$RELEASE_TEST_LOG"
6466
printf 'xcrun %s\n' "$*" >> "$RELEASE_TEST_LOG"
6567
[[ "${MOCK_NOTARY_REJECT:-0}" != 1 ]] || exit 1
6668
printf '{"id":"12345678-1234-1234-1234-123456789abc","status":"%s"}\n' "${MOCK_NOTARY_STATUS:-Accepted}"
@@ -111,6 +113,8 @@ export GOG_OFFICIAL_RELEASE=1
111113
export CODESIGN_IDENTITY='Developer ID Application: OpenClaw Foundation (FWJYW4S8P8)'
112114
export CODESIGN_KEYCHAIN=/tmp/foundation-release.keychain-db
113115
export MAC_RELEASE_CODESIGN_KEYCHAIN=$CODESIGN_KEYCHAIN
116+
mkdir -p "$tmp/isolated-home"
117+
export HOME="$tmp/isolated-home"
114118

115119
reset_binary
116120
unset NOTARYTOOL_KEYCHAIN_PROFILE
@@ -187,6 +191,13 @@ grep -Fq -- '--timestamp --options runtime --identifier com.steipete.gogcli.gog'
187191
grep -Fq -- '--keychain /tmp/foundation-release.keychain-db --sign Developer ID Application: OpenClaw Foundation (FWJYW4S8P8)' "$log"
188192
grep -Fq -- 'notarytool submit' "$log"
189193
grep -Fq -- '--keychain-profile test-profile --no-s3-acceleration --wait --output-format json' "$log"
194+
expected_release_home=$(/usr/bin/dscl . -read "/Users/$(/usr/bin/id -un)" NFSHomeDirectory | /usr/bin/sed 's/^NFSHomeDirectory: //')
195+
grep -Fq "codesign-home $expected_release_home" "$log"
196+
grep -Fq "xcrun-home $expected_release_home" "$log"
197+
if grep -Fq "$tmp/isolated-home" "$log"; then
198+
echo "codesign test: Apple security tools retained the isolated build HOME" >&2
199+
exit 1
200+
fi
190201
grep -Fq -- '--verify --strict -R=identifier "com.steipete.gogcli.gog"' "$log"
191202
grep -Fq -- 'codesign -d -r-' "$log"
192203
grep -Fq -- '--verify --strict --check-notarization -R=notarized' "$log"

0 commit comments

Comments
 (0)