Skip to content

Commit 15bffa0

Browse files
authored
feat: Make notarization with Apple ID more usable (altool is no longer supported) (#8159)
Previously, we supported notarizing with the legacy `altool` or the new `notarytool` API. The legacy tool has since been decommissioned. 1. Look at `APPLE_TEAM_ID` environment variable for getting the team to notarize as. Previously, when authenticating with an Apple ID, this property was used to determine whether to notarize with the old or new API. It's confusing to have the authentication split across these two places. 2. Mark legacy notarize API as deprecated and remove old validation.
1 parent 8e36be1 commit 15bffa0

5 files changed

Lines changed: 33 additions & 59 deletions

File tree

.changeset/moody-years-poke.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"app-builder-lib": minor
3+
"electron-builder": minor
4+
---
5+
6+
Use `APPLE_TEAM_ID` env var when using notarizing with `APPLE_ID`.
7+
Deprecate legacy (`altool`) notarization API.

docs/configuration/mac.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ The top-level [mac](configuration.md#Configuration-mac) key contains set of opti
110110
<p>This option has no effect unless building for “universal” arch and applies only if <code>mergeASARs</code> is <code>true</code>.</p>
111111
</li>
112112
<li>
113-
<p><code id="MacConfiguration-notarize">notarize</code> <a href="#NotarizeLegacyOptions">NotarizeLegacyOptions</a> | <a href="#NotarizeNotaryOptions">NotarizeNotaryOptions</a> | Boolean | “undefined” - Options to use for @electron/notarize (ref: <a href="https://github.com/electron/notarize">https://github.com/electron/notarize</a>). Supports both <code>legacy</code> and <code>notarytool</code> notarization tools. Use <code>false</code> to explicitly disable</p>
114-
<p>Note: In order to activate the notarization step You MUST specify one of the following via environment variables: 1. <code>APPLE_API_KEY</code>, <code>APPLE_API_KEY_ID</code> and <code>APPLE_API_ISSUER</code>. 2. <code>APPLE_ID</code> and <code>APPLE_APP_SPECIFIC_PASSWORD</code> 3. <code>APPLE_KEYCHAIN</code> and <code>APPLE_KEYCHAIN_PROFILE</code></p>
113+
<p><code id="MacConfiguration-notarize">notarize</code> <a href="#NotarizeLegacyOptions">NotarizeLegacyOptions</a> | <a href="#NotarizeNotaryOptions">NotarizeNotaryOptions</a> | Boolean | “undefined” - Options to use for @electron/notarize (ref: <a href="https://github.com/electron/notarize">https://github.com/electron/notarize</a>). Use <code>false</code> to explicitly disable</p>
114+
<p>Note: In order to activate the notarization step You MUST specify one of the following via environment variables: 1. <code>APPLE_API_KEY</code>, <code>APPLE_API_KEY_ID</code> and <code>APPLE_API_ISSUER</code>. 2. <code>APPLE_ID</code>, <code>APPLE_APP_SPECIFIC_PASSWORD</code>, and <code>APPLE_TEAM_ID</code> 3. <code>APPLE_KEYCHAIN</code> and <code>APPLE_KEYCHAIN_PROFILE</code></p>
115115
<p>For security reasons it is recommended to use the first option (see <a href="https://github.com/electron-userland/electron-builder/issues/7859">https://github.com/electron-userland/electron-builder/issues/7859</a>)</p>
116116
</li>
117117
</ul>
@@ -124,7 +124,7 @@ The top-level [mac](configuration.md#Configuration-mac) key contains set of opti
124124
<h2 id="notarizenotaryoptions">NotarizeNotaryOptions</h2>
125125
<p>undefined</p>
126126
<ul>
127-
<li><strong><code id="NotarizeNotaryOptions-teamId">teamId</code></strong> String - The team ID you want to notarize under for when using <code>notarytool</code></li>
127+
<li tag.description=""><code id="NotarizeNotaryOptions-teamId">teamId</code> String - The team ID you want to notarize under for when using <code>notarytool</code> Deprecated:</li>
128128
</ul>
129129

130130
<!-- end of generated block -->

packages/app-builder-lib/scheme.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,9 +3687,6 @@
36873687
"type": "string"
36883688
}
36893689
},
3690-
"required": [
3691-
"teamId"
3692-
],
36933690
"type": "object"
36943691
},
36953692
"NsisOptions": {

packages/app-builder-lib/src/macPackager.ts

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AppInfo } from "./appInfo"
1010
import { CertType, CodeSigningInfo, createKeychain, findIdentity, Identity, isSignAllowed, removeKeychain, reportError, sign } from "./codeSign/macCodeSign"
1111
import { DIR_TARGET, Platform, Target } from "./core"
1212
import { AfterPackContext, ElectronPlatformName } from "./index"
13-
import { MacConfiguration, MasConfiguration, NotarizeLegacyOptions, NotarizeNotaryOptions } from "./options/macOptions"
13+
import { MacConfiguration, MasConfiguration, NotarizeNotaryOptions } from "./options/macOptions"
1414
import { Packager } from "./packager"
1515
import { chooseNotNull, resolveFunction, PlatformPackager } from "./platformPackager"
1616
import { ArchiveTarget } from "./targets/ArchiveTarget"
@@ -20,13 +20,7 @@ import { isMacOsHighSierra } from "./util/macosVersion"
2020
import { getTemplatePath } from "./util/pathManager"
2121
import * as fs from "fs/promises"
2222
import { notarize, NotarizeOptions } from "@electron/notarize"
23-
import {
24-
LegacyNotarizePasswordCredentials,
25-
LegacyNotarizeStartOptions,
26-
NotaryToolStartOptions,
27-
NotaryToolCredentials,
28-
NotaryToolKeychainCredentials,
29-
} from "@electron/notarize/lib/types"
23+
import { NotaryToolKeychainCredentials } from "@electron/notarize/lib/types"
3024

3125
export type CustomMacSignOptions = SignOptions
3226
export type CustomMacSign = (configuration: CustomMacSignOptions, packager: MacPackager) => Promise<void>
@@ -510,9 +504,18 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
510504
log.info(null, "notarization successful")
511505
}
512506

513-
private getNotarizeOptions(appPath: string) {
507+
private getNotarizeOptions(appPath: string): NotarizeOptions | undefined {
508+
let teamId = process.env.APPLE_TEAM_ID
514509
const appleId = process.env.APPLE_ID
515510
const appleIdPassword = process.env.APPLE_APP_SPECIFIC_PASSWORD
511+
const options = this.platformSpecificBuildOptions.notarize
512+
const tool = "notarytool"
513+
514+
const optionsTeamId = (options as NotarizeNotaryOptions)?.teamId
515+
if (optionsTeamId) {
516+
log.warn(null, "Please specify notarization Team ID in the `APPLE_TEAM_ID` env var instead of `notarize.teamId`")
517+
teamId = optionsTeamId
518+
}
516519

517520
// option 1: app specific password
518521
if (appleId || appleIdPassword) {
@@ -522,7 +525,10 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
522525
if (!appleIdPassword) {
523526
throw new InvalidConfigurationError(`APPLE_APP_SPECIFIC_PASSWORD env var needs to be set`)
524527
}
525-
return this.generateNotarizeOptions(appPath, { appleId, appleIdPassword })
528+
if (!teamId) {
529+
throw new InvalidConfigurationError(`APPLE_TEAM_ID env var needs to be set`)
530+
}
531+
return { tool, appPath, appleId, appleIdPassword, teamId }
526532
}
527533

528534
// option 2: API key
@@ -533,7 +539,7 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
533539
if (!appleApiKey || !appleApiKeyId || !appleApiIssuer) {
534540
throw new InvalidConfigurationError(`Env vars APPLE_API_KEY, APPLE_API_KEY_ID and APPLE_API_ISSUER need to be set`)
535541
}
536-
return this.generateNotarizeOptions(appPath, undefined, { appleApiKey, appleApiKeyId, appleApiIssuer })
542+
return { tool, appPath, appleApiKey, appleApiKeyId, appleApiIssuer }
537543
}
538544

539545
// option 3: keychain
@@ -544,50 +550,12 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
544550
if (keychain) {
545551
args = { ...args, keychain }
546552
}
547-
return this.generateNotarizeOptions(appPath, undefined, args)
553+
return { tool, appPath, ...args }
548554
}
549555

550556
// if no credentials provided, skip silently
551557
return undefined
552558
}
553-
554-
private generateNotarizeOptions(appPath: string, legacyLogin?: LegacyNotarizePasswordCredentials, notaryToolLogin?: NotaryToolCredentials): NotarizeOptions | undefined {
555-
const options = this.platformSpecificBuildOptions.notarize
556-
if (typeof options === "boolean" && legacyLogin) {
557-
const proj: LegacyNotarizeStartOptions = {
558-
appPath,
559-
...legacyLogin,
560-
appBundleId: this.appInfo.id,
561-
}
562-
return proj
563-
}
564-
const teamId = (options as NotarizeNotaryOptions)?.teamId
565-
if ((teamId || options === true) && (legacyLogin || notaryToolLogin)) {
566-
const proj: NotaryToolStartOptions = {
567-
appPath,
568-
...(legacyLogin ?? notaryToolLogin!),
569-
teamId,
570-
}
571-
return { tool: "notarytool", ...proj }
572-
}
573-
if (legacyLogin) {
574-
const { appBundleId, ascProvider } = options as NotarizeLegacyOptions
575-
return {
576-
appPath,
577-
...legacyLogin,
578-
appBundleId: appBundleId || this.appInfo.id,
579-
ascProvider: ascProvider || undefined,
580-
}
581-
}
582-
if (notaryToolLogin) {
583-
return {
584-
tool: "notarytool",
585-
appPath,
586-
...notaryToolLogin,
587-
}
588-
}
589-
return undefined
590-
}
591559
}
592560

593561
function getCertificateTypes(isMas: boolean, isDevelopment: boolean): CertType[] {

packages/app-builder-lib/src/options/macOptions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,19 @@ export interface MacConfiguration extends PlatformSpecificBuildOptions {
214214

215215
/**
216216
* Options to use for @electron/notarize (ref: https://github.com/electron/notarize).
217-
* Supports both `legacy` and `notarytool` notarization tools. Use `false` to explicitly disable
217+
* Use `false` to explicitly disable
218218
*
219219
* Note: In order to activate the notarization step You MUST specify one of the following via environment variables:
220220
* 1. `APPLE_API_KEY`, `APPLE_API_KEY_ID` and `APPLE_API_ISSUER`.
221-
* 2. `APPLE_ID` and `APPLE_APP_SPECIFIC_PASSWORD`
221+
* 2. `APPLE_ID`, `APPLE_APP_SPECIFIC_PASSWORD`, and `APPLE_TEAM_ID`
222222
* 3. `APPLE_KEYCHAIN` and `APPLE_KEYCHAIN_PROFILE`
223223
*
224224
* For security reasons it is recommended to use the first option (see https://github.com/electron-userland/electron-builder/issues/7859)
225225
*/
226226
readonly notarize?: NotarizeLegacyOptions | NotarizeNotaryOptions | boolean | null
227227
}
228228

229+
/** @deprecated */
229230
export interface NotarizeLegacyOptions {
230231
/**
231232
* The app bundle identifier your Electron app is using. E.g. com.github.electron. Useful if notarization ID differs from app ID (unlikely).
@@ -242,8 +243,9 @@ export interface NotarizeLegacyOptions {
242243
export interface NotarizeNotaryOptions {
243244
/**
244245
* The team ID you want to notarize under for when using `notarytool`
246+
* @deprecated Set the `APPLE_TEAM_ID` environment variable instead
245247
*/
246-
readonly teamId: string
248+
readonly teamId?: string
247249
}
248250

249251
export interface DmgOptions extends TargetSpecificOptions {

0 commit comments

Comments
 (0)