Skip to content

Commit 4d0fdc8

Browse files
authored
MONGOSH-278 - Notarize macOS package (#342)
1 parent 071e4a4 commit 4d0fdc8

File tree

9 files changed

+58
-33
lines changed

9 files changed

+58
-33
lines changed

.evergreen.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ variables:
3030
-c 'cd /tmp/build && npm run evergreen-release package'
3131
else
3232
npm run evergreen-release package
33+
if [ `uname` == Darwin ]; then
34+
# Verify signing
35+
spctl -a -vvv -t install dist/mongosh
36+
fi
3337
fi
3438
RELEASE_MONGOSH
3539

config/build.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module.exports = {
6464
appleUser: process.env.APPLE_DEV_USER,
6565
applePassword: process.env.APPLE_DEV_PASSWORD,
6666
appleAppIdentity: process.env.APPLE_APP_IDENTITY,
67+
entitlementsFile: path.resolve(__dirname, 'macos-entitlements.xml'),
6768
isCi: process.env.IS_CI === 'true',
6869
isPatch: process.env.IS_PATCH === 'true',
6970
platform: os.platform(),

config/macos-entitlements.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.allow-jit</key>
6+
<true/>
7+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8+
<true/>
9+
<key>com.apple.security.cs.disable-executable-page-protection</key>
10+
<true/>
11+
</dict>
12+
</plist>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"mocha": "^7.1.2",
9696
"mongodb-js-precommit": "^2.0.0",
9797
"mongodb-runner": "^4.7.5",
98-
"node-codesign": "durran/node-codesign",
98+
"node-codesign": "github:addaleax/node-codesign",
9999
"parcel-bundler": "^1.12.4",
100100
"pkg": "^4.4.3",
101101
"pkg-deb": "^1.1.1",
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import compileExec from './compile-exec';
22
import { createTarball, TarballFile } from './tarball';
33
import Config from './config';
4+
import Platform from './platform';
5+
import os from 'os';
6+
import macOSSignAndNotarize from './macos-sign';
47

58
export default async function compileAndZipExecutable(config: Config): Promise<TarballFile> {
69
const executable = await compileExec(
@@ -12,15 +15,21 @@ export default async function compileAndZipExecutable(config: Config): Promise<T
1215
config.segmentKey,
1316
);
1417

15-
// Zip the executable.
16-
const artifact = await createTarball(
17-
executable,
18-
config.outputDir,
19-
config.buildVariant,
20-
config.version,
21-
config.rootDir
22-
);
18+
const runCreateTarball = async(): Promise<TarballFile> => {
19+
return await createTarball(
20+
executable,
21+
config.outputDir,
22+
config.buildVariant,
23+
config.version,
24+
config.rootDir
25+
);
26+
};
2327

24-
// add artifcats for .rpm and .msi
25-
return artifact;
28+
// Zip the executable, or, on macOS, do it as part of the notarization/signing
29+
// step.
30+
if (os.platform() === Platform.MacOs && !config.dryRun) {
31+
return await macOSSignAndNotarize(executable, config, runCreateTarball);
32+
} else {
33+
return await runCreateTarball();
34+
}
2635
}

packages/build/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default interface Config {
2121
appleUser?: string;
2222
applePassword?: string;
2323
appleAppIdentity?: string;
24+
entitlementsFile?: string;
2425
isCi?: boolean;
2526
platform?: string;
2627
execNodeVersion?: string;

packages/build/src/macos-sign.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import util from 'util';
33
import codesign from 'node-codesign';
44
import { notarize as nodeNotarize } from 'electron-notarize';
55
import Config from './config';
6-
import { createTarball } from './tarball';
6+
import { createTarball, TarballFile } from './tarball';
77

88
/**
99
* Notarizes the zipped mongosh. Will send the tarball to Apple and poll apple
@@ -29,31 +29,29 @@ const notarize = (bundleId: string, artifact: string, user: string, password: st
2929
* @param {string} executable - The mongosh executable.
3030
* @param {string} identity - The apple developer identity.
3131
*/
32-
const sign = (executable: string, identity: string) => {
33-
return new Promise((resolve, reject) => {
34-
codesign({ identity: identity, appPath: executable }, (err, paths) => {
35-
if (err) {
36-
reject(err);
37-
} else {
38-
resolve(err);
39-
}
40-
});
32+
const sign = (executable: string, identity: string, entitlementsFile: string) => {
33+
return util.promisify(codesign)({
34+
identity: identity,
35+
appPath: executable,
36+
entitlements: entitlementsFile,
4137
});
4238
};
4339

44-
const publish = async(executable: string, artifact: string, platform: string, config: Config) => {
45-
console.log('mongosh: removing unsigned tarball:', artifact);
46-
await util.promisify(fs.unlink)(artifact);
40+
const macOSSignAndNotarize = async(
41+
executable: string,
42+
config: Config,
43+
runCreateTarball: () => Promise<TarballFile>): Promise<TarballFile> => {
44+
4745
console.log('mongosh: signing:', executable);
48-
await sign(executable, config.appleAppIdentity).
49-
catch((e) => { console.error(e); throw e; });
46+
await sign(executable, config.appleAppIdentity, config.entitlementsFile);
5047
console.log('mongosh: notarizing and creating tarball:', executable);
51-
await createTarball(executable, config.outputDir, platform, config.version, config.rootDir);
48+
const artifact = await runCreateTarball();
5249
await notarize(
5350
config.bundleId,
54-
artifact,
51+
artifact.path,
5552
config.appleUser,
56-
config.applePassword).catch((e) => { console.error(e); throw e; });
53+
config.applePassword);
54+
return artifact;
5755
};
5856

59-
export default publish;
57+
export default macOSSignAndNotarize;

scripts/evergreen-release.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const runRelease = async() => {
1111
const command = process.argv[2];
1212

1313
if (!['package', 'publish'].includes(command)) {
14-
throw new Error('USAGE: npm run evergreen-release <package|publish> [--dry]');
14+
throw new Error('USAGE: npm run evergreen-release -- <package|publish> [--dry]');
1515
}
1616

1717
if (process.argv.includes('--dry')) {

0 commit comments

Comments
 (0)