Answer#
Three separate things, in this order:
- Code signing marks the app as coming from you. For distribution outside the Mac App Store, Apple's route is a Developer ID Application certificate from a paid Apple Developer account. Apps are signed with the hardened runtime enabled, which notarization requires.
- Notarization is an automatic check by Apple. You upload the signed app (in a zip, dmg or pkg) with the
notarytoolcommand; Apple scans it and replies accepted or rejected, with a log. - Stapling attaches the accepted ticket to your app, so macOS can verify it without network access.
The commands, as documented by Apple (not run here, placeholders in angle brackets):
# 1. sign the .app with the hardened runtime and a secure timestamp
codesign --force --options runtime --timestamp --sign "Developer ID Application: <Name> (<TEAMID>)" Notes.app
# 2. zip it for upload
ditto -c -k --keepParent Notes.app Notes.zip
# 3. upload and wait for the verdict (credentials were stored earlier with `xcrun notarytool store-credentials`)
xcrun notarytool submit Notes.zip --keychain-profile "<profile>" --wait
# 4. if it was rejected, read the log for the reasons
xcrun notarytool log <submission-id> --keychain-profile "<profile>"
# 5. attach the ticket to the app, then check it
xcrun stapler staple Notes.app
xcrun stapler validate Notes.appPractical points:
- Sign everything inside the bundle, including helper executables and libraries, before the outer app. Rejections often name one unsigned file.
- Do not change the bundle after signing. Even adding a file invalidates the signature.
- A Rust executable is a normal Mach-O file, so the tools treat it like any other once it is in a bundle (see the bundle layout thread).
- Do it in CI with the certificate and credentials in the CI system's secrets, on a macOS runner.
- Check the result on a clean Mac by downloading the file as a user would, rather than copying it over.
This thread does not claim how Gatekeeper behaves for any particular macOS version; read Apple's current documentation for that.
Common mistakes#
- Using the wrong certificate type. The Developer ID Application certificate is for apps outside the store; others are for the store or for installers.
- Notarizing an unsigned or non-hardened build.
- Staple the app you ship, not a copy made before stapling.
Related questions#
Do I need to notarize for testing on my own Mac?#
Not for your own builds, but anything you send to other people is judged by their Mac; sign and notarize the file you send.
Sources#
- Apple, Notarizing macOS software before distribution: https://developer.apple.com/documentation/security/notarizing-macos-software-before-distribution (listed by Apple; the page body could not be fetched as text here)
- Apple, Signing Mac software with Developer ID: https://developer.apple.com/developer-id/ (not fetched)