Skip to content

Notarize the GitX app#334

Merged
hannesa2 merged 2 commits intomasterfrom
feature/Apple-Notary-Submission
Sep 18, 2022
Merged

Notarize the GitX app#334
hannesa2 merged 2 commits intomasterfrom
feature/Apple-Notary-Submission

Conversation

@insha
Copy link
Copy Markdown
Collaborator

@insha insha commented Sep 16, 2022

Changes include:

  • Hardened Runtime entitlement has been added to all targets
  • BuildPR workflow has been updated to include step to keychain prep with certificate and provisioning profile, archive, export, and notarize the resulting binary.

💡 Author's Note
This is a work in progress and will need testing and fine tuning. All secrets have been added to the repository using GitHub Secrets and used by the action workflow. Please do leave feedback, if any, thank you.

@insha insha force-pushed the feature/Apple-Notary-Submission branch 4 times, most recently from cb671fd to 3c297b7 Compare September 16, 2022 20:57
Changes include:
- Hardened Runtime entitlement has been added to all targets
- BuildPR workflow has been updated to include step to keychain prep with certificate and provisioning profile, archive, export, and notarize the resulting binary.
@insha insha force-pushed the feature/Apple-Notary-Submission branch from 3c297b7 to 726339f Compare September 16, 2022 21:20
@insha insha added enhancement WIP Work in progress labels Sep 16, 2022
@hannesa2 hannesa2 removed the WIP Work in progress label Sep 18, 2022
@hannesa2 hannesa2 force-pushed the feature/Apple-Notary-Submission branch from dc8185c to ef79590 Compare September 18, 2022 16:14
Copy link
Copy Markdown
Contributor

@hannesa2 hannesa2 left a comment

Choose a reason for hiding this comment

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

Nice, even the verify of the notarization shows me an "accepted"

image

It looks good to me, any improvement can be done later too

xcrun stapler staple "$APP_PATH"
ditto -c -k --keepParent "$APP_PATH" "$ZIP_PATH"
- name: Check Notarization
run: spctl -a -vv GitX.app
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I added this verify of the notarization

@hannesa2 hannesa2 changed the title WIP: Adding notarization steps to the CI pipeline Notarizate the GitX app Sep 18, 2022
@hannesa2 hannesa2 merged commit 7cc0658 into master Sep 18, 2022
@hannesa2 hannesa2 deleted the feature/Apple-Notary-Submission branch September 18, 2022 16:28
@hannesa2
Copy link
Copy Markdown
Contributor

Thanks a lot of your generous help here @insha

@hannesa2 hannesa2 changed the title Notarizate the GitX app Notarize the GitX app Sep 18, 2022
@hannesa2
Copy link
Copy Markdown
Contributor

Unfortunately we only notarize the pull request pipeline, and forgot the release. I will drop the release and recreate it again

@insha
Copy link
Copy Markdown
Collaborator Author

insha commented Sep 18, 2022 via email

@hannesa2
Copy link
Copy Markdown
Contributor

Also do we need the notary steps for the PR flow?

I already did it

@insha
Copy link
Copy Markdown
Collaborator Author

insha commented Sep 18, 2022 via email

env:
EXPORT_OPTIONS: ${{ secrets.NOTARY_EXPORT_OPTIONS }}
run: |
mv GitX.xcarchive/Products/Applications/GitX.app .
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's about #337 and #336
@insha Before we move GitX.xcarchive/Products/Applications/GitX.app to root .

run: cd External/objective-git && script/bootstrap && script/update_libgit2 && cd ../..
- name: Build project
run: xcodebuild -workspace GitX.xcworkspace -scheme GitX -archivePath ./GitX archive ARCHS="${{ matrix.abi }}"
run: xcodebuild -workspace GitX.xcworkspace -scheme GitX -archivePath ./GitX archive ARCHS="${{ matrix.abi }}" PRODUCT_BUNDLE_IDENTIFIER=${{ secrets.NOTARY_BUNDLE_IDENTIFIER}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@insha can it be this secrets.NOTARY_BUNDLE_IDENTIFIER can have a relation to this meaning identifier net.phere.GitX ?


echo -n "$EXPORT_OPTIONS" > EXPORT_OPTIONS_PATH

xcodebuild -exportArchive -archivePath GitX.xcarchive -exportPath . -exportOptionsPlist EXPORT_OPTIONS_PATH
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now we create a new archive and using this. Not sure if this is an issue

@insha
Copy link
Copy Markdown
Collaborator Author

insha commented Sep 19, 2022 via email

@hannesa2
Copy link
Copy Markdown
Contributor

This sounds promising.

To clarify this secrets.NOTARY_BUNDLE_IDENTIFIER :
Which one do you used for notarizing to be clear what I should use in kGitXBundleIdentifier in the GitXScriptingConstants.h ?

@insha
Copy link
Copy Markdown
Collaborator Author

insha commented Sep 20, 2022 via email

@ADTC
Copy link
Copy Markdown
Contributor

ADTC commented Feb 25, 2023

@insha can you please check why PR builds are failing?

image

@ADTC
Copy link
Copy Markdown
Contributor

ADTC commented Feb 25, 2023

@hannesa2 It looks like the environment variables from the GitHub Actions secrets are coming up as empty.

image

These secrets would be shown masked with asterisks, not removed completely, as you can see from this old build log.

Can you please check the settings?

@ADTC
Copy link
Copy Markdown
Contributor

ADTC commented Feb 25, 2023

Quick update: The secrets and variables for actions are not passed to workflows that are triggered by a pull request from a fork (using pull_request event).

From GitHub documentation (suggested by this comment), I'm gathering three ideas on how to resolve this:

  1. Use the pull_request_target event instead to run the workflow in the context of the PR's base. Apparently this event type will have access to secrets. This won't work because the base context will not contain the changes in the PR.
  2. Use two workflows, first with pull_request that does nothing, and a second with workflow_run which runs when the first one has completed. Apparently, the second workflow will have access to secrets. This won't work because it can only run from the default branch.
  3. Have a separate workflow for pull_request event which doesn't make use of any secret. In our case, it means it shouldn't attempt to notarize the build. It should just do a normal build without any Apple certificate or notarization (which isn't required for a PR build anyway).

ADTC added a commit to ADTC/gitx that referenced this pull request Feb 25, 2023
Pull requests opened from forks will not have access to secrets and variables. We don't need to notarize builds on the master branch or on pull requests. Only the builds from BuildRelease workflow file need to be notarized before making a release.
@hannesa2
Copy link
Copy Markdown
Contributor

The variables are all there and all is fine concerning this
image

@ADTC
Copy link
Copy Markdown
Contributor

ADTC commented Feb 25, 2023

That's good to know. But they can't be accessed in a forked PR for security reasons. It's a GitHub limitation to safeguard against leaks. That's why the PRs must build without needing any secret. Anyway we don't need to notarize builds in PR. We just need to know that the builds are successful.

@hannesa2
Copy link
Copy Markdown
Contributor

Please see my recommendation #365 (review)

run: xcodebuild -workspace GitX.xcworkspace -scheme GitX -archivePath ./GitX archive ARCHS="${{ matrix.abi }}" PRODUCT_BUNDLE_IDENTIFIER=${{ secrets.NOTARY_BUNDLE_IDENTIFIER}}
- name: Prepare artifact
env:
EXPORT_OPTIONS: ${{ secrets.NOTARY_EXPORT_OPTIONS }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@insha
I try to do the same on an other project, but I've no clue what's the content of NOTARY_EXPORT_OPTIONS is.
I guess it's not a secret, am I right ?
If yes, please can you write me the content of it ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@hannesa2 Apologies for the delayed response. The value of this secret variable is the contents of the export options plist file. It is in secrets because it contains my Apple Team ID. The contents are as follows with my team ID redacted:

<?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>destination</key>
	<string>export</string>
	<key>method</key>
	<string>developer-id</string>
	<key>provisioningProfiles</key>
	<dict>
		<key>com.themacronaut.net.phere.GitX</key>
		<string>GitX Notarized Distribution</string>
	</dict>
	<key>signingCertificate</key>
	<string>Developer ID Application</string>
	<key>signingStyle</key>
	<string>manual</string>
	<key>teamID</key>
	<string>---REDACTED---</string>
</dict>
</plist>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You mean to say the entire XML content is put inside an environment variable? 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, from what I recall, that is correct. The reason being that the plist files has sensitive information in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants