-
Notifications
You must be signed in to change notification settings - Fork 7
feat(CLI): Add macOS binary signing using Apple Distribution certificate [SCD-129] #1002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bikmazefe
wants to merge
6
commits into
main
Choose a base branch
from
scd-129
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
121b785
feat(CLI): Add macOS binary signing using Apple Distribution certific…
bikmazefe 0a98809
Handle notarization
bikmazefe feaf411
Rename script
bikmazefe 85e33ac
Apply review comments
bikmazefe e792abd
Pin commit SHA for action
bikmazefe 161912a
Adjust the workflow and script after successful testing
bikmazefe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
| umask 077 | ||
|
|
||
| CERTIFICATE_BASE64="${SIGNING_CERTIFICATE}" | ||
| P12_PASSWORD="${CERTIFICATE_PASSWORD}" | ||
| SIGNING_IDENTITY="${SIGNING_IDENTITY}" | ||
| KEYCHAIN_PASSWORD="${KEYCHAIN_PASSWORD}" | ||
| DIST_DIR="${DIST_DIR:-dist}" | ||
|
|
||
| CERTIFICATE_PATH="$(pwd)/build_certificate.p12" | ||
| KEYCHAIN_PATH="$(pwd)/my-signing.keychain-db" | ||
|
|
||
| # Basic env validation to fail fast | ||
| require_env() { | ||
| local name="$1" value="$2" | ||
| if [[ -z "$value" ]]; then | ||
| echo "❌ Missing required environment variable: $name" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| require_env "SIGNING_CERTIFICATE" "${CERTIFICATE_BASE64}" | ||
| require_env "CERTIFICATE_PASSWORD" "${P12_PASSWORD}" | ||
| require_env "SIGNING_IDENTITY" "${SIGNING_IDENTITY}" | ||
| require_env "KEYCHAIN_PASSWORD" "${KEYCHAIN_PASSWORD}" | ||
| require_env "NOTARIZATION_APPLE_ID" "${NOTARIZATION_APPLE_ID:-}" | ||
| require_env "NOTARIZATION_APP_PASSWORD" "${NOTARIZATION_APP_PASSWORD:-}" | ||
| require_env "NOTARIZATION_TEAM_ID" "${NOTARIZATION_TEAM_ID:-}" | ||
|
|
||
|
|
||
| cleanup() { | ||
| echo "🧹 Cleaning up keychain and certificate..." | ||
| # Attempt to delete the temporary keychain | ||
| security delete-keychain "$KEYCHAIN_PATH" || true | ||
| # Remove certificate file | ||
| rm -f "$CERTIFICATE_PATH" || true | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| echo "🔐 Setting up certificate and keychain..." | ||
|
|
||
| # Decode the certificate (macOS-only) | ||
| echo "$CERTIFICATE_BASE64" | /usr/bin/base64 -D > "$CERTIFICATE_PATH" | ||
| # Restrict permissions on sensitive certificate material | ||
| chmod 600 "$CERTIFICATE_PATH" | ||
|
|
||
| # Create temporary keychain | ||
| security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" | ||
| security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH" | ||
| security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" | ||
|
|
||
| # Add keychain to the search list (prepend to existing list) | ||
| # This is required for codesign to find the identity | ||
| EXISTING_KEYCHAINS=$(security list-keychains -d user | tr -d '"' | tr '\n' ' ') | ||
| security list-keychains -d user -s "$KEYCHAIN_PATH" $EXISTING_KEYCHAINS | ||
|
|
||
| # Import certificate into keychain | ||
| security import "$CERTIFICATE_PATH" -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k "$KEYCHAIN_PATH" | ||
| security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" | ||
|
|
||
| # Set the custom keychain as the default for this session | ||
| security default-keychain -s "$KEYCHAIN_PATH" | ||
|
|
||
| # Debug: show keychain search list | ||
| echo "🔎 Keychain search list:" | ||
| security list-keychains -d user | ||
|
|
||
| # Show available signing identities for visibility | ||
| echo "🔎 Available signing identities (codesigning):" | ||
| security find-identity -v -p codesigning "$KEYCHAIN_PATH" || true | ||
|
|
||
| # Also check all keychains | ||
| echo "🔎 All available signing identities:" | ||
| security find-identity -v -p codesigning || true | ||
|
|
||
| # Extract the SHA-1 hash from the keychain for reliable signing | ||
| # This avoids issues with identity name matching | ||
| IDENTITY_HASH=$(security find-identity -v -p codesigning "$KEYCHAIN_PATH" | grep "Developer ID Application" | head -1 | awk '{print $2}') | ||
| if [[ -z "$IDENTITY_HASH" ]]; then | ||
| echo "❌ No Developer ID Application identity found in keychain" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "🔑 Using identity hash: $IDENTITY_HASH" | ||
|
|
||
| # Find and sign all macOS binaries dynamically | ||
| echo "🔎 Searching for macOS binaries in $DIST_DIR..." | ||
|
|
||
| shopt -s nullglob | ||
| for binary in "$DIST_DIR"/phrase_macosx_*; do | ||
| [[ "$binary" == *.tar.gz ]] && continue | ||
| [[ ! -f "$binary" ]] && continue | ||
| echo "🔏 Signing $binary..." | ||
| codesign --force --timestamp --options runtime --keychain "$KEYCHAIN_PATH" --sign "$IDENTITY_HASH" "$binary" | ||
| codesign --verify --verbose=2 "$binary" | ||
| done | ||
|
|
||
| echo "✅ All macOS binaries signed successfully." | ||
|
|
||
| # --- Recreate tar.gz with signed binaries (for Homebrew) --- | ||
| echo "📦 Recreating tar.gz archives with signed binaries..." | ||
| for binary in "$DIST_DIR"/phrase_macosx_*; do | ||
| [[ "$binary" == *.tar.gz ]] && continue | ||
| [[ "$binary" == *.zip ]] && continue | ||
| [[ ! -f "$binary" ]] && continue | ||
| relbin="${binary#${DIST_DIR}/}" | ||
| # Remove old tar.gz if exists | ||
| rm -f "$DIST_DIR/${relbin}.tar.gz" | ||
| # Create new tar.gz with signed binary renamed to 'phrase' | ||
| echo "Creating $DIST_DIR/${relbin}.tar.gz with signed binary..." | ||
| ( | ||
| cd "$DIST_DIR" | ||
| cp "$relbin" phrase | ||
| tar --create phrase | gzip -n > "${relbin}.tar.gz" | ||
| rm phrase | ||
| ) | ||
| done | ||
|
|
||
| # --- Zip artifacts for notarization --- | ||
| echo "📦 Zipping macOS binaries for notarization..." | ||
| shopt -s nullglob | ||
| for bin in "$DIST_DIR"/phrase_macosx_*; do | ||
| [[ "$bin" == *.tar.gz ]] && continue | ||
| relbin="${bin#${DIST_DIR}/}" | ||
| echo "Creating $DIST_DIR/${relbin}.zip" | ||
| ( | ||
| cd "$DIST_DIR" && /usr/bin/zip -o "${relbin}.zip" "${relbin}" | ||
| ) | ||
| done | ||
|
|
||
| # --- Notarization via Apple notarytool (Apple ID + app-specific password) --- | ||
| echo "📝 Notarizing zipped binaries with Apple Notary (Apple ID)..." | ||
| for zip in "$DIST_DIR"/phrase_macosx_*.zip; do | ||
| [[ -e "$zip" ]] || continue | ||
| echo "Submitting $zip to Apple Notary..." | ||
| xcrun notarytool submit "$zip" \ | ||
| --apple-id "$NOTARIZATION_APPLE_ID" \ | ||
| --password "$NOTARIZATION_APP_PASSWORD" \ | ||
| --team-id "$NOTARIZATION_TEAM_ID" \ | ||
| --wait | ||
| echo "ℹ️ Notarization complete for $zip." | ||
| done | ||
|
|
||
| echo "🎉 Signing and notarization finished." | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.