-
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
5
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
5 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 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,97 @@ | ||
| #!/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="./build_certificate.p12" | ||
| KEYCHAIN_PATH="./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" | ||
|
|
||
| # 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: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" | ||
|
|
||
| # Show available signing identities for visibility | ||
| echo "🔎 Available signing identities (codesigning):" | ||
| security find-identity -v -p codesigning "$KEYCHAIN_PATH" || true | ||
|
|
||
| # Find and sign all macOS binaries dynamically | ||
| echo "🔎 Searching for macOS binaries in $DIST_DIR..." | ||
|
|
||
| find "$DIST_DIR" -type f \( -name "phrase_macosx_*" ! -name "*.tar.gz" \) -print0 | while IFS= read -r -d '' binary; do | ||
| echo "🔏 Signing $binary..." | ||
| codesign --timestamp --options runtime --keychain "$KEYCHAIN_PATH" --sign "$SIGNING_IDENTITY" "$binary" | ||
| codesign --verify --verbose=2 --keychain "$KEYCHAIN_PATH" "$binary" | ||
| done | ||
|
|
||
| echo "✅ All macOS binaries signed successfully." | ||
|
|
||
| # --- 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The certificate file is created with default permissions that may be world-readable. Set restrictive permissions (e.g., chmod 600) on the certificate file immediately after creation to prevent unauthorized access to sensitive cryptographic material.