The short answer
Short answer: per Electron's official docs, a macOS app has to be code signed first and then submitted to Apple for notarization before release. Signing can only be done on macOS, and notarization is started automatically by the packaging tool after signing. Requesting certificates and preparing credentials can be done in a browser on any operating system.
Which steps require macOS
What must be on macOS
- Code signing. electron-builder's docs say in so many words that macOS code signing works only on macOS.
@electron/osx-sign, which Electron Forge uses underneath, likewise depends on the system's signing tools and keychain. - Starting notarization through the toolchain. Forge's docs say notarization requires Xcode.
What can be prepared on any operating system
- Join the Apple Developer Program (listed as a prerequisite in Electron's docs).
- Create a
Developer ID Applicationcertificate in the developer account: it is for apps distributed outside the Mac App Store. Apple states that only the team's Account Holder can generate Developer ID certificates. - Generate an app-specific password, or create an App Store Connect API key.
- Write the signing and notarization configuration into the project and commit it.
Forge's docs give the reason both steps are needed: starting with macOS 10.15, an app has to be both signed and notarized for users to run it without turning off additional security checks.
How to do it on a remote Mac
Install the certificate into the remote Mac's keychain
Generate a certificate signing request on the remote Mac, create the certificate in the developer account, then download and install it. Alternatively, import an existing
.p12. Then confirm:security find-identity -p codesigning -vYou are ready only when an entry starting with Developer ID Application appears in the list.
Electron Forge: turn on osxSign
Add
osxSign: {}topackagerConfigin the Forge config. The docs suggest starting from an empty object, since the defaults work as-is in most cases. Forge signs at the Package step, not at the Make step.Electron Forge: configure osxNotarize
Choose one of three authentication methods:
- Apple ID:
appleId,appleIdPassword(an app-specific password),teamId. - API key:
appleApiKey,appleApiKeyId,appleApiIssuer. - Keychain profile:
keychainProfile.
Read the values from environment variables (for example
process.env.APPLE_ID) and do not hard-code them in the config file. On a remote Mac you use long term, the third is the least hassle: first store the credentials in the keychain under a name with Apple'sxcrun notarytool store-credentials, and only that name appears in the config.- Apple ID:
electron-builder: certificate and notarization variables
When the certificate is already in the keychain, electron-builder looks up a usable signing identity from the keychain. Notarization credentials are supplied through environment variables, in any one of three sets:
APPLE_ID,APPLE_APP_SPECIFIC_PASSWORD,APPLE_TEAM_ID.APPLE_API_KEY(path to the.p8file),APPLE_API_KEY_ID,APPLE_API_ISSUER.APPLE_KEYCHAIN_PROFILE,APPLE_TEAM_ID, optionally withAPPLE_KEYCHAIN.
Per the notarization docs, when
mac.notarizeis not set, it notarizes if credentials are present and skips with a warning if not. Setting it totruemakes the build fail outright when credentials are missing, which suits production releases.Keep the hardened runtime on
Notarization requires Hardened Runtime to be enabled. electron-builder turns it on by default for regular macOS builds. When you need extra entitlements (camera, microphone and so on), supply your own entitlements file. Note the docs' reminder: a custom file replaces the default file instead of being appended to it, so you have to write out every entry that should be there. In Forge, set this with
optionsForFileunderosxSign.Build and verify
Build again. After notarization succeeds, electron-builder automatically staples the notarization ticket to the app so it can be verified offline too. If you suspect stapling did not succeed, the docs suggest checking with
xcrun stapler validate. Finally, uploading the dmg and then downloading and opening it on another Mac is the most straightforward verification.
FAQ
Notarization reports "the binary is not signed with a valid Developer ID certificate"
electron-builder's troubleshooting notes point out that this usually means a Mac App Store certificate was used for a package meant for website distribution. Certificates are not interchangeable between the two distribution routes. Switch to Developer ID Application.
Notarization reports an invalid Info.plist or an unsigned file
A common cause is an unsigned third-party binary in the package, such as a command-line tool shipped with the app or an executable inside a native module. electron-builder's docs suggest signing it in an afterSign hook. You can also download the log with Apple's xcrun notarytool log, which lists exactly which file it is.
Does notarization have to be submitted from a Mac?
Apple separately offers the Notary API for submitting notarization over a web interface, and its documentation says this is so you do not depend on Xcode. But the app being notarized must already be signed, and signing cannot leave macOS, so overall you still need a Mac or a macOS build machine.
What do I need to take care of before the rental ends?
Export the certificate together with its private key as a .p12 and keep it yourself, delete the .p8 key file from the machine and the notarization credentials stored in the keychain, and sign out of your Apple Account. Data is not kept once the machine is reclaimed, and backups are your responsibility. For notes on signing in to your account, see can I sign in to my own developer account.
Related
- Can I build a macOS installer for an Electron app on Windows or Linux?
- How do I publish an Electron app to the Mac App Store or distribute a dmg without a Mac?
- How do I build a universal Electron app for both Intel and Apple silicon Macs?
- Can I sign in with my own Apple Developer account on a rented Mac?
Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support