signing.adoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # Release signing
  2. OliveTin signs release binaries on two platforms:
  3. * **macOS** — Developer ID + notarization via [quill](https://github.com/anchore/quill) in a separate GitHub Actions job (signed darwin tarballs are uploaded after the release is published).
  4. * **Windows** — Authenticode via [SignPath Foundation](https://signpath.org/) in a separate GitHub Actions job (signed zip/MSI are uploaded after the release is published).
  5. ## macOS release signing
  6. Release builds sign and notarize the `darwin` binaries using [quill](https://github.com/anchore/quill). This runs on a Linux CI runner; no macOS runner or Xcode is required.
  7. Like Windows signing, this happens **after** the release is published, so a problem on Apple's side cannot block a release:
  8. 1. GoReleaser builds `OliveTin-darwin-{amd64,arm64}.tar.gz` unsigned and leaves them out of the GitHub release and `checksums.txt`. The `build` job uploads them as the `unsigned-darwin` workflow artifact.
  9. 2. The `sign-macos` job checks the `.p12` chain, then signs and notarizes each binary with quill, repacks the tarballs and checks the designated requirement.
  10. 3. The job uploads the signed tarballs to the release and adds their lines to `checksums.txt`.
  11. If `sign-macos` fails (for example an expired Apple agreement, a notary outage or a certificate problem), the release stays published without macOS assets. Fix the cause, then use **Re-run failed jobs** on that workflow run. The unsigned artifact must still be within its retention period.
  12. `sign-windows` and `sign-macos` share a concurrency group, so they never update `checksums.txt` at the same time.
  13. ### Prerequisites
  14. - An active [Apple Developer Program](https://developer.apple.com/programs/) membership.
  15. - A **Developer ID Application** certificate (not "Apple Development" or "Mac App Distribution").
  16. - An [App Store Connect API key](https://appstoreconnect.apple.com/access/integrations/api) with at least **Developer** access.
  17. ### One-time setup
  18. #### 1. Create the signing certificate (OpenSSL, no Mac/Xcode)
  19. Work in a private directory. Keep the private key offline and never commit it.
  20. ```sh
  21. mkdir -p ~/apple-signing && cd ~/apple-signing
  22. chmod 700 .
  23. openssl genrsa -out developer_id_app.key 2048
  24. openssl req -new -key developer_id_app.key -out developer_id_app.csr \
  25. -subj "/emailAddress=you@example.com/CN=Your Name/C=GB"
  26. ```
  27. 1. Open [Certificates, Identifiers & Profiles](https://developer.apple.com/account/resources/certificates/list).
  28. 2. Create a certificate of type **Developer ID Application**. Prefer **G2 Sub-CA** if the portal asks.
  29. 3. Upload `developer_id_app.csr` and download the resulting `.cer` (often named `developerID_application.cer`).
  30. Build a `.p12` that includes the **full** chain: leaf + Developer ID G2 intermediate + Apple Root CA.
  31. The Apple Root **must** be present. With only leaf + G2, quill embeds a designated requirement of the form `certificate root[field.1.2.840.113635.100.6.2.6]`. On macOS that resolves to Apple Root CA (which does not have that OID), so AMFI SIGKILLs the binary with `does not satisfy its designated Requirement` even though notarization still succeeds. A correct chain produces `certificate 1[...]` instead.
  32. ```sh
  33. curl -fsSLO https://www.apple.com/certificateauthority/DeveloperIDG2CA.cer
  34. curl -fsSLO https://www.apple.com/appleca/AppleIncRootCertificate.cer
  35. openssl x509 -inform DER -in developerID_application.cer -out developerID_application.pem
  36. openssl x509 -inform DER -in DeveloperIDG2CA.cer -out DeveloperIDG2CA.pem
  37. openssl x509 -inform DER -in AppleIncRootCertificate.cer -out AppleRootCA.pem
  38. # Chain file: intermediate then root (leaf is passed separately via -in).
  39. cat DeveloperIDG2CA.pem AppleRootCA.pem > chain.pem
  40. # Export password becomes MACOS_SIGN_PASSWORD.
  41. # On OpenSSL 3 (e.g. Fedora), -legacy improves compatibility with some tooling:
  42. openssl pkcs12 -export -legacy \
  43. -inkey developer_id_app.key \
  44. -in developerID_application.pem \
  45. -certfile chain.pem \
  46. -out Certificates.p12
  47. ```
  48. Confirm the `.p12` has three certificates before base64-encoding:
  49. ```sh
  50. openssl pkcs12 -in Certificates.p12 -nodes -passin pass:"$MACOS_SIGN_PASSWORD" 2>/dev/null \
  51. | grep -c "BEGIN CERTIFICATE"
  52. # expect: 3
  53. ```
  54. If you already have a Mac with the certificate in Keychain Access, you can export a `.p12` from there instead — include the full chain when exporting.
  55. #### 2. Create the notarization API key
  56. 1. Open [App Store Connect → Users and Access → Integrations → App Store Connect API](https://appstoreconnect.apple.com/access/integrations/api).
  57. 2. Create a key with **Developer** role (or Admin).
  58. 3. Download the `.p8` file once (it cannot be downloaded again). Note the **Key ID** shown in the portal and the **Issuer ID** at the top of the API keys page.
  59. #### 3. Base64-encode the key files
  60. Run on a machine that has the files (Linux or macOS):
  61. ```sh
  62. base64 -w0 < ./Certificates.p12 # MACOS_SIGN_P12
  63. base64 -w0 < ./AuthKey_XXXXXX.p8 # MACOS_NOTARY_KEY
  64. ```
  65. On macOS without GNU coreutils, use `base64 -i file | tr -d '\n'`.
  66. #### 4. Add GitHub repository secrets
  67. In **Settings → Secrets and variables → Actions**, create:
  68. | Secret | Value |
  69. |--------|-------|
  70. | `MACOS_SIGN_P12` | Base64 contents of the `.p12` file |
  71. | `MACOS_SIGN_PASSWORD` | Password used when exporting the `.p12` |
  72. | `MACOS_NOTARY_KEY` | Base64 contents of the `.p8` file |
  73. | `MACOS_NOTARY_KEY_ID` | Key ID from App Store Connect (e.g. `ABC123DEF4`) |
  74. | `MACOS_NOTARY_ISSUER_ID` | Issuer UUID from App Store Connect |
  75. All five must be present; `sign-macos` fails (without affecting the published release) if any are missing.
  76. ### Renewal
  77. | Item | Typical lifetime | What to do |
  78. |------|------------------|------------|
  79. | Developer ID Application certificate | ~5 years | Create a new certificate in the Apple portal, export a new **full-chain** `.p12` (leaf + G2 intermediate + Apple Root CA), update `MACOS_SIGN_P12` and `MACOS_SIGN_PASSWORD`. |
  80. | App Store Connect API key | Does not expire, but can be revoked | Create a new key if compromised or lost; update `MACOS_NOTARY_KEY`, `MACOS_NOTARY_KEY_ID`, and optionally `MACOS_NOTARY_ISSUER_ID`. |
  81. | Apple Developer Program | Annual subscription | Renew membership before it lapses; existing certificates stop working if the account is inactive. |
  82. | Apple Developer agreements | Re-issued by Apple from time to time | When Apple publishes an updated Program License Agreement, the Account Holder must accept it at https://developer.apple.com/account. Until then notarization fails with `403 FORBIDDEN.REQUIRED_AGREEMENTS_MISSING_OR_EXPIRED`. |
  83. After updating secrets, the next release on `main` (via semantic-release) will use the new credentials automatically.
  84. ### Verifying a signed release
  85. From any platform (no Mac required), check that quill did **not** emit the broken `certificate root[...]` designated requirement:
  86. ```sh
  87. go install github.com/anchore/quill/cmd/quill@v0.7.1
  88. quill describe OliveTin-darwin-arm64/OliveTin
  89. ```
  90. The requirements line must contain `certificate 1[field.1.2.840.113635.100.6.2.6]`. If it says `certificate root[field.1.2.840.113635.100.6.2.6]`, the `.p12` is missing Apple Root CA — rebuild it and update `MACOS_SIGN_P12`.
  91. On a Mac, also run:
  92. ```sh
  93. tar -xzf OliveTin-darwin-arm64.tar.gz
  94. codesign --verify --strict -vvvv OliveTin-darwin-arm64/OliveTin
  95. spctl -a -vv -t execute OliveTin-darwin-arm64/OliveTin
  96. ```
  97. `codesign` should report both `valid on disk` and `satisfies its Designated Requirement`. `spctl` should report `accepted` with `source=Notarized Developer ID`.
  98. ### Configuration reference
  99. - GoReleaser: the `darwin` build and archive in link:https://github.com/OliveTin/OliveTin/blob/main/.goreleaser.yml[`.goreleaser.yml`]
  100. - CI job and secrets: link:https://github.com/OliveTin/OliveTin/blob/main/.github/workflows/build-and-release.yml[`.github/workflows/build-and-release.yml`] (`sign-macos` job)
  101. - Sign, notarize and upload: link:https://github.com/OliveTin/OliveTin/blob/main/var/macos/sign-and-publish.sh[`var/macos/sign-and-publish.sh`]
  102. - CI preflight (3-cert P12): link:https://github.com/OliveTin/OliveTin/blob/main/var/macos/verify-macos-sign-p12.sh[`var/macos/verify-macos-sign-p12.sh`]
  103. - CI post-sign check (designated requirement): link:https://github.com/OliveTin/OliveTin/blob/main/var/macos/verify-signed-darwin.sh[`var/macos/verify-signed-darwin.sh`]
  104. ## Windows release signing (SignPath)
  105. Windows Authenticode signing uses [SignPath Foundation](https://signpath.org/) (free for qualifying open-source projects). It does **not** use GoReleaser Pro.
  106. GoReleaser publishes a GitHub release **without** Windows zip/MSI assets. A separate `sign-windows` job submits the unsigned Windows files (as workflow artifacts) to SignPath, then uploads the signed zip/MSI and updates `checksums.txt` on the already-published release.
  107. Signed artifacts:
  108. * `OliveTin.exe` inside `OliveTin-windows-amd64.zip`
  109. * nested `OliveTin.exe` and the `OliveTin-windows-amd64.msi` installer (deep signing)
  110. If SignPath secrets/vars are missing or signing fails, the release still publishes; Windows assets are simply missing until a successful `sign-windows` run. Install URLs for the Windows zip may 404 until signing finishes.
  111. ### Prerequisites
  112. - Approval for the [SignPath Foundation open-source program](https://signpath.io/product/open-source).
  113. - The SignPath GitHub App installed on the OliveTin organization/repository.
  114. - A SignPath project linked to this repository, with a release signing policy.
  115. ### One-time setup
  116. #### 1. Apply for SignPath Foundation
  117. 1. Open https://signpath.io/product/open-source and apply with the OliveTin GitHub repository URL.
  118. 2. After approval, create (or confirm) the organization and project in the SignPath portal.
  119. #### 2. Install the SignPath GitHub App
  120. 1. Install the SignPath GitHub App and grant access to the OliveTin repository.
  121. 2. Link the Trusted Build System **GitHub.com** to the SignPath project (required so SignPath can verify the workflow artifact origin).
  122. #### 3. Create artifact configurations
  123. In the SignPath project, create two artifact configurations with these slugs (must match CI). Paste the XML from the reference copies in this repo (SignPath does **not** load them automatically):
  124. * slug `windows-zip` ← link:https://github.com/OliveTin/OliveTin/blob/main/docs/modules/dev/signpath/windows-zip.xml[`signpath/windows-zip.xml`]
  125. * slug `windows-msi` ← link:https://github.com/OliveTin/OliveTin/blob/main/docs/modules/dev/signpath/windows-msi.xml[`signpath/windows-msi.xml`]
  126. Use **Custom** XML in the SignPath UI and paste the file contents. Do **not** use **Upload an artifact sample** on these `.xml` files — SignPath will treat them as XML documents to sign (`xml-file`), which is unavailable on the Foundation/Open Source plan. See link:https://github.com/OliveTin/OliveTin/blob/main/docs/modules/dev/signpath/README.md[`signpath/README.md`].
  127. #### 4. Add GitHub secrets and variables
  128. In **Settings → Secrets and variables → Actions**:
  129. | Kind | Name | Value |
  130. |------|------|-------|
  131. | Secret | `SIGNPATH_API_TOKEN` | CI submitter API token from SignPath |
  132. | Variable | `SIGNPATH_ORGANIZATION_ID` | SignPath organization ID |
  133. | Variable | `SIGNPATH_PROJECT_SLUG` | SignPath project slug (e.g. `olivetin`) |
  134. | Variable | `SIGNPATH_SIGNING_POLICY_SLUG` | Signing policy slug (e.g. `release-signing`) |
  135. #### 5. Pipeline behaviour
  136. On a new semantic-release from `main`:
  137. 1. GoReleaser publishes container images and a GitHub release **without** Windows zip/MSI assets (those are built locally for SignPath only).
  138. 2. The build job uploads the unsigned Windows files as GitHub Actions artifacts.
  139. 3. The `sign-windows` job submits each artifact to SignPath, waits for completion, then runs `var/windows/signpath-publish-signed.sh` to upload the signed files and refresh `checksums.txt`.
  140. All jobs in this chain use GitHub-hosted runners (required by SignPath for OSS projects).
  141. ### Verifying a signed release
  142. On Windows, download `OliveTin-windows-amd64.msi` or extract `OliveTin.exe` from the zip, then either:
  143. * Right-click → **Properties** → **Digital Signatures**, or
  144. * Run:
  145. ```bat
  146. signtool verify /pa OliveTin.exe
  147. signtool verify /pa OliveTin-windows-amd64.msi
  148. ```
  149. ### Configuration reference
  150. - Release publish (no Windows assets initially): `release.draft: false` and `release.ids` in link:https://github.com/OliveTin/OliveTin/blob/main/.goreleaser.yml[`.goreleaser.yml`]
  151. - CI job: `sign-windows` in link:https://github.com/OliveTin/OliveTin/blob/main/.github/workflows/build-and-release.yml[`.github/workflows/build-and-release.yml`]
  152. - Publish helper: link:https://github.com/OliveTin/OliveTin/blob/main/var/windows/signpath-publish-signed.sh[`var/windows/signpath-publish-signed.sh`]
  153. - SignPath artifact configs (reference only): link:https://github.com/OliveTin/OliveTin/blob/main/docs/modules/dev/signpath/windows-zip.xml[`signpath/windows-zip.xml`], link:https://github.com/OliveTin/OliveTin/blob/main/docs/modules/dev/signpath/windows-msi.xml[`signpath/windows-msi.xml`]
  154. - link:https://docs.signpath.io/trusted-build-systems/github[SignPath GitHub Actions docs]
  155. - link:https://docs.signpath.io/artifact-configuration/examples[SignPath artifact configuration examples]