Skip to content

Add MacOS signing #33

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
rake_checks:
name: Rake Checks
runs-on: ubuntu-latest
strategy:
matrix:
check: [ 'rubocop', 'commits' ]
steps:
- name: Checkout current PR
uses: actions/checkout@v4
Expand All @@ -29,4 +26,4 @@ jobs:
run: |
gem update --system --silent --no-document
bundle install --jobs 4 --retry 3
- run: bundle exec rake ${{ matrix.check }} --trace
- run: bundle exec rake rubocop --trace
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vendor/*
output/*
signed/*
.bundle
Gemfile.lock
Gemfile.local
Expand Down
5 changes: 2 additions & 3 deletions configs/projects/openvox-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
proj.extra_file_to_sign File.join(proj.bindir, 'puppet')
proj.extra_file_to_sign File.join(proj.bindir, 'pxp-agent')
proj.extra_file_to_sign File.join(proj.bindir, 'wrapper.sh')
proj.signing_hostname 'osx-signer-prod-3.delivery.puppetlabs.net'
proj.signing_username 'jenkins'
proj.signing_command 'security -q unlock-keychain -p \$$OSX_SIGNING_KEYCHAIN_PW \$$OSX_SIGNING_KEYCHAIN; codesign --timestamp --keychain \$$OSX_SIGNING_KEYCHAIN -vfs \"\$$OSX_CODESIGNING_CERT\"'
proj.use_local_signing true
proj.signing_command 'codesign --timestamp --keychain $$OSX_SIGNING_KEYCHAIN -vfs "$$OSX_CODESIGNING_CERT"'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I have it set up to run as root and imported into the System keychain on my VM, we don't need to specifically unlock the keychain. Later on, when we move this into GHA, we may want a separate keychain, or we may end up doing this entirely differently.

end

if platform.is_fedora? || platform.name =~ /el-10/
Expand Down
45 changes: 45 additions & 0 deletions tasks/sign.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'fileutils'

# Adapted from https://github.com/puppetlabs/packaging/blob/15da180e9574e4582c096b0537334627d3f0f814/lib/packaging/sign/dmg.rb#L43
# Likely we can make this better at some point, probably integrating into Vanagon itself.
namespace :vox do
desc 'Sign package with installer signing key'
task :sign, [:tag] do |_, args|
abort 'You must provide a tag.' if args[:tag].nil? || args[:tag].empty?
dmgs = Dir.glob("#{__dir__}/../output/**/*#{args[:tag]}*.dmg")
abort 'No files for the given tag found in the output directory.' if dmgs.empty?

mnt = Dir.mktmpdir('mnt')
puts "Temporary mount dir is #{mnt}"
working = Dir.mktmpdir('working')
puts "Temporary working dir is #{working}"
begin
FileUtils.mkdir_p('./signed')
dmgs.each do |dmg|
dmg_basename = File.basename(dmg)
puts "Signing #{dmg_basename}"
puts "Mounting dmg"
run_command("/usr/bin/hdiutil attach #{dmg} -mountpoint #{mnt} -nobrowse")
Dir.glob("#{mnt}/*").each do |f|
f_basename = File.basename(f)
if f.end_with?('.pkg')
puts "Signing #{f_basename}"
run_command("/usr/bin/productsign --keychain \"${OSX_SIGNING_KEYCHAIN}\" --sign \"${OSX_DMGSIGNING_CERT}\" #{f} #{working}/#{f_basename}")
else
puts "Copying #{f_basename}"
FileUtils.cp(f, "#{working}/#{f_basename}")
end
end
puts "Detatching dmg"
run_command("/usr/bin/hdiutil detach #{mnt} -quiet")
puts "Creating dmg with signed package"
run_command("/usr/bin/hdiutil create -volname #{dmg_basename} -size 500m -srcfolder #{working}/ ./signed/#{dmg_basename}")
puts "Signed package dmg at signed/#{dmg_basename}"
FileUtils.rm_rf("#{working}/*")
end
ensure
FileUtils.rm_rf(mnt)
FileUtils.rm_rf(working)
end
end
end