Skip to content

Commit 7afd78d

Browse files
committed
improve(mac): guard elevation signing identity against drift
scripts/mac-elevation-host.sh ships as the portable installer added in #123675, so it is deliberately self-contained and cannot source shared constants. That forces it to duplicate ELEVATION_TEAM_ID and ELEVATION_IDENTITY from scripts/codesign-mac-app.sh, with nothing keeping the two copies in sync. Add a test asserting they agree, so rotation drift fails at build time instead of on a target Mac. Also document why the sign-time and install-time elevation verification functions both exist: verify_elevation_app requires a notarized and stapled bundle, so it cannot replace the sign-time check, and deleting that check would defer every identity failure until after a notarization submission is already spent. No behavior change: no artifact bytes, filenames, modes, receipt fields, signing, notarization, or install paths are touched.
1 parent 3289e08 commit 7afd78d

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎scripts/codesign-mac-app.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ verify_team_ids() {
320320
fi
321321
}
322322

323+
# Sign-time twin of verify_elevation_app in mac-elevation-host.sh, which asserts the same identity
324+
# invariants but requires an already notarized and stapled bundle. Dropping this check defers every
325+
# elevation identity failure until after an Apple notarization submission has been spent.
323326
verify_elevation_signature() {
324327
[[ "$SIGNING_VARIANT" == "elevation-host" ]] || return 0
325328

‎scripts/mac-elevation-host.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ verify_universal_machos() {
166166
done < <(find "$app" -type f -perm -111 -print0)
167167
}
168168

169+
# Canonical elevation identity check: a strict superset of verify_elevation_signature in
170+
# codesign-mac-app.sh, and the only one that runs post-notarization and on the target Mac at install
171+
# time. Dropping it lets the portable installer accept an archive nobody re-verified after signing.
169172
verify_elevation_app() {
170173
local app="$1"
171174
[[ -d "$app" && ! -L "$app" ]] || fail "elevation app not found or symlinked: $app"

‎test/scripts/mac-elevation-host.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
77

88
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
99
const scriptPath = "scripts/mac-elevation-host.sh";
10+
const codesignScriptPath = "scripts/codesign-mac-app.sh";
1011

1112
function writeExecutable(filePath: string, contents: string): void {
1213
writeFileSync(filePath, contents, "utf8");
@@ -229,6 +230,24 @@ describe("mac elevation host command contract", () => {
229230
expect(script).toContain('spctl --assess --type execute "$app"');
230231
});
231232

233+
it("keeps portable signing identity aligned with the signer", () => {
234+
const portableScript = readFileSync(scriptPath, "utf8");
235+
const codesignScript = readFileSync(codesignScriptPath, "utf8");
236+
const constant = (source: string, name: string) =>
237+
source.match(new RegExp(`^${name}="([^"]+)"$`, "m"))?.[1];
238+
239+
expect(
240+
[
241+
constant(portableScript, "EXPECTED_TEAM_ID"),
242+
constant(portableScript, "EXPECTED_AUTHORITY"),
243+
],
244+
"mac-elevation-host.sh is a self-contained portable installer, so its duplicated signing constants must match codesign-mac-app.sh",
245+
).toEqual([
246+
constant(codesignScript, "ELEVATION_TEAM_ID"),
247+
constant(codesignScript, "ELEVATION_IDENTITY"),
248+
]);
249+
});
250+
232251
it.skipIf(process.platform !== "darwin")(
233252
"renders a persistent background-only launchd job without changing normal login",
234253
() => {

0 commit comments

Comments
 (0)