-
Notifications
You must be signed in to change notification settings - Fork 1
378 lines (371 loc) · 15.5 KB
/
Copy pathmacos-live-qualification.yml
File metadata and controls
378 lines (371 loc) · 15.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: macos-live-qualification
on:
push:
branches:
- "qualify/portability-macos-live"
paths:
- ".github/workflows/macos-live-qualification.yml"
- "scripts/qualify-macos-live.sh"
- "scripts/validate-macos-launchd-deactivation.mjs"
- "scripts/macos-evidence-manifest.mjs"
- "ccm/**"
- "install.sh"
- "scripts/package-plugin.sh"
- "scripts/sync-plugin-dist.sh"
- "plugin/**"
- "tests/scripts/test_install_integrity.sh"
- "tests/scripts/test_macos_evidence_artifact.sh"
- "tests/content/macos-qualification-workflow.test.mjs"
# Live Darwin qualification is intentionally opt-in: add `ci:macos-live` to the PR at the
# revision that needs evidence. Remove/re-add the label after later commits to re-qualify.
pull_request:
types: [labeled]
paths:
- ".github/workflows/macos-live-qualification.yml"
- "scripts/qualify-macos-live.sh"
- "scripts/validate-macos-launchd-deactivation.mjs"
- "scripts/macos-evidence-manifest.mjs"
- "ccm/**"
- "tests/content/macos-qualification-workflow.test.mjs"
workflow_dispatch:
permissions:
contents: read
concurrency:
# Unrelated label events get a unique run-id group, so they cannot cancel a real qualification.
group: ${{ github.workflow }}-${{ github.event.label.name == 'ci:macos-live' && github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' && github.event.label.name == 'ci:macos-live' }}
jobs:
build-sea:
name: build / ${{ matrix.contract }}
if: ${{ github.event_name != 'pull_request' || github.event.label.name == 'ci:macos-live' }}
strategy:
fail-fast: false
matrix:
include:
- runner: macos-14
contract: darwin-arm64
uname_arch: arm64
node_arch: arm64
asset: ccm-darwin-arm64
- runner: macos-15-intel
contract: darwin-x64
uname_arch: x86_64
node_arch: x64
asset: ccm-darwin-x64
runs-on: ${{ matrix.runner }}
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: pnpm/action-setup@v4
with:
version: 10.22.0
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: ccm/pnpm-lock.yaml
- name: Assert real runner identity
shell: bash
run: |
set -euo pipefail
test "$(uname -s)" = Darwin
test "$(uname -m)" = "${{ matrix.uname_arch }}"
test "$(node -p 'process.arch')" = "${{ matrix.node_arch }}"
- name: Install dependencies and build workspace
shell: bash
run: |
set -euo pipefail
pnpm -C ccm install --frozen-lockfile
pnpm -C ccm build
- name: Build and attest SEA
id: build
shell: bash
env:
ASSET: ${{ matrix.asset }}
run: |
set -euo pipefail
OUT="${RUNNER_TEMP}/macos-sea/${ASSET}"
EVIDENCE="${RUNNER_TEMP}/macos-sea/build-evidence"
mkdir -p "$(dirname "${OUT}")" "${EVIDENCE}"
set +e
(
set -euxo pipefail
{
printf 'exact_commit=%s\n' "$(git rev-parse HEAD)"
printf 'exact_tree=%s\n' "$(git rev-parse 'HEAD^{tree}')"
printf 'runner_label=%s\n' '${{ matrix.runner }}'
printf 'expected_contract=%s\n' '${{ matrix.contract }}'
printf 'uname_s=%s\n' "$(uname -s)"
printf 'uname_m=%s\n' "$(uname -m)"
printf 'node_arch=%s\n' "$(node -p 'process.arch')"
uname -a
sw_vers
node --version
pnpm --version
diskutil info / || true
mount
} >"${EVIDENCE}/runner.txt" 2>&1
CCM_SEA_NODE="$(command -v node)" CCM_SEA_OUT="${OUT}" \
bash ccm/apps/cli/scripts/build-sea.sh >"${EVIDENCE}/build-sea.log" 2>&1
if grep -Eq 'fexecve|execveat|/dev/fd|/proc/self/fd' \
ccm/apps/cli/native/runtime-invoke-helper-darwin.c; then
printf '%s\n' 'Darwin helper source contains a forbidden fd-exec claim' >&2
exit 1
fi
node - ccm/apps/cli/.native-build/runtime-invoke-helper.json '${{ matrix.node_arch }}' \
>"${EVIDENCE}/runtime-helper-contract.log" <<'NODE'
const fs = require('node:fs');
const [file, expectedArch] = process.argv.slice(2);
const doc = JSON.parse(fs.readFileSync(file, 'utf8'));
if (doc.contract !== 'darwin-path-attested-v1') process.exit(2);
if (doc.platform !== 'darwin' || doc.arch !== expectedArch) process.exit(3);
process.stdout.write(`${JSON.stringify(doc, null, 2)}\n`);
NODE
nm -u ccm/apps/cli/.native-build/runtime-invoke-helper \
>"${EVIDENCE}/runtime-helper-symbols.log"
if grep -Eq '_fexecve|_execveat' "${EVIDENCE}/runtime-helper-symbols.log"; then
printf '%s\n' 'Darwin helper imports a forbidden descriptor-exec symbol' >&2
exit 1
fi
grep -Eq '^[[:space:]]*_execve$' "${EVIDENCE}/runtime-helper-symbols.log"
chmod 755 "${OUT}"
"${OUT}" --version >"${EVIDENCE}/sea-version.log" 2>&1
codesign --verify --strict --verbose=4 "${OUT}" >"${EVIDENCE}/codesign-verify.log" 2>&1
codesign -dvvv "${OUT}" >"${EVIDENCE}/codesign-display.log" 2>&1
otool -L "${OUT}" >"${EVIDENCE}/otool.log" 2>&1
if grep -Eq '/opt/homebrew|/usr/local/(opt|Cellar)|libnode' "${EVIDENCE}/otool.log"; then
printf '%s\n' 'non-system dynamic dependency found' >&2
exit 1
fi
(
cd "$(dirname "${OUT}")"
shasum -a 256 "${ASSET}" >"${ASSET}.sha256"
shasum -a 256 -c "${ASSET}.sha256"
) >"${EVIDENCE}/checksum.log" 2>&1
) 2>&1 | tee "${EVIDENCE}/build-attestation.log"
pipeline_status=("${PIPESTATUS[@]}")
build_exit_code="${pipeline_status[0]}"
tee_exit_code="${pipeline_status[1]}"
if [ "${build_exit_code}" -eq 0 ] && [ "${tee_exit_code}" -ne 0 ]; then
build_exit_code="${tee_exit_code}"
fi
set -e
printf '{"schema":"ccm/macos-build-result/v1","exit_code":%s,"tee_exit_code":%s}\n' \
"${build_exit_code}" "${tee_exit_code}" >"${EVIDENCE}/build-result.json"
printf 'exit_code=%s\n' "${build_exit_code}" >>"${GITHUB_OUTPUT}"
exit 0
- name: Upload non-release SEA evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: macos-sea-${{ matrix.contract }}
path: |
${{ runner.temp }}/macos-sea/${{ matrix.asset }}
${{ runner.temp }}/macos-sea/${{ matrix.asset }}.sha256
${{ runner.temp }}/macos-sea/build-evidence
if-no-files-found: error
retention-days: 7
- name: Enforce build verdict
if: always()
shell: bash
env:
BUILD_EXIT_CODE: ${{ steps.build.outputs.exit_code }}
run: |
set -euo pipefail
if ! [[ "${BUILD_EXIT_CODE}" =~ ^[0-9]+$ ]] || [ "${BUILD_EXIT_CODE}" -gt 255 ]; then
printf '%s\n' 'build attestation did not report a valid exit code; inspect the uploaded evidence' >&2
exit 1
fi
if [ "${BUILD_EXIT_CODE}" -ne 0 ]; then
printf 'build attestation exited %s; inspect the uploaded evidence\n' "${BUILD_EXIT_CODE}" >&2
exit "${BUILD_EXIT_CODE}"
fi
qualify:
name: qualify / ${{ matrix.contract }}
needs: build-sea
strategy:
fail-fast: false
matrix:
include:
- runner: macos-14
contract: darwin-arm64
uname_arch: arm64
node_arch: arm64
asset: ccm-darwin-arm64
- runner: macos-15-intel
contract: darwin-x64
uname_arch: x86_64
node_arch: x64
asset: ccm-darwin-x64
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: pnpm/action-setup@v4
with:
version: 10.22.0
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: ccm/pnpm-lock.yaml
- name: Download SEA as a fresh workflow artifact
uses: actions/download-artifact@v4
with:
name: macos-sea-${{ matrix.contract }}
path: ${{ runner.temp }}/downloaded-sea
- name: Bind downloaded SEA to exact checkout
shell: bash
run: |
set -euo pipefail
expected_commit="$(git rev-parse HEAD)"
expected_tree="$(git rev-parse 'HEAD^{tree}')"
build_identity="${RUNNER_TEMP}/downloaded-sea/build-evidence/runner.txt"
grep -Fx "exact_commit=${expected_commit}" "${build_identity}"
grep -Fx "exact_tree=${expected_tree}" "${build_identity}"
qualification_root="${RUNNER_TEMP}/macos-qualification-${{ matrix.contract }}"
mkdir -p "${qualification_root}"
cp -R "${RUNNER_TEMP}/downloaded-sea/build-evidence" \
"${qualification_root}/sea-build-evidence"
- name: Install qualification dependencies
shell: bash
run: |
set -euo pipefail
pnpm -C ccm install --frozen-lockfile
pnpm -C ccm build
npm install --global @anthropic-ai/claude-code
- name: Run live qualification
id: live
continue-on-error: true
shell: bash
env:
EXPECTED_UNAME_ARCH: ${{ matrix.uname_arch }}
EXPECTED_NODE_ARCH: ${{ matrix.node_arch }}
run: |
chmod 755 "${RUNNER_TEMP}/downloaded-sea/${{ matrix.asset }}"
bash scripts/qualify-macos-live.sh \
"${RUNNER_TEMP}/downloaded-sea/${{ matrix.asset }}" \
'${{ matrix.contract }}' \
"${RUNNER_TEMP}/macos-qualification-${{ matrix.contract }}"
- name: Upload raw qualification evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: macos-live-raw-evidence-${{ matrix.contract }}
path: ${{ runner.temp }}/macos-qualification-${{ matrix.contract }}
# The isolated RUNNER_TEMP tree intentionally contains runtime state and plugin manifests
# below dot-directories; it is not the runner's ambient HOME or credential store.
include-hidden-files: true
if-no-files-found: error
overwrite: true
retention-days: 7
- name: Enforce qualification verdict
if: steps.live.outcome != 'success'
shell: bash
run: |
printf '%s\n' 'live qualification reported one or more required failures; inspect the uploaded raw evidence' >&2
exit 1
evidence-index:
name: evidence index
if: ${{ always() && (github.event_name != 'pull_request' || github.event.label.name == 'ci:macos-live') }}
needs: qualify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: actions/download-artifact@v4
with:
# Keep raw inputs in a namespace that cannot match this job's index from an earlier attempt.
pattern: macos-live-raw-evidence-*
path: evidence
merge-multiple: false
- name: Verify inner manifests and build the outer index
shell: bash
env:
EXPECTED_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
set -euo pipefail
node <<'NODE'
const fs = require('node:fs');
const expected = [
'macos-live-raw-evidence-darwin-arm64',
'macos-live-raw-evidence-darwin-x64',
];
const entries = fs.readdirSync('evidence', { withFileTypes: true });
if (entries.some((entry) => !entry.isDirectory())) {
throw new Error('evidence download root must contain artifact directories only');
}
const actual = entries.map((entry) => entry.name).sort();
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
throw new Error(`expected artifact directories ${expected.join(',')}; observed ${actual.join(',')}`);
}
NODE
for artifact in \
macos-live-raw-evidence-darwin-arm64 \
macos-live-raw-evidence-darwin-x64; do
root="evidence/${artifact}"
node scripts/macos-evidence-manifest.mjs verify "${root}" "${root}/SHA256SUMS"
done
node <<'NODE'
const fs = require('node:fs');
const artifacts = [
'macos-live-raw-evidence-darwin-arm64',
'macos-live-raw-evidence-darwin-x64',
];
const expectedCommit = process.env.EXPECTED_COMMIT;
if (!/^[0-9a-f]{40}$/.test(expectedCommit || '')) {
throw new Error('expected commit must be one immutable 40-hex workflow identity');
}
function readIdentity(file) {
const lines = fs.readFileSync(file, 'utf8').split('\n');
const value = (key) => {
const prefix = `${key}=`;
const matches = lines.filter((line) => line.startsWith(prefix));
if (matches.length !== 1) {
throw new Error(`${file}: expected exactly one ${key} record`);
}
const observed = matches[0].slice(prefix.length);
if (!/^[0-9a-f]{40}$/.test(observed)) {
throw new Error(`${file}: ${key} must be 40-hex`);
}
return observed;
};
return {
exact_commit: value('exact_commit'),
exact_tree: value('exact_tree'),
};
}
let commonTree = null;
for (const artifact of artifacts) {
const root = `evidence/${artifact}`;
const summary = readIdentity(`${root}/summary.txt`);
const build = readIdentity(`${root}/sea-build-evidence/runner.txt`);
for (const [record, identity] of [['summary', summary], ['build', build]]) {
if (identity.exact_commit !== expectedCommit) {
throw new Error(`${artifact}/${record}: expected commit ${expectedCommit}; observed ${identity.exact_commit}`);
}
}
if (summary.exact_tree !== build.exact_tree) {
throw new Error(`${artifact}: qualification/build tree identity mismatch`);
}
if (commonTree !== null && summary.exact_tree !== commonTree) {
throw new Error(`${artifact}: cross-architecture tree identity mismatch`);
}
commonTree = summary.exact_tree;
}
NODE
node scripts/macos-evidence-manifest.mjs write evidence EVIDENCE_SHA256SUMS
node scripts/macos-evidence-manifest.mjs verify evidence EVIDENCE_SHA256SUMS
cat EVIDENCE_SHA256SUMS
- uses: actions/upload-artifact@v4
with:
name: macos-live-evidence-index
path: EVIDENCE_SHA256SUMS
if-no-files-found: error
overwrite: true
retention-days: 7