Skip to content

Commit d6072dc

Browse files
Trevor159Evergreen Agent
authored andcommitted
SERVER-75033 Capture core dumps from test failures on macOS
1 parent a38a340 commit d6072dc

File tree

5 files changed

+100
-68
lines changed

5 files changed

+100
-68
lines changed

etc/evergreen_yml_components/definitions.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,15 +2949,7 @@ tasks:
29492949
archive-dist-test
29502950
task_compile_flags: >-
29512951
PREFIX=dist-test
2952-
- command: subprocess.exec
2953-
params:
2954-
binary: bash
2955-
add_expansions_to_env: true
2956-
args:
2957-
- "src/evergreen/run_python_script.sh"
2958-
- "evergreen/macos_notary.py"
2959-
- "mongodb-binaries.${ext|tgz}"
2960-
2952+
sign_macos_archive: true
29612953
- command: s3.put
29622954
params:
29632955
optional: true
@@ -8081,14 +8073,7 @@ tasks:
80818073
${additional_package_targets|}
80828074
task_compile_flags: >-
80838075
--legacy-tarball
8084-
- command: subprocess.exec
8085-
params:
8086-
binary: bash
8087-
add_expansions_to_env: true
8088-
args:
8089-
- "src/evergreen/run_python_script.sh"
8090-
- "evergreen/macos_notary.py"
8091-
- "mongodb-dist.${ext|tgz}"
8076+
sign_macos_archive: true
80928077
- func: "f_expansions_write"
80938078
- command: subprocess.exec
80948079
params:

etc/macos_dev_entitlements.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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-unsigned-executable-memory</key><true/>
6+
<!--The get-task-allow entitlement is insecure and must only be used in dev environments-->
7+
<key>com.apple.security.get-task-allow</key><true/>
8+
</dict>
9+
</plist>
10+
File renamed without changes.

evergreen/macos_notary.py

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
import os
23
import platform
34
import shutil
@@ -6,15 +7,13 @@
67
import zipfile
78
import stat
89
import sys
10+
import yaml
11+
912

1013
if platform.system().lower() != 'darwin':
1114
print("Not a macos system, skipping macos signing.")
1215
sys.exit(0)
1316

14-
if len(sys.argv) < 2:
15-
print("Must provide at least 1 archive to sign.")
16-
sys.exit(1)
17-
1817
supported_archs = {
1918
'arm64': 'arm64',
2019
'x86_64': 'amd64'
@@ -25,12 +24,20 @@
2524
print(f"Unsupported platform uname arch: {arch}, must be {supported_archs.keys()}")
2625
sys.exit(1)
2726

28-
macnotary_name = f'darwin_{supported_archs[arch]}'
27+
expansions_file = "../expansions.yml"
28+
if not os.path.exists(expansions_file):
29+
print("Evergreen expansions file not found. Skipping macos_notary.")
30+
sys.exit(0)
2931

30-
if os.environ['project'] == "mongodb-mongo-master-nightly":
31-
signing_type = 'notarizeAndSign'
32-
else:
33-
signing_type = 'sign'
32+
with open(expansions_file) as file:
33+
expansions = yaml.safe_load(file)
34+
35+
should_sign = expansions.get("sign_macos_archive", None)
36+
if not should_sign:
37+
print("sign_macos_archive expansion not found not found or false. Skipping macos_notary.")
38+
sys.exit(0)
39+
40+
macnotary_name = f'darwin_{supported_archs[arch]}'
3441

3542
macnotary_url = f'https://macos-notary-1628249594.s3.amazonaws.com/releases/client/latest/{macnotary_name}.zip'
3643
print(f'Fetching macnotary tool from: {macnotary_url}')
@@ -42,43 +49,51 @@
4249
os.chmod(f'{macnotary_name}/macnotary', st.st_mode | stat.S_IEXEC)
4350

4451
failed = False
45-
archives = sys.argv[1:]
46-
47-
for archive in archives:
48-
archive_base, archive_ext = os.path.splitext(archive)
49-
unsigned_archive = f'{archive_base}_unsigned{archive_ext}'
50-
shutil.move(archive, unsigned_archive)
51-
52-
signing_cmd = [
53-
f'./{macnotary_name}/macnotary',
54-
'-f', f'{unsigned_archive}',
55-
'-m', f'{signing_type}',
56-
'-u', 'https://dev.macos-notary.build.10gen.cc/api',
57-
'-k', 'server',
58-
'--entitlements', 'etc/macos_entitlements.xml',
59-
'--verify',
60-
'-b', 'server.mongodb.com',
61-
'-i', f'{os.environ["task_id"]}',
62-
'-c', f'{os.environ["project"]}',
63-
'-o', f'{archive}'
64-
]
65-
66-
signing_env = os.environ.copy()
67-
signing_env['MACOS_NOTARY_SECRET'] = os.environ["macos_notarization_secret"]
68-
print(' '.join(signing_cmd))
69-
p = subprocess.Popen(signing_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=signing_env)
70-
71-
print(f"Signing tool completed with exitcode: {p.returncode}")
72-
for line in iter(p.stdout.readline, b''):
73-
print(f'macnotary: {line.decode("utf-8").strip()}')
74-
p.wait()
75-
76-
if p.returncode != 0:
77-
failed = True
78-
shutil.move(unsigned_archive, archive)
79-
else:
80-
os.unlink(unsigned_archive)
52+
parser = argparse.ArgumentParser(
53+
prog="MacOS Notary",
54+
description="Sign and/or notarize a tarball containing unsigned binaries.",
55+
)
56+
parser.add_argument("--archive-name", "-a", action="store", required=True)
57+
parser.add_argument("--entitlements-file", "-e", action="store", required=True)
58+
parser.add_argument("--signing-type", "-s", action="store", required=True)
59+
args = parser.parse_args()
60+
archive_name = args.archive_name
61+
entitlements_file = args.entitlements_file
62+
signing_type = args.signing_type
63+
64+
archive_base, archive_ext = os.path.splitext(archive_name)
65+
unsigned_archive = f'{archive_base}_unsigned{archive_ext}'
66+
shutil.move(archive_name, unsigned_archive)
67+
68+
signing_cmd = [
69+
f'./{macnotary_name}/macnotary',
70+
'-f', f'{unsigned_archive}',
71+
'-m', f'{signing_type}',
72+
'-u', 'https://dev.macos-notary.build.10gen.cc/api',
73+
'-k', 'server',
74+
'--entitlements', entitlements_file,
75+
'--verify',
76+
'-b', 'server.mongodb.com',
77+
'-i', f'{expansions["task_id"]}',
78+
'-c', f'{expansions["project"]}',
79+
'-o', f'{archive_name}'
80+
]
81+
82+
signing_env = os.environ.copy()
83+
signing_env['MACOS_NOTARY_SECRET'] = expansions.get("macos_notarization_secret", "")
84+
print(' '.join(signing_cmd))
85+
p = subprocess.Popen(signing_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=signing_env)
86+
87+
print(f"Signing tool completed with exitcode: {p.returncode}")
88+
for line in iter(p.stdout.readline, b''):
89+
print(f'macnotary: {line.decode("utf-8").strip()}')
90+
p.wait()
91+
92+
if p.returncode != 0:
93+
failed = True
94+
shutil.move(unsigned_archive, archive_name)
95+
else:
96+
os.unlink(unsigned_archive)
8197

8298
if failed:
8399
exit(1)
84-

site_scons/site_tools/auto_archive.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,25 @@ def archive_builder(source, target, env, for_signature):
290290
return cmd
291291

292292

293+
def macos_archive_sign_builder(source, target, env, for_signature):
294+
if env['PLATFORM'] != 'darwin' or env.GetOption("ninja") != 'disabled':
295+
return ""
296+
297+
if env.GetOption("release") is not None:
298+
print("MacOS release build found, signing with release entitlements.")
299+
entitlements_file = 'etc/macos_release_entitlements.xml'
300+
signing_type = 'notarizeAndSign'
301+
else:
302+
print("MacOS dev build found, signing with insecure development entitlements.")
303+
entitlements_file = 'etc/macos_dev_entitlements.xml'
304+
signing_type = 'sign'
305+
306+
archive_name = env.File(target[0])
307+
macos_notory_cmd = f"{sys.executable} evergreen/macos_notary.py --archive-name={archive_name} --entitlements-file={entitlements_file} --signing-type={signing_type}"
308+
309+
return macos_notory_cmd
310+
311+
293312
def exists(env):
294313
return True
295314

@@ -299,11 +318,14 @@ def generate(env):
299318
env.Tool("auto_install_binaries")
300319

301320
bld = SCons.Builder.Builder(
302-
action=SCons.Action.CommandGeneratorAction(
303-
archive_builder,
304-
{"cmdstr": "Building package ${TARGETS[0]} from ${SOURCES[1:]}"}
305-
if not env.Verbose() else {"cmdstr": ""},
306-
))
321+
action=SCons.Action.ListAction([
322+
SCons.Action.CommandGeneratorAction(
323+
archive_builder,
324+
{"cmdstr": "Building package ${TARGETS[0]} from ${SOURCES[1:]}"}
325+
if not env.Verbose() else {"cmdstr": ""},
326+
),
327+
SCons.Action.CommandGeneratorAction(macos_archive_sign_builder, {})
328+
]))
307329
env.Append(BUILDERS={"AutoArchive": bld})
308330
env["AUTO_ARCHIVE_TARBALL_SUFFIX"] = env.get(
309331
"AUTO_ARCHIVE_TARBALL_SUFFIX",

0 commit comments

Comments
 (0)