From 96e61da24710152bbd1f636c07be1ee05dd4c3a2 Mon Sep 17 00:00:00 2001 From: Elliot Mackenzie Date: Wed, 18 Nov 2026 17:28:23 +1000 Subject: [PATCH] Sign and verify the macOS installer before release publication --- .github/workflows/release.yml | 8 +++++++ README.md | 9 ++++++++ build/macos/sign_installer.sh | 34 +++++++++++++++++++++++++++++ tests/test_release_qualification.py | 12 ++++++++-- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 build/macos/sign_installer.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee5edf0..75ca71d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -159,6 +159,14 @@ jobs: chmod +x build/macos/build_pkg.sh ./build/macos/build_pkg.sh "${VERSION}" "${{ matrix.macos_arch }}" + - name: Sign and verify macOS installer + if: runner.os == 'macOS' + shell: bash + env: + MAC_INSTALLER_P12_BASE64: ${{ secrets.MAC_INSTALLER_P12_BASE64 }} + MAC_INSTALLER_P12_PASSWORD: ${{ secrets.MAC_INSTALLER_P12_PASSWORD }} + run: bash build/macos/sign_installer.sh "dist/dataplicity-cli-${VERSION}-macos-${{ matrix.macos_arch }}.pkg" + - name: Stage macOS release artifacts if: runner.os == 'macOS' shell: bash diff --git a/README.md b/README.md index 1818630..b6b1786 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,15 @@ If you do have Python available and prefer `pipx`: pipx install dataplicity-cli ``` +### macOS installer signing in CI + +The Release workflow signs the direct-download package with MachineForest Ltd’s +Developer ID Installer identity and checks the trusted signature and publisher +before generating checksums. Configure `MAC_INSTALLER_P12_BASE64` (the encrypted +PKCS#12 identity encoded as base64) and `MAC_INSTALLER_P12_PASSWORD` in the +protected `release-signing` environment. A qualification-only run performs the +same check. A failed signing or verification step blocks publication. + ## Quick start Guided setup (recommended): diff --git a/build/macos/sign_installer.sh b/build/macos/sign_installer.sh new file mode 100644 index 0000000..14f6b18 --- /dev/null +++ b/build/macos/sign_installer.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -euo pipefail + +# The release workflow calls this on an ephemeral macOS runner, before checksumming. +package="${1:?expected package path}" +[[ -f "$package" ]] +: "${MAC_INSTALLER_P12_BASE64:?Missing Developer ID Installer certificate in the release-signing environment}" +: "${MAC_INSTALLER_P12_PASSWORD:?Missing Developer ID Installer certificate password}" + +export LC_ALL=C +umask 077 +work=$(mktemp -d) +keychain="$work/installer.keychain-db" +cleanup() { + security delete-keychain "$keychain" >/dev/null 2>&1 || true + rm -rf "$work" +} +trap cleanup EXIT +identity='Developer ID Installer: MachineForest Ltd (82FBZ5BYTV)' +keychain_password=$(openssl rand -hex 32) +security create-keychain -p "$keychain_password" "$keychain" +security unlock-keychain -p "$keychain_password" "$keychain" +printf '%s' "$MAC_INSTALLER_P12_BASE64" | base64 -D > "$work/installer.p12" +security import "$work/installer.p12" -k "$keychain" -P "$MAC_INSTALLER_P12_PASSWORD" -T /usr/bin/productsign +rm "$work/installer.p12" +unset MAC_INSTALLER_P12_BASE64 MAC_INSTALLER_P12_PASSWORD +security set-key-partition-list -S apple-tool:,apple: -s -k "$keychain_password" "$keychain" >/dev/null + +productsign --timestamp --keychain "$keychain" --sign "$identity" "$package" "$work/signed.pkg" +signature=$(pkgutil --check-signature "$work/signed.pkg") +printf '%s\n' "$signature" +grep -Eq '^[[:space:]]*Status: signed by (a developer certificate issued by Apple for distribution|a certificate trusted by )' <<< "$signature" +grep -Fq "1. $identity" <<< "$signature" +mv "$work/signed.pkg" "$package" diff --git a/tests/test_release_qualification.py b/tests/test_release_qualification.py index b4ec85f..6d0f6b8 100644 --- a/tests/test_release_qualification.py +++ b/tests/test_release_qualification.py @@ -76,14 +76,22 @@ def test_entire_release_and_distribution_write_dependency_closure_is_guarded(): assert 'Verify Windows MSI signature' in blocks['build'] -def test_original_build_sign_upload_and_release_bytes_except_reviewed_runner_migration(): +def test_original_build_sign_upload_and_release_bytes_except_reviewed_macos_changes(): source = WORKFLOW.read_text() assert source.count(INPUT) == 1 and source.count(GUARD) == 1 # GitHub retired macOS 14 on 2026-11-02. Permit only this exact build-runner - # replacement; retain the original digest over every other workflow byte. + # replacement and the installer signing step; pin the other workflow bytes. runner = ' - name: macos-universal2\n os: macos-15-intel\n' assert source.count(runner) == 1 assert 'macos-14' not in source + signing_start = source.index(' - name: Sign and verify macOS installer') + staging_start = source.index(' - name: Stage macOS release artifacts') + assert source.index(' - name: Build macOS pkg') < signing_start < staging_start + signing = source[signing_start:staging_start] + assert signing.splitlines()[1].strip() == "if: runner.os == 'macOS'" + assert 'continue-on-error' not in signing + assert 'run: bash build/macos/sign_installer.sh' in signing + source = source[:signing_start] + source[staging_start:] original = source.replace(INPUT, '', 1).replace(GUARD, '', 1).replace( runner, runner.replace('macos-15-intel', 'macos-14'), 1).encode() digest = hashlib.sha1(b'blob ' + str(len(original)).encode() + b'\0' + original).hexdigest()