Skip to content

Commit a67d9bc

Browse files
committed
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>
1 parent 502c117 commit a67d9bc

2 files changed

Lines changed: 92 additions & 28 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: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
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+
target="$1"
722

8-
if [ -z "$pkgid" ]; then
9-
echo "Usage: $0 <pkgid>"
23+
if [ -z "$target" ]; then
24+
echo "Usage: $0 <path-to-pkg-or-binary>"
1025
exit 1
1126
fi
1227

@@ -26,6 +41,21 @@ if [ -z "$NOTARIZATION_TEAM_ID" ]; then
2641
exit 0
2742
fi
2843

44+
# Legacy call form: a version id instead of a path.
45+
if [ ! -e "$target" ] && [ -e "node-$target.pkg" ]; then
46+
target="node-$target.pkg"
47+
fi
48+
49+
if [ ! -e "$target" ]; then
50+
echo "error: $target does not exist." 1>&2
51+
exit 1
52+
fi
53+
54+
case "$target" in
55+
*.pkg) kind=pkg ;;
56+
*) kind=binary ;;
57+
esac
58+
2959
echo "Notarization process is done with Notarytool."
3060

3161
if ! command -v xcrun notarytool > /dev/null
@@ -34,20 +64,6 @@ then
3464
exit 1
3565
fi
3666

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-
5167
# The notarization ticket can take a while to become available from Apple's
5268
# servers after notarytool reports "Accepted", so retry with backoff.
5369
retry() {
@@ -64,15 +80,62 @@ retry() {
6480
done
6581
}
6682

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
83+
submit() {
84+
echo "Submitting $1 for notarization..."
85+
if xcrun notarytool submit \
86+
--keychain-profile "NODE_RELEASE_PROFILE" \
87+
--wait \
88+
"$1"; then
89+
echo "Notarization $1 submitted successfully."
90+
else
91+
echo "Notarization $1 failed."
92+
return 1
93+
fi
94+
}
95+
96+
if [ "$kind" = "pkg" ]; then
97+
submit "$target" || exit 1
98+
99+
if ! retry xcrun spctl --assess --type install --context context:primary-signature --ignore-cache --verbose=2 "$target"; then
100+
echo "error: Signature will not be accepted by Gatekeeper!" 1>&2
101+
exit 1
102+
else
103+
echo "Verification was successful."
104+
fi
105+
106+
if ! retry xcrun stapler staple "$target"; then
107+
echo "error: Stapling $target failed." 1>&2
108+
exit 1
109+
fi
110+
echo "Stapler was successful."
70111
else
71-
echo "Verification was successful."
72-
fi
112+
# ditto preserves the code signature and resource forks, which plain zip
113+
# does not, so it is the archiver Apple documents for notarization uploads.
114+
# The zip only exists for the upload. Remove it on every exit path,
115+
# including a failed ditto or an interrupted build, the same way the
116+
# dep_updaters scripts clean their workspace.
117+
zip="$target.notarize.zip"
118+
cleanup () {
119+
EXIT_CODE=$?
120+
rm -f "$zip"
121+
exit $EXIT_CODE
122+
}
123+
trap cleanup INT TERM EXIT
124+
rm -f "$zip"
125+
if ! ditto -c -k --keepParent "$target" "$zip"; then
126+
echo "error: Could not create $zip for submission." 1>&2
127+
exit 1
128+
fi
73129

74-
if ! retry xcrun stapler staple "node-$pkgid.pkg"; then
75-
echo "error: Stapling node-$pkgid.pkg failed." 1>&2
76-
exit 1
130+
submit "$zip" || exit 1
131+
rm -f "$zip"
132+
133+
# There is nothing to staple to a bare binary, so the only way to confirm
134+
# the ticket is live is to have codesign look it up. spctl cannot be used
135+
# here: it rejects command line tools with "does not seem to be an app".
136+
if ! retry codesign --verify --verbose=2 -R=notarized "$target"; then
137+
echo "error: $target will not be accepted by Gatekeeper!" 1>&2
138+
exit 1
139+
fi
140+
echo "Verification was successful."
77141
fi
78-
echo "Stapler was successful."

0 commit comments

Comments
 (0)