Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Conversation

@vdye
Copy link
Collaborator

@vdye vdye commented Mar 6, 2023

Summary

This pull request is a follow-up to #12, adding infrastructure to sign and notarize the MacOS .pkgs we generate.

  • The first commit deals with signing the package: first its contents (using codesign), then the .pkg itself. These steps require two different signing certificates; see this post for more information about the former, and this one for more on the latter.

  • The second commit adds a step to notarize the generated package, then "staples" the notarization ticket to the package so that Gatekeeper can approve the install without accessing the internet. This documentation explains the process.

  • The third commit integrates this signing process into the release.yml workflow. To add some protections around the Apple credentials we're using to sign and notarize, the MacOS packaging steps are moved into the (approval-required, branch/tag pattern-protected) release environment with the appropriate secrets (more on hat later). Before the make package execution, a step is added to set up the certificates & notarization credential in the local keychain. If those credentials aren't present, the workflow logs a warning and builds the package without signing; hopefully, this will make it easier for developers to modify/test the workflow in their forks.

Testing

At this time, I don't yet have valid certificates to sign with (working on that separately). However, I was able to test that the workflow at least sets up credentials and tries to perform the correct operations, depending on the environment:

  1. I first tested with no secrets in the release environment. The workflow correctly identified that neither signing nor notarization could be configured and did neither, resulting in a successful (albeit unsigned) execution. Link.

  2. Next, I added a self-signed certificate as the application & installer certificate. The certificates were set up correctly, but notarization was not. The workflow found and used the certificates as intended, but because productbuild --sign doesn't appear to work with self-signed certs, the workflow failed. Link.

  3. Finally, I added notarization credentials. Now, the certificates and notarization profile are set up correctly, although the workflow still fails due to the invalid certificate. Link.

Across all of these tests, I was prompted to approve use of the release environment (as configured). I also verified that the "branch" protection rule (it also matches tags, which is used in this situation) on the environment was working correctly by changing it to something that didn't match the release tags. Link.

To verify the notarization piece (since the earlier tests didn't even reach it), I pushed a modified version of this branch that disables the codesigning steps of make package so it would attempt to notarize an unsigned package. That fails as expected (notarytool won't notarize an unsigned package), but the behavior otherwise appears to be correct. Link.

@vdye vdye force-pushed the vdye/sign-macos-artifacts branch from dc556cd to 81da3ef Compare March 7, 2023 23:59
@vdye vdye temporarily deployed to release March 8, 2023 00:13 — with Image GitHub Actions Inactive
@vdye vdye temporarily deployed to release March 8, 2023 00:13 — with Image GitHub Actions Inactive
@vdye vdye force-pushed the vdye/sign-macos-artifacts branch from 81da3ef to 2e1167c Compare March 9, 2023 18:25
@vdye vdye changed the title DO NOT REVIEW YET: Add MacOS signing & notarization to release workflow Add MacOS signing & notarization to release workflow Mar 9, 2023
@vdye vdye marked this pull request as ready for review March 9, 2023 19:12
@vdye vdye self-assigned this Mar 9, 2023
@vdye vdye added this to the v1.0 milestone Mar 9, 2023
Copy link
Collaborator

@ldennington ldennington left a comment

Choose a reason for hiding this comment

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

Nice! Great job adding the flexibility to sign/not sign, notarize/not notarize, etc. I'll get a ticket made up to move GCM and microsoft/git's sensitive signing secrets into environments as well.

Copy link
Collaborator

@derrickstolee derrickstolee left a comment

Choose a reason for hiding this comment

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

A lot of this is over my head, but the proof is in the pudding build.

--identity="$(APPLE_APP_IDENTITY)" \
--entitlements="$(CURDIR)/build/package/pkg/entitlements.xml"

$(PKG_FILENAME): codesign
Copy link
Collaborator

Choose a reason for hiding this comment

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

Neat that you can conditionally add dependencies like this.

@vdye vdye temporarily deployed to release March 15, 2023 22:17 — with Image GitHub Actions Inactive
@vdye vdye temporarily deployed to release March 15, 2023 22:17 — with Image GitHub Actions Inactive
@vdye
Copy link
Collaborator Author

vdye commented Mar 15, 2023

After configuring the repository's signing and notarization settings, the release build succeeds (link) and all artifacts are properly signed & notarized! 🎉 The branch is now out-of-date with main, so after a rebase I'll merge.

vdye added 3 commits March 15, 2023 15:30
Add a new script 'codesign.sh' to sign the contents of a given MacOS
directory with the appropriate Apple Developer ID certificate (assumed to
already be set up in a keychain). Add a 'codesign' target to the 'make
package' workflow that only runs if the 'APPLE_APP_IDENTITY' build variable
is set.

Additionally, add an '--identity' argument to 'pack.sh' to sign the .pkg
generated by 'productbuild' - if 'APPLE_INST_IDENTITY' is not set, the .pkg
is not signed.

Note that the signing identities for 'codesign.sh' and 'pack.sh' are
different variables: 'APPLE_APP_IDENTITY' is the application
signing identity, and 'APPLE_INST_IDENTITY' is the installer signing
identity. More information on this signing process can be found at [1] and
[2].

Finally, change the temporary package name suffix from '.tmp' to
'.component' to more clearly indicate that it is a component package.

[1] https://developer.apple.com/forums/thread/701514
[2] https://developer.apple.com/forums/thread/701581

Signed-off-by: Victoria Dye <[email protected]>
Add a 'notarize.sh' script to notarize the generated package with the
environment-specified credential profile. The script is only run if the
signing build variables and 'APPLE_KEYCHAIN_PROFILE' are set, since Apple
notarization can only succeed if the package contents *and* the resulting
package are properly signed.

Signed-off-by: Victoria Dye <[email protected]>
Add a step to set up the signing keychain for signing the MacOS package
contents with the Apple Developer certificates, and enable
signing/notarization in the 'make package' build that generates the
artifacts.

In order to make the signing process more secure, the MacOS packaging jobs
are performed in a 'release' environment.

Note that it is possible to run the workflow with no signing/notarization,
signing-only (no notarization), or both signing & notarization; the behavior
depends on which workflow secrets are set. This ensures that artifacts can
be successfully built in a variety of environments, making it easier for
forks to test the release build should they want to.

Signed-off-by: Victoria Dye <[email protected]>
@vdye vdye force-pushed the vdye/sign-macos-artifacts branch from 2e1167c to 051d636 Compare March 15, 2023 22:30
@vdye vdye merged commit 3c0554e into main Mar 15, 2023
@vdye vdye deleted the vdye/sign-macos-artifacts branch March 15, 2023 22:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants