Skip to content

Commit e0c71bc

Browse files
UlisesGasconaduh95
authored andcommitted
tools: notarize bin/node in the darwin tarballs
The binary tarball target only codesigns bin/node. Notarization runs only for the pkg, and tools/osx-notarize.sh only knows how to submit a pkg, so every darwin tarball binary ships signed but without a ticket. Gatekeeper then applies a full trust evaluation to each process spawned through it, which slows down every CLI shim on macOS. Make tools/osx-notarize.sh take a path instead of a version id. A .pkg keeps the existing flow. Any other file is treated as a Mach-O binary: it is zipped with ditto, submitted with notarytool, and the ticket is verified with `codesign --verify -R=notarized` using the existing retry helper. spctl cannot be used for that check, it rejects command line tools as "not an app". The binary itself is not modified, so published checksums do not change. A bare version id is still accepted and resolved to node-<version>.pkg for the release branches. Call the script from the binary target after codesign. It is a no-op unless the NOTARIZATION_* variables are exported, so the tarball jobs keep behaving as today until the release job injects them. Refs: #67140 Refs: nodejs/build#3538 Refs: nodejs/build#4545 Refs: #66855 Assisted-by: Claude Assisted-by: Codex Signed-off-by: Ulises Gascon <ulisesgascongonzalez@gmail.com> PR-URL: #67143 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Stewart X Addison <sxa@redhat.com>
1 parent 17be7f1 commit e0c71bc

2 files changed

Lines changed: 116 additions & 46 deletions

File tree

‎Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ $(PKG): release-only
12471247
--resources $(MACOSOUTDIR)/installer/productbuild/Resources \
12481248
--package-path $(MACOSOUTDIR)/pkgs ./$(PKG)
12491249
SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" sh tools/osx-productsign.sh
1250-
sh tools/osx-notarize.sh $(FULLVERSION)
1250+
sh tools/osx-notarize.sh $(PKG)
12511251

12521252
.PHONY: pkg
12531253
pkg: $(PKG) ## Build the macOS installer for releases.
@@ -1433,6 +1433,7 @@ else
14331433
endif
14341434
ifeq ($(OSTYPE),darwin)
14351435
SIGN="$(CODESIGN_CERT)" PKGDIR="$(BINARYNAME)" sh tools/osx-codesign.sh
1436+
sh tools/osx-notarize.sh $(BINARYNAME)/bin/node
14361437
endif
14371438
tar -cf $(BINARYNAME).tar $(BINARYNAME)
14381439
$(RM) -r $(BINARYNAME)

‎tools/osx-notarize.sh‎

Lines changed: 114 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,107 @@
11
#!/bin/sh
22

3-
# Notarize a generated node-<version>.pkg file as an Apple requirement for installation on macOS Catalina and later, as validated by Gatekeeper.
3+
# Notarize a macOS release artifact as an Apple requirement for running or
4+
# installing on macOS Catalina and later, as validated by Gatekeeper.
45
# Uses notarytool and requires Xcode >= 13.0.
6+
#
7+
# Usage: osx-notarize.sh <path>
8+
#
9+
# <path> ending in .pkg: the installer is submitted as is, assessed with
10+
# spctl and the notarization ticket is stapled to it.
11+
# any other <path>: a Mach-O binary, such as bin/node from the release
12+
# tarball. Apple only accepts zip, dmg or pkg submissions, so the binary
13+
# is zipped for the upload and the zip is discarded afterwards. A bare
14+
# binary cannot carry a stapled ticket; Gatekeeper fetches it online by
15+
# the code directory hash, so the binary itself is left untouched and the
16+
# published checksums do not change.
17+
#
18+
# For backwards compatibility a bare version id (for example v26.13.0) is
19+
# accepted and resolved to node-<version>.pkg.
520

6-
pkgid="$1"
21+
# The notarization ticket can take a while to become available from Apple's
22+
# servers after notarytool reports "Accepted", so retry with backoff.
23+
retry() {
24+
delay=15
25+
attempt=1
26+
while ! "$@"; do
27+
if [ "$attempt" -ge 6 ]; then
28+
return 1
29+
fi
30+
echo "Attempt $attempt failed, retrying in ${delay}s..."
31+
sleep "$delay"
32+
attempt=$((attempt + 1))
33+
delay=$((delay * 2))
34+
done
35+
}
36+
37+
submit() {
38+
echo "Submitting $1 for notarization..."
39+
if xcrun notarytool submit \
40+
--keychain-profile "NODE_RELEASE_PROFILE" \
41+
--wait \
42+
"$1"; then
43+
echo "Notarization $1 submitted successfully."
44+
else
45+
echo "Notarization $1 failed."
46+
return 1
47+
fi
48+
}
49+
50+
# Remove the upload zip on every exit path, including a failed ditto or an
51+
# interrupted build, the same way the dep_updaters scripts clean their
52+
# workspace. $zip is only set by notarize_binary.
53+
cleanup() {
54+
EXIT_CODE=$?
55+
if [ -n "$zip" ]; then
56+
rm -f "$zip"
57+
fi
58+
exit $EXIT_CODE
59+
}
60+
61+
notarize_pkg() {
62+
submit "$1" || exit 1
63+
64+
if ! retry xcrun spctl --assess --type install --context context:primary-signature --ignore-cache --verbose=2 "$1"; then
65+
echo "error: Signature will not be accepted by Gatekeeper!" 1>&2
66+
exit 1
67+
fi
68+
echo "Verification was successful."
69+
70+
if ! retry xcrun stapler staple "$1"; then
71+
echo "error: Stapling $1 failed." 1>&2
72+
exit 1
73+
fi
74+
echo "Stapler was successful."
75+
}
76+
77+
notarize_binary() {
78+
# ditto preserves the code signature and resource forks, which plain zip
79+
# does not, so it is the archiver Apple documents for notarization uploads.
80+
# The zip only exists for the upload and is removed by cleanup.
81+
zip="$1.notarize.zip"
82+
rm -f "$zip"
83+
if ! ditto -c -k --keepParent "$1" "$zip"; then
84+
echo "error: Could not create $zip for submission." 1>&2
85+
exit 1
86+
fi
87+
88+
submit "$zip" || exit 1
89+
rm -f "$zip"
90+
91+
# There is nothing to staple to a bare binary, so the only way to confirm
92+
# the ticket is live is to have codesign look it up. spctl cannot be used
93+
# here: it rejects command line tools with "does not seem to be an app".
94+
if ! retry codesign --verify --verbose=2 -R=notarized "$1"; then
95+
echo "error: $1 will not be accepted by Gatekeeper!" 1>&2
96+
exit 1
97+
fi
98+
echo "Verification was successful."
99+
}
7100

8-
if [ -z "$pkgid" ]; then
9-
echo "Usage: $0 <pkgid>"
101+
target="$1"
102+
103+
if [ -z "$target" ]; then
104+
echo "Usage: $0 <path-to-pkg-or-binary>"
10105
exit 1
11106
fi
12107

@@ -26,6 +121,16 @@ if [ -z "$NOTARIZATION_TEAM_ID" ]; then
26121
exit 0
27122
fi
28123

124+
# Legacy call form: a version id instead of a path.
125+
if [ ! -e "$target" ] && [ -e "node-$target.pkg" ]; then
126+
target="node-$target.pkg"
127+
fi
128+
129+
if [ ! -e "$target" ]; then
130+
echo "error: $target does not exist." 1>&2
131+
exit 1
132+
fi
133+
29134
echo "Notarization process is done with Notarytool."
30135

31136
if ! command -v xcrun notarytool > /dev/null
@@ -34,45 +139,9 @@ then
34139
exit 1
35140
fi
36141

37-
echo "Submitting node-$pkgid.pkg for notarization..."
38-
39-
xcrun notarytool submit \
40-
--keychain-profile "NODE_RELEASE_PROFILE" \
41-
--wait \
42-
"node-$pkgid.pkg"
43-
44-
if [ $? -eq 0 ]; then
45-
echo "Notarization node-$pkgid.pkg submitted successfully."
46-
else
47-
echo "Notarization node-$pkgid.pkg failed."
48-
exit 1
49-
fi
50-
51-
# The notarization ticket can take a while to become available from Apple's
52-
# servers after notarytool reports "Accepted", so retry with backoff.
53-
retry() {
54-
delay=15
55-
attempt=1
56-
while ! "$@"; do
57-
if [ "$attempt" -ge 6 ]; then
58-
return 1
59-
fi
60-
echo "Attempt $attempt failed, retrying in ${delay}s..."
61-
sleep "$delay"
62-
attempt=$((attempt + 1))
63-
delay=$((delay * 2))
64-
done
65-
}
66-
67-
if ! retry xcrun spctl --assess --type install --context context:primary-signature --ignore-cache --verbose=2 "node-$pkgid.pkg"; then
68-
echo "error: Signature will not be accepted by Gatekeeper!" 1>&2
69-
exit 1
70-
else
71-
echo "Verification was successful."
72-
fi
142+
trap cleanup INT TERM EXIT
73143

74-
if ! retry xcrun stapler staple "node-$pkgid.pkg"; then
75-
echo "error: Stapling node-$pkgid.pkg failed." 1>&2
76-
exit 1
77-
fi
78-
echo "Stapler was successful."
144+
case "$target" in
145+
*.pkg) notarize_pkg "$target" ;;
146+
*) notarize_binary "$target" ;;
147+
esac

0 commit comments

Comments
 (0)