Skip to content

Commit e499765

Browse files
poshuljpfeufferCopilot
authored
Fix remaining notarization issues from OpenMS#8486 (OpenMS#8494)
* address coderabbot issues from OpenMS#8486 * Add build.keychain to security list-keychains Add build.keychain to the list of keychains for code signing. * Change ctest verbosity level in CI workflow (OpenMS#8497) * Add productsign to key-partition-list in CI workflow * Update notarize.sh to include ASC_TEAMID parameter TEAM_ID is now required even with only one team. * Add teamID to notarize fix producbuild key permissions * Add team ID to notarization log fetching * Initial plan * Add macOS code signing for thirdparty components for notarization Co-authored-by: jpfeuffer <8102638+jpfeuffer@users.noreply.github.com> * Add check for THIRDPARTY directory existence before signing Co-authored-by: jpfeuffer <8102638+jpfeuffer@users.noreply.github.com> * Sign each thirdparty component individually for macOS notarization Co-authored-by: jpfeuffer <8102638+jpfeuffer@users.noreply.github.com> --------- Co-authored-by: Julianus Pfeuffer <8102638+jpfeuffer@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent c54be7f commit e499765

5 files changed

Lines changed: 55 additions & 18 deletions

File tree

.github/workflows/openms_ci_matrix_full.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,14 @@ jobs:
506506
echo $APPLE_CERTIFICATE | base64 --decode > certificate.p12
507507
echo $INSTALLER_CERTIFICATE | base64 --decode > installer_certificate.p12
508508
security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
509+
security list-keychains -d user -s build.keychain
509510
security default-keychain -s build.keychain
510511
security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
511512
security set-keychain-settings -t 3600 -u build.keychain
512-
security import certificate.p12 -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
513-
security import installer_certificate.p12 -k build.keychain -P "$INSTALLER_CERTIFICATE_PASSWORD" -T /usr/bin/codesign -T /usr/bin/productsign
514-
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain
513+
security import certificate.p12 -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign -T /usr/bin/productbuild
514+
security import installer_certificate.p12 -k build.keychain -P "$INSTALLER_CERTIFICATE_PASSWORD" -T /usr/bin/codesign -T /usr/bin/productsign -T /usr/bin/productbuild
515+
security set-key-partition-list -S apple-tool:,apple:,codesign:,productsign:,productbuild: -s -k "$KEYCHAIN_PASSWORD" build.keychain
516+
515517
echo "=== Available signing identities ==="
516518
security find-identity -v -p codesigning build.keychain
517519
@@ -521,7 +523,7 @@ jobs:
521523
run: |
522524
# do not fail immediately
523525
set +e
524-
${{ steps.set-vars.outputs.xvfb }} ctest --output-on-failure -V -S $GITHUB_WORKSPACE/OpenMS/tools/ci/cipackage.cmake
526+
${{ steps.set-vars.outputs.xvfb }} ctest --output-on-failure -VV -S $GITHUB_WORKSPACE/OpenMS/tools/ci/cipackage.cmake
525527
retVal=$?
526528
if [ $retVal -ne 0 ]; then
527529
echo -e "\033[0;31m Errors in packaging:"
@@ -552,6 +554,7 @@ jobs:
552554
shell: bash
553555
env:
554556
APPLE_APP_SPECIFIC_NOTARIZATION_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_NOTARIZATION_PASSWORD }}
557+
TEAM_ID: "C64UCGJ5PL"
555558
run: |
556559
echo "=== Starting macOS package notarization ==="
557560
cd $GITHUB_WORKSPACE/OpenMS/bld/
@@ -572,6 +575,7 @@ jobs:
572575
"de.openms" \
573576
"apple@openms.de" \
574577
"APPLE_APP_SPECIFIC_NOTARIZATION_PASSWORD" \
578+
"$TEAM_ID" \
575579
"$GITHUB_WORKSPACE/OpenMS/bld/"
576580
577581
echo "=== Notarization complete ==="

cmake/MacOSX/notarize.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@
1111
# password_env_var - Environment variable name containing app-specific password
1212
# log_folder - Optional: folder for log files (defaults to current directory)
1313

14+
# Exit on error and fail on any error in a pipeline
1415
set -e
16+
set -o pipefail
1517

1618
BUNDLE_PKG="$1"
1719
BUNDLE_ID="$2"
1820
ASC_USERNAME="$3"
1921
ASC_PASSWORD_ENVVAR="$4"
20-
LOG_FOLDER="${5:-.}"
22+
ASC_TEAMID="$5"
23+
LOG_FOLDER="${6:-.}"
2124

2225
NOTARIZE_LOG="$LOG_FOLDER/notarize.log"
2326

2427
mkdir -p "$LOG_FOLDER"
2528
touch "$NOTARIZE_LOG"
2629

2730
REMOVE_PKG=false
31+
IS_ZIP=false
2832

2933
echo "=== macOS Notarization Script ==="
3034
echo "Bundle: $BUNDLE_PKG"
@@ -55,7 +59,8 @@ elif [[ $BUNDLE_PKG == *.pkg ]]; then
5559
echo "Notarizing PKG: $BUNDLE_PKG"
5660
elif [[ $BUNDLE_PKG == *.zip ]]; then
5761
# For zip files, we need to unzip to staple, then re-zip
58-
BUNDLE_FILE=${BUNDLE_PKG%.*}
62+
BUNDLE_FILE="$BUNDLE_PKG"
63+
IS_ZIP=true
5964
echo "Notarizing ZIP: $BUNDLE_PKG (will staple contents)"
6065
elif [[ $BUNDLE_PKG == *.app ]]; then
6166
# Apps need to be zipped for upload, then unzipped for stapling
@@ -82,10 +87,12 @@ echo "=== Submitting for notarization ==="
8287

8388
# Submit for notarization using notarytool
8489
# --wait makes the command block until notarization is complete
85-
# Note: --team-id is optional if you only have one team
90+
# Ensure pipefail is set for this block in case of subshells
91+
set -o pipefail
8692
if xcrun notarytool submit "$BUNDLE_PKG" \
8793
--apple-id "$ASC_USERNAME" \
8894
--password "${!ASC_PASSWORD_ENVVAR}" \
95+
--team-id "$ASC_TEAMID" \
8996
--wait \
9097
2>&1 | tee "$NOTARIZE_LOG"; then
9198

@@ -102,7 +109,7 @@ if xcrun notarytool submit "$BUNDLE_PKG" \
102109

103110
# Note: You cannot staple a .zip file directly
104111
# If the original was a zip, we need to handle it differently
105-
if [[ "$BUNDLE_FILE" == *.zip ]]; then
112+
if [[ "$IS_ZIP" = true ]]; then
106113
echo "Warning: Cannot staple a .zip file. The notarization is stored with Apple."
107114
echo "Users will need to be online for Gatekeeper to verify the notarization."
108115
else
@@ -139,6 +146,7 @@ if xcrun notarytool submit "$BUNDLE_PKG" \
139146
xcrun notarytool log "$SUBMISSION_ID" \
140147
--apple-id "$ASC_USERNAME" \
141148
--password "${!ASC_PASSWORD_ENVVAR}" \
149+
--team-id "$ASC_TEAMID" \
142150
"$LOG_FOLDER/notarization_details.json" 2>&1 || true
143151

144152
if [[ -f "$LOG_FOLDER/notarization_details.json" ]]; then

cmake/package_dragndrop_dmg.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "3.5")
119119
## For notarization, SIGNING_EMAIL must also be set.
120120
if (DEFINED CPACK_BUNDLE_APPLE_CERT_APP AND DEFINED SIGNING_EMAIL)
121121
add_custom_target(signed_dist
122-
COMMAND codesign --deep --force --sign ${CPACK_BUNDLE_APPLE_CERT_APP} ${CPACK_PACKAGE_FILE_NAME}.dmg
122+
COMMAND codesign --deep --force --timestamp --sign ${CPACK_BUNDLE_APPLE_CERT_APP} ${CPACK_PACKAGE_FILE_NAME}.dmg
123123
COMMAND ${OPENMS_HOST_DIRECTORY}/cmake/MacOSX/notarize.sh ${CPACK_PACKAGE_FILE_NAME}.dmg de.openms ${SIGNING_EMAIL} APPLE_APP_SPECIFIC_NOTARIZATION_PASSWORD ${OPENMS_HOST_BINARY_DIRECTORY}
124124
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
125125
COMMENT "Signing and notarizing ${CPACK_PACKAGE_FILE_NAME}.dmg as ${CPACK_BUNDLE_APPLE_CERT_APP}"
126126
DEPENDS dist)
127127
elseif(DEFINED CPACK_BUNDLE_APPLE_CERT_APP)
128128
message(STATUS "SIGNING_EMAIL not set. DMG will be signed but not notarized.")
129129
add_custom_target(signed_dist
130-
COMMAND codesign --deep --force --sign ${CPACK_BUNDLE_APPLE_CERT_APP} ${CPACK_PACKAGE_FILE_NAME}.dmg
130+
COMMAND codesign --deep --force --timestamp --sign ${CPACK_BUNDLE_APPLE_CERT_APP} ${CPACK_PACKAGE_FILE_NAME}.dmg
131131
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
132132
COMMENT "Signing ${CPACK_PACKAGE_FILE_NAME}.dmg as ${CPACK_BUNDLE_APPLE_CERT_APP} (not notarized)"
133133
DEPENDS dist)

cmake/package_mac_productbuild.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ install(CODE "
124124
COMPONENT library
125125
)
126126

127+
## Sign thirdparty components
128+
foreach(component IN LISTS THIRDPARTY_COMPONENT_GROUP)
129+
install(CODE "
130+
if(EXISTS \${CMAKE_INSTALL_PREFIX}/${INSTALL_SHARE_DIR}/THIRDPARTY/${component}/)
131+
execute_process(COMMAND find \${CMAKE_INSTALL_PREFIX}/${INSTALL_SHARE_DIR}/THIRDPARTY/${component}/ -type f -execdir codesign --force --options runtime -i de.openms.thirdparty.${component}.{} --sign \"${CPACK_BUNDLE_APPLE_CERT_APP}\" {} \\; OUTPUT_VARIABLE thirdparty_sign_out ERROR_VARIABLE thirdparty_sign_out)
132+
message('\${thirdparty_sign_out}')
133+
endif()"
134+
COMPONENT ${component}
135+
)
136+
endforeach()
137+
127138
## When Applications are installed (which is the FIRST in alphabetical order AND the main component),
128139
## a postinstall script runs to set file icon
129140
install(FILES ${PROJECT_SOURCE_DIR}/cmake/MacOSX/openms_logo_large_transparent.png

tools/ci/capture-env.sh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,32 @@ function write_file() {
7575
fi
7676

7777
for var in "${vars_to_cache[@]}"; do
78-
# This next line is a little tricky. It says to evaluate $var and
79-
# use its value as the name of another variable to evaluate
80-
# (indirection). The ":-" bit says to set the variable to an
81-
# empty string if it is not already defined.
78+
# Indirection: get value, default to empty
8279
val="${!var:-}"
8380

84-
if [ -n "${val}" ]; then
81+
# Sanitize: trim CR, LF, and trailing whitespace
82+
val_sane="$(printf '%s' "$val" | tr -d '\r\n' | sed 's/[[:space:]]*$//')"
83+
84+
if [ -n "$val_sane" ]; then
8585
if [ "$option_verbose" -eq 1 ]; then
86-
echo "Found $var with value $val"
86+
# Redact sensitive variables
87+
case "$var" in
88+
SIGNING_EMAIL|SIGNING_IDENTITY|CPACK_PRODUCTBUILD_IDENTITY_NAME)
89+
# Mask: show first and last char, rest as asterisks (if length > 2)
90+
len=${#val_sane}
91+
if [ "$len" -le 2 ]; then
92+
masked="$val_sane"
93+
else
94+
masked="${val_sane:0:1}***${val_sane: -1}"
95+
fi
96+
echo "Found $var with value $masked (redacted)"
97+
;;
98+
*)
99+
echo "Found $var with value $val_sane"
100+
;;
101+
esac
87102
fi
88-
89-
printf '%s:STRING=%s\n' "$var" "${val}" >>"$file"
103+
printf '%s:STRING=%s\n' "$var" "$val_sane" >>"$file"
90104
fi
91105
done
92106
}

0 commit comments

Comments
 (0)