Sign Binaries and Notarize OSX Installer (#59084)

* Notarize binaries

* Fix codesign

* Make scripts executable

* Improve docs

* Fix productbuild

* Enable hardened runtime, sign .so files

* Spell notarize correctly

* Set notarize executable

* Add entitlements for all binaries

* Only pass single package name to notarize

* Only sign bin with entitlements

* Notarize binaries

* Fix codesign

* Make scripts executable

* Improve docs

* Fix productbuild

* Enable hardened runtime, sign .so files

* Spell notarize correctly

* Set notarize executable

* Add entitlements for all binaries

* Only pass single package name to notarize

* Only sign bin with entitlements

* Fix docs in build.sh

* Add changelog

* Remove unneeded parameter

* Add echo statements

* Fix changelog

Co-authored-by: Salt Admin <saltadmin@build--osx-10.14-mojave-.shared>
Co-authored-by: Sage the Rage <36676171+sagetherage@users.noreply.github.com>
This commit is contained in:
Shane Lee 2021-02-22 11:46:19 -07:00 committed by GitHub
parent 2b7b618574
commit 6853342ea0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 403 additions and 151 deletions

2
changelog/54513.fixed Normal file
View file

@ -0,0 +1,2 @@
Binaries for the salt installer package for OSX are now signed and the installer
package is notarized

View file

@ -1,5 +1,5 @@
#!/bin/bash
############################################################################
################################################################################
#
# Title: Build Salt Script for macOS
# Authors: CR Oldham, Shane Lee
@ -9,7 +9,7 @@
# tools required to create a .pkg file for installation on macOS.
# Salt and all dependencies will be installed to /opt/salt. A
# .pkg file will then be created based on the contents of
# /opt/salt
# /opt/salt. The pkg will be signed and notarized
#
# Requirements:
# - Xcode Command Line Tools (xcode-select --install)
@ -33,19 +33,64 @@
#
# ./build.sh v3001 false /tmp/custom_pkg
#
############################################################################
# This script uses the following scripts:
#
# build_env.sh
# Builds python and other salt dependencies such as pkg-config,
# libsodium, zeromq, and openssl.
#
# sign_binaries.sh
# Signs all the binaries with the Developer App certificate specified in
# the DEV_APP_CERT environment variable. It signs all binaries in the
# /opt/salt/bin and /opt/salt/lib directories. It also signs .dylib
# files in the /opt/salt/lib directory.
#
# package.sh
# Builds a package file from the contents of /opt/salt and signs it with
# the Developer Installer certificate specified in the DEV_INSTALL_CERT
# environment variable.
#
# notarize.sh
# Sends the package to be notarized by apple and staples the
# notarization to the installer pkg. It uses the Apple Account name
# specified in the APPLE_ACCT environment variable and the app-specific
# password for that account specified in the APP_SPEC_PWD environment
# variable.
#
# Environment Setup:
# This script requires certificates and environment variables be present on
# the system. They are used by the above scripts. Details can be found in
# the individual scripts that use them.
#
# Import Certificates:
# Import the Salt Developer Application and Installer Signing
# certificates using the following commands:
#
# security import "developerID_application.p12" -k ~/Library/Keychains/login.keychain
# security import "developerID_installer.p12" -k ~/Library/Keychains/login.keychain
#
# Define Environment Variables:
# Define the environment variables using the following commands (replace
# with the actual values):
#
# export DEV_APP_CERT="Developer ID Application: Salt Stack, Inc. (AB123ABCD1)"
# export DEV_INSTALL_CERT="Developer ID Installer: Salt Stack, Inc. (AB123ABCD1)"
# export APPLE_ACCT="username@domain.com"
# export APP_SPEC_PWD="abcd-efgh-ijkl-mnop"
#
################################################################################
############################################################################
################################################################################
# Make sure the script is launched with sudo
############################################################################
################################################################################
if [[ $(id -u) -ne 0 ]]
then
exec sudo /bin/bash -c "$(printf '%q ' "$BASH_SOURCE" "$@")"
fi
############################################################################
################################################################################
# Check passed parameters, set defaults
############################################################################
################################################################################
echo -n -e "\033]0;Build: Variables\007"
if [ "$1" == "" ]; then
@ -66,17 +111,17 @@ else
PKGDIR=$3
fi
############################################################################
################################################################################
# Additional Parameters Required for the script to function properly
############################################################################
################################################################################
SRCDIR=`git rev-parse --show-toplevel`
PKGRESOURCES=$SRCDIR/pkg/osx
PYTHON=/opt/salt/bin/python3
CPUARCH=`uname -m`
############################################################################
################################################################################
# Make sure this is the Salt Repository
############################################################################
################################################################################
if [[ ! -e "$SRCDIR/.git" ]] && [[ ! -e "$SRCDIR/scripts/salt" ]]; then
echo "This directory doesn't appear to be a git repository."
echo "The macOS build process needs some files from a Git checkout of Salt."
@ -84,31 +129,38 @@ if [[ ! -e "$SRCDIR/.git" ]] && [[ ! -e "$SRCDIR/scripts/salt" ]]; then
exit -1
fi
############################################################################
################################################################################
# Create the Build Environment
############################################################################
################################################################################
echo -n -e "\033]0;Build: Build Environment\007"
$PKGRESOURCES/build_env.sh $TEST_MODE
if [[ "$?" != "0" ]]; then
echo "Failed to build the environment."
exit -1
fi
############################################################################
################################################################################
# Install Salt
############################################################################
################################################################################
echo -n -e "\033]0;Build: Install Salt\007"
rm -rf $SRCDIR/build
rm -rf $SRCDIR/dist
$PYTHON $SRCDIR/setup.py build -e "$PYTHON -E -s"
$PYTHON $SRCDIR/setup.py install
############################################################################
# Build Package
############################################################################
echo -n -e "\033]0;Build: Package Salt\007"
$PKGRESOURCES/build_pkg.sh $VERSION $PKGDIR
################################################################################
# Sign Binaries built by Salt
################################################################################
echo -n -e "\033]0;Build: Sign Binaries\007"
$PKGRESOURCES/sign_binaries.sh
############################################################################
# Sign Package
############################################################################
$PKGRESOURCES/build_sig.sh salt-$VERSION-py3-$CPUARCH.pkg salt-$VERSION-py3-$CPUARCH-signed.pkg
################################################################################
# Build and Sign Package
################################################################################
echo -n -e "\033]0;Build: Package Salt\007"
$PKGRESOURCES/package.sh $VERSION $PKGDIR
################################################################################
# Notarize Package
################################################################################
echo -n -e "\033]0;Build: Notarize Salt\007"
$PKGRESOURCES/notarize.sh salt-$VERSION-py3-$CPUARCH-signed.pkg

View file

@ -1,6 +1,5 @@
#!/bin/bash
############################################################################
################################################################################
#
# Title: Build Environment Script for macOS
# Authors: CR Oldham, Shane Lee
@ -25,19 +24,19 @@
#
# ./dev_env.sh
#
############################################################################
################################################################################
############################################################################
################################################################################
# Make sure the script is launched with sudo
############################################################################
################################################################################
if [[ $(id -u) -ne 0 ]]
then
exec sudo /bin/bash -c "$(printf '%q ' "$BASH_SOURCE" "$@")"
fi
############################################################################
################################################################################
# Set to Exit on all Errors
############################################################################
################################################################################
trap 'quit_on_error $LINENO $BASH_COMMAND' ERR
quit_on_error() {
@ -45,9 +44,9 @@ quit_on_error() {
exit -1
}
############################################################################
################################################################################
# Parameters Required for the script to function properly
############################################################################
################################################################################
echo -n -e "\033]0;Build_Env: Variables\007"
MACOSX_DEPLOYMENT_TARGET=10.13
@ -77,9 +76,9 @@ PIP=$INSTALL_DIR/bin/pip3
export PKG_CONFIG
export PKG_CONFIG_PATH
############################################################################
################################################################################
# Determine Which XCode is being used (XCode or XCode Command Line Tools)
############################################################################
################################################################################
# Prefer Xcode command line tools over any other gcc installed (e.g. MacPorts,
# Fink, Brew)
# Check for Xcode Command Line Tools first
@ -93,10 +92,10 @@ else
exit -1
fi
############################################################################
################################################################################
# Download Function
# - Downloads and verifies the MD5
############################################################################
################################################################################
download(){
if [ -z "$1" ]; then
echo "Must pass a URL to the download function"
@ -130,9 +129,9 @@ download(){
return $?
}
############################################################################
################################################################################
# Ensure Paths are present and clean
############################################################################
################################################################################
echo "################################################################################"
echo "Ensure Paths are present and clean"
echo "################################################################################"
@ -148,9 +147,9 @@ rm -rf build
mkdir -p build
BUILDDIR=$SCRIPTDIR/build
############################################################################
################################################################################
# Download and install pkg-config
############################################################################
################################################################################
echo -n -e "\033]0;Build_Env: pkg-config: download\007"
PKGURL="http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz"
@ -171,9 +170,9 @@ $MAKE check
echo -n -e "\033]0;Build_Env: pkg-config: make install\007"
$MAKE install
############################################################################
################################################################################
# Download and install libsodium
############################################################################
################################################################################
echo -n -e "\033]0;Build_Env: libsodium: download\007"
PKGURL="https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz"
@ -194,9 +193,9 @@ $MAKE check
echo -n -e "\033]0;Build_Env: libsodium: make install\007"
$MAKE install
############################################################################
################################################################################
# Download and install zeromq
############################################################################
################################################################################
echo -n -e "\033]0;Build_Env: zeromq: download\007"
PKGURL="https://github.com/zeromq/zeromq4-1/releases/download/v4.1.7/zeromq-4.1.7.tar.gz"
@ -218,9 +217,9 @@ $MAKE check
echo -n -e "\033]0;Build_Env: zeromq: make install\007"
$MAKE install
############################################################################
################################################################################
# Download and install OpenSSL
############################################################################
################################################################################
echo -n -e "\033]0;Build_Env: OpenSSL: download\007"
PKGURL="http://openssl.org/source/openssl-1.0.2u.tar.gz"
@ -241,9 +240,9 @@ $MAKE test
echo -n -e "\033]0;Build_Env: OpenSSL: make install\007"
$MAKE install
############################################################################
################################################################################
# Download and install Python
############################################################################
################################################################################
echo -n -e "\033]0;Build_Env: Python: download\007"
# if $1 is true the we should remove the --enable-optimizations flag to get a quicker
# build if testing other functions of this script
@ -270,14 +269,14 @@ $MAKE
echo -n -e "\033]0;Build_Env: Python: make install\007"
$MAKE install
############################################################################
################################################################################
# upgrade pip
############################################################################
################################################################################
$PIP install --upgrade pip wheel
############################################################################
################################################################################
# Download and install salt python dependencies
############################################################################
################################################################################
echo -n -e "\033]0;Build_Env: PIP Dependencies\007"
cd $BUILDDIR

View file

@ -1,57 +0,0 @@
#!/bin/bash
############################################################################
#
# Title: Sign Package Script for macOS
# Authors: Shane Lee
# Date: December 2015
#
# Description: This signs an macOS Installer Package (.pkg)
# /opt/salt
#
# Requirements:
# - Xcode Command Line Tools (xcode-select --install)
# - A valid signing certificate in the login.keychain. Signing Certificates
# can be optained from the Apple Developer site.
#
# Usage:
# This script must be passed 2 parameters
# $1 : <source package> : the package that will be signed
# $2 : <signed package> : the name to give the signed package (can't be
# the same as the source package)
#
# Example:
# The following will sign the 'salt-v2015.8.3.pkg' file and save it as
# 'salt-v2015.8.3.signed.pkg'
#
# ./build_sig.sh salt-v2015.8.3.pkg salt-v2015.8.3.signed.pkg
#
############################################################################
############################################################################
# Check input parameters
############################################################################
if [ "$1" == "" ]; then
echo "Must supply a source package"
else
INPUT=$1
fi
if [ "$2" == "" ]; then
echo "Must supply a signed package name"
else
OUTPUT=$2
fi
############################################################################
# Import the Salt Developer Signing certificate
############################################################################
security import "Developer ID Installer.p12" -k ~/Library/Keychains/login.keychain
############################################################################
# Sign the package
############################################################################
productsign --sign "Developer ID Installer: Salt Stack, Inc. (VK797BMMY4)" $INPUT $OUTPUT
#
# codesign --sign "Developer ID Application: Salt Stack, Inc. (XXXXXXXXXX)" $INPUT $OUTPUT
# https://developer.apple.com/documentation/xcode/notarizing_macos_software_before_distribution?language=objc
# stapler or altool

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>

107
pkg/osx/notarize.sh Executable file
View file

@ -0,0 +1,107 @@
#!/bin/bash
################################################################################
#
# Title: Notarize Package Script for the macOS installer
# Author: Shane Lee
# Date: December 2020
#
# Description: This notarizes the macOS Installer Package (.pkg)
#
# Requirements:
# - Xcode Command Line Tools (xcode-select --install)
#
# Usage:
# This script must be passed 2 parameters
#
# $1 : <package>
# The package that will be notarized (must be signed)
#
# Example:
# The following will notarize the 'salt-v2015.8.3-signed.pkg' file
#
# ./notarize.sh salt-v2015.8.3-signed.pkg
#
# Environment Setup:
#
# Define Environment Variables:
# Create two environment variables for the apple account and the
# app-specific password associated with that account. To generate the
# app-specific password see: https://support.apple.com/en-us/HT204397
#
# export APPLE_ACCT="username@domain.com"
# export APP_SPEC_PWD="abcd-efgh-ijkl-mnop"
#
################################################################################
echo "#########################################################################"
echo "Notarize Salt Package"
################################################################################
# Check input parameters
################################################################################
if [ "$1" == "" ]; then
echo "Must supply a package to notarize"
else
PACKAGE=$1
fi
################################################################################
# Environment Variables
################################################################################
echo "**** Setting Variables"
BUNDLE_ID="com.saltstack.salt"
NOTARIZE_APP_LOG=$(mktemp -t notarize-app)
NOTARIZE_INFO_LOG=$(mktemp -t notarize-info)
################################################################################
# Delete temporary files on exit
################################################################################
function finish {
rm "$NOTARIZE_APP_LOG" "$NOTARIZE_INFO_LOG"
}
trap finish EXIT
################################################################################
# Submit app for notarization
################################################################################
echo "**** Submitting Package for Notarization"
if ! xcrun altool --notarize-app \
--primary-bundle-id "$BUNDLE_ID" \
--username "$APPLE_ACCT" \
--password "$APP_SPEC_PWD" \
-f "$PACKAGE" > "$NOTARIZE_APP_LOG" 2>&1; then
cat "$NOTARIZE_APP_LOG" 1>&2
exit 1
fi
# Get RequestUUID from the APP LOG
cat "$NOTARIZE_APP_LOG"
RequestUUID=$(awk -F ' = ' '/RequestUUID/ {print $2}' "$NOTARIZE_APP_LOG")
echo "**** Checking Notarization Status"
# Check status every 30 seconds
while sleep 30 && date; do
echo "Waiting for Apple to approve the notarization so it can be stapled.
This can take a few minutes or more. Script auto checks every 30 sec"
# check notarization status
if ! xcrun altool --notarization-info "$RequestUUID" \
--username "$APPLE_ACCT" \
--password "$APP_SPEC_PWD" > "$NOTARIZE_INFO_LOG" 2>&1; then
cat "$NOTARIZE_INFO_LOG" 1>&2
exit 1
fi
# Look for Status in the INFO LOG
cat "$NOTARIZE_INFO_LOG"
# once notarization is complete, run stapler and exit
if ! grep -q "Status: in progress" "$NOTARIZE_INFO_LOG"; then
echo "**** Stapling Notarization to the Package"
xcrun stapler staple "$PACKAGE"
exit $?
fi
done
echo "Notarize Salt Package Completed Successfully"
echo "#########################################################################"

View file

@ -1,11 +1,11 @@
#!/bin/bash
############################################################################
################################################################################
#
# Title: Build Package Script for macOS
# Title: Build Package Script for the macOS installer
# Authors: CR Oldham, Shane Lee
# Date: December 2015
#
# Description: This creates an macOS package for Salt from the contents of
# Description: This creates a signed macOS package for Salt from the contents of
# /opt/salt
#
# Requirements:
@ -22,21 +22,42 @@
# The following will build Salt version 2017.7.0 with Python 3 and
# stage all files in /tmp/salt_pkg:
#
# ./build.sh 2017.7.0 3
# ./package.sh 2017.7.0 /tmp/salt_pkg
#
############################################################################
# Environment Setup:
#
# Import Certificates:
# Import the Salt Developer Installer Signing certificate using the
# following command:
#
# security import "developerID_installer.p12" -k ~/Library/Keychains/login.keychain
#
# NOTE: The .p12 certificate is required as the .cer certificate is
# is missing the private key. This can be created by exporting the
# certificate from the machine it was created on
#
# Define Environment Variables:
# Create an environment variable with the name of the certificate to use
# from the keychain for installer signing. Use the following command
# (The actual value must match what is provided in the certificate):
#
# export DEV_INSTALL_CERT="Developer ID Installer: Salt Stack, Inc. (AB123ABCD1)"
#
################################################################################
echo "#########################################################################"
echo "Building Salt Package"
############################################################################
################################################################################
# Make sure the script is launched with sudo
############################################################################
################################################################################
if [[ $(id -u) -ne 0 ]]
then
exec sudo /bin/bash -c "$(printf '%q ' "$BASH_SOURCE" "$@")"
fi
############################################################################
################################################################################
# Set to Exit on all Errors
############################################################################
################################################################################
trap 'quit_on_error $LINENO $BASH_COMMAND' ERR
quit_on_error() {
@ -44,9 +65,9 @@ quit_on_error() {
exit -1
}
############################################################################
################################################################################
# Check passed parameters, set defaults
############################################################################
################################################################################
# Get/Set Version
if [ "$1" == "" ]; then
VERSION=`git describe`
@ -63,17 +84,17 @@ fi
CPUARCH=`uname -m`
############################################################################
################################################################################
# Additional Parameters Required for the script to function properly
############################################################################
echo -n -e "\033]0;Build_Pkg: Variables\007"
################################################################################
echo "**** Setting Variables"
SRCDIR=`git rev-parse --show-toplevel`
PKGRESOURCES=$SRCDIR/pkg/osx
############################################################################
################################################################################
# Make sure this is the Salt Repository
############################################################################
################################################################################
if [[ ! -e "$SRCDIR/.git" ]] && [[ ! -e "$SRCDIR/scripts/salt" ]]; then
echo "This directory doesn't appear to be a git repository."
echo "The macOS build process needs some files from a Git checkout of Salt."
@ -81,27 +102,27 @@ if [[ ! -e "$SRCDIR/.git" ]] && [[ ! -e "$SRCDIR/scripts/salt" ]]; then
exit -1
fi
############################################################################
################################################################################
# Ensure Paths are present and clean
############################################################################
echo -n -e "\033]0;Build_Pkg: Clean Staging Area\007"
################################################################################
echo "**** Cleaning Staging Area"
# Clean folder in the staging area
rm -rdf $PKGDIR
mkdir -p $PKGDIR
############################################################################
################################################################################
# Copy Start Scripts from Salt Repo to /opt/salt
############################################################################
echo -n -e "\033]0;Build_Pkg: Copy Start Scripts\007"
################################################################################
echo "**** Copying Start Scripts"
cp $PKGRESOURCES/scripts/start-*.sh /opt/salt/bin/
cp $PKGRESOURCES/scripts/salt-config.sh /opt/salt/bin
############################################################################
################################################################################
# Copy Service Definitions from Salt Repo to the Package Directory
############################################################################
echo -n -e "\033]0;Build_Pkg: Copy Service Definitions\007"
################################################################################
echo "**** Copying Service Definitions"
mkdir -p $PKGDIR/opt
cp -r /opt/salt $PKGDIR/opt
@ -112,10 +133,10 @@ cp $PKGRESOURCES/scripts/com.saltstack.salt.master.plist $PKGDIR/Library/LaunchD
cp $PKGRESOURCES/scripts/com.saltstack.salt.syndic.plist $PKGDIR/Library/LaunchDaemons
cp $PKGRESOURCES/scripts/com.saltstack.salt.api.plist $PKGDIR/Library/LaunchDaemons
############################################################################
################################################################################
# Remove unnecessary files from the package
############################################################################
echo -n -e "\033]0;Build_Pkg: Trim unneeded files\007"
################################################################################
echo "**** Trimming Unneeded Files"
rm -rdf $PKGDIR/opt/salt/bin/pkg-config
rm -rdf $PKGDIR/opt/salt/lib/pkgconfig
@ -126,22 +147,22 @@ rm -rdf $PKGDIR/opt/salt/share/man/man1/pkg-config.1
rm -rdf $PKGDIR/opt/salt/lib/python3.7/test
echo -n -e "\033]0;Build_Pkg: Remove compiled python files\007"
echo "**** Removing Compiled Python Files (.pyc)"
find $PKGDIR/opt/salt -name '*.pyc' -type f -delete
############################################################################
################################################################################
# Copy Config Files from Salt Repo to the Package Directory
############################################################################
echo -n -e "\033]0;Build_Pkg: Copy Config Files\007"
################################################################################
echo "**** Copying Config Files"
mkdir -p $PKGDIR/etc/salt
cp $SRCDIR/conf/minion $PKGDIR/etc/salt/minion.dist
cp $SRCDIR/conf/master $PKGDIR/etc/salt/master.dist
############################################################################
# Add Version and CPU Arch to distribution.xml
############################################################################
echo -n -e "\033]0;Build_Pkg: Add Version to .xml\007"
################################################################################
# Add Title, Description, Version and CPU Arch to distribution.xml
################################################################################
echo "**** Modifying distribution.xml"
TITLE="Salt $VERSION (Python 3)"
DESC="Salt $VERSION with Python 3"
@ -161,19 +182,27 @@ sed -E -i '' "$SEDSTR" distribution.xml
SEDSTR="s/@CPUARCH@/$CPUARCH/g"
sed -i '' "$SEDSTR" distribution.xml
############################################################################
################################################################################
# Build the Package
############################################################################
echo -n -e "\033]0;Build_Pkg: Build Package\007"
################################################################################
echo "**** Building the Source Package"
# Build the src package
pkgbuild --root=$PKGDIR \
--scripts=pkg-scripts \
--identifier=com.saltstack.salt \
--version=$VERSION \
--ownership=recommended salt-src-$VERSION-py3-$CPUARCH.pkg
--ownership=recommended \
salt-src-$VERSION-py3-$CPUARCH.pkg
echo "**** Building and Signing the Product Package with Timestamp"
productbuild --resources=pkg-resources \
--distribution=distribution.xml \
--package-path=salt-src-$VERSION-py3-$CPUARCH.pkg \
--version=$VERSION salt-$VERSION-py3-$CPUARCH.pkg
--version=$VERSION \
--sign "$DEV_INSTALL_CERT" \
--timestamp \
salt-$VERSION-py3-$CPUARCH-signed.pkg
echo "Building Salt Package Completed Successfully"
echo "#########################################################################"

110
pkg/osx/sign_binaries.sh Executable file
View file

@ -0,0 +1,110 @@
#!/bin/bash
################################################################################
#
# Title: Binary Signing Script for the macOS installer
# Author: Shane Lee
# Date: December 2020
#
# Description: This signs all binaries built by the `build_env.sh` script as
# well as those created by installing salt. It assumes a python
# environment in /opt/salt with salt installed
#
# Requirements:
# - Xcode Command Line Tools (xcode-select --install)
#
# Usage:
# This script ignores any parameters passed to it
#
# Example:
#
# sudo ./sign_binaries
#
# Environment Setup:
#
# Import Certificates:
# Import the Salt Developer Application Signing certificate using the
# following command:
#
# security import "developerID_application.p12" -k ~/Library/Keychains/login.keychain
#
# NOTE: The .p12 certificate is required as the .cer certificate is
# is missing the private key. This can be created by exporting the
# certificate from the machine it was created on
#
# Define Environment Variables:
# Create an environment variable with the name of the certificate to use
# from the keychain for binary signing. Use the following command (The
# actual value must match what is provided in the certificate):
#
# export DEV_APP_CERT="Developer ID Application: Salt Stack, Inc. (AB123ABCD1)"
#
################################################################################
echo "#########################################################################"
echo "Signing Binaries"
################################################################################
# Make sure the script is launched with sudo
################################################################################
if [[ $(id -u) -ne 0 ]]
then
exec sudo /bin/bash -c "$(printf '%q ' "$BASH_SOURCE" "$@")"
fi
################################################################################
# Set to Exit on all Errors
################################################################################
trap 'quit_on_error $LINENO $BASH_COMMAND' ERR
quit_on_error() {
echo "$(basename $0) caught error on line : $1 command was: $2"
exit -1
}
################################################################################
# Environment Variables
################################################################################
echo "**** Setting Variables"
INSTALL_DIR=/opt/salt
################################################################################
# Sign python binaries in `bin` and `lib`
################################################################################
echo "**** Signing binaries that have entitlements (/opt/salt/bin)"
find ${INSTALL_DIR}/bin \
-type f \
-perm -u=x \
-exec codesign --timestamp \
--options=runtime \
--verbose \
--entitlements ./entitlements.plist \
--sign "$DEV_APP_CERT" "{}" \;
echo "**** Signing binaries (/opt/salt/lib)"
find ${INSTALL_DIR}/lib \
-type f \
-perm -u=x \
-exec codesign --timestamp \
--options=runtime \
--verbose \
--sign "$DEV_APP_CERT" "{}" \;
echo "**** Signing dynamic libraries (*dylib) (/opt/salt/lib)"
find ${INSTALL_DIR}/lib \
-type f \
-name "*dylib" \
-exec codesign --timestamp \
--options=runtime \
--verbose \
--sign "$DEV_APP_CERT" "{}" \;
echo "**** Signing shared libraries (*.so) (/opt/salt/lib)"
find ${INSTALL_DIR}/lib \
-type f \
-name "*.so" \
-exec codesign --timestamp \
--options=runtime \
--verbose \
--sign "$DEV_APP_CERT" "{}" \;
echo "**** Signing Binaries Completed Successfully"
echo "#########################################################################"