【问题标题】:How to sign and notarize a PKG within a Github Actions macos runner如何在 Github Actions macos runner 中签署和公证 PKG
【发布时间】:2022-04-20 19:37:12
【问题描述】:

上下文

我正在构建一个 Github Actions 作业以构建、签署和公证 PKG 文件。

我正在使用 Apple Id 帐户(工作流程需要用户名和密码)以及带有私钥(加密)的 Developer Id Installer 证书。两者都保存为机密 (base64),并将在工作流中转换为 .p12 文件,然后添加到钥匙串中。

此作业是私有存储库中更大工作流的一部分,它首先从软件生成文件(使用 Pyinstaller),然后将 PKG 导出到 AWS S3 存储桶上。

实现

jobs:
  [...]

  pkg:
    needs: [...]
    runs-on: macos-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Download macos bin file
        uses: actions/download-artifact@v2
        with:
          name: macos-bin-files
          path: dist/
      - name:
        run: | 
          ----- Create certificate files from secrets base64 -----
          echo ${{ secrets.DEVELOPER_ID_INSTALLER_CER }} | base64 --decode > certificate_installer.cer
          echo ${{ secrets.DEVELOPER_ID_INSTALLER_KEY }} | base64 --decode > certificate_installer.key

          ----- Create p12 file -----
          openssl pkcs12 -export -name zup -in certificate_installer.cer -inkey certificate_installer.key -passin pass:${{ secrets.KEY_PASSWORD }} -out certificate_installer.p12 -passout pass:${{ secrets.P12_PASSWORD }}

          ----- Configure Keychain -----
          KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
          security create-keychain -p "${{ secrets.KEYCHAIN_PASSWORD }}" $KEYCHAIN_PATH
          security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
          security unlock-keychain -p "${{ secrets.KEYCHAIN_PASSWORD }}" $KEYCHAIN_PATH

          ----- Import certificates on Keychain -----
          security import certificate_installer.p12 -P "${{ secrets.P12_PASSWORD }}" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
          security list-keychain -d user -s $KEYCHAIN_PATH

          ----- Generate PKG from files -----
          use a macos installer script (ref: https://github.com/KosalaHerath/macos-installer-builder/tree/master/macOS-x64)

          ----- Sign PKG file -----
          productsign --sign "${{ secrets.DEVELOPER_ID_INSTALLER_NAME }}" $INPUT_FILE_PATH $OUTPUT_FILE_PATH

          - name: "Notarize Release Build PKG"
            uses: devbotsxyz/xcode-notarize@v1 
            with:
              product-path: $PATH_TO_PKG
              appstore-connect-username: ${{ secrets.APPLE_ACCOUNT_USERNAME }}
              appstore-connect-password: ${{ secrets.APPLE_ACCOUNT_PASSWORD }}
              primary-bundle-id: 'BUNDLE_ID'

          - name: "Staple Release Build"
            uses: devbotsxyz/xcode-staple@v1
            with:
              product-path: $PATH_TO_PKG

  [...]

问题

我关注了installing an Apple certificate on macOS runners 的 Github Action 官方文档,这部分工作正常。我可以将证书添加到钥匙串并使用它通过productsign 命令对PKG 文件进行签名。

但是,当我将 PKG 发送给 Apple 进行公证时,它会返回该错误:

Error: Notarization status <invalid> - Package Invalid
Error: Notarization failed

我尝试了什么

PKG 在分发时按预期工作(只需要以管理员身份打开,未经过公证),因此问题似乎与包实现无关。

我尝试使用命令行执行公证,以下链接来自不同来源:

但是,即使使用这些命令行(不使用 notarize 操作),我也无法对 PKG 文件进行公证。

问题

我的工作流程出了什么问题,我在尝试对包裹进行公证之前是否遗漏了什么?

PS:我在 Github Actions macos 运行器上找不到任何参考...

【问题讨论】:

    标签: macos certificate github-actions sign notarize


    【解决方案1】:

    解决方案

    在设置devbotsxyz/xcode-notarize@v1 字段verbose:true 后,我观察到Apple 返回了一个指向JSON 的链接,解释了为什么包对于公证无效。

    在这个 JSON 中,它被告知构成我的 PKG 的所有文件(有很多文件,因为在我的上下文中我无法将 --onefile 与 Pyinstaller 一起使用)是无效的因为它们没有签名和时间戳。

    经过一番研究,我找到了this post on the Apple Developer Forum 并了解到PKG 文件需要进行INSIDE OUT 签名:首先,您对Pyinstaller 生成的每个文件进行签名,然后对收集所有这些文件的PKG 进行签名。

    为此,您不能使用 productsign 命令(因为它仅适用于 .pkg、.zip 和 .dmg),而是使用 codesign

    但是,codesign 不使用 Developer Id Installer certificate,而是使用 Developer Id Application certificate,因此我还必须将此新证书添加到工作流中。

    请注意,由于我的 PKG 将由数百个文件组成,因此我还需要 a bash script to use codesign to sign each one of them

    我的最终工作流程如下所示:

    jobs:
      [...]
    
      pkg:
        needs: [...]
        runs-on: macos-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v2
    
          - name: Download macos bin file
            uses: actions/download-artifact@v2
            with:
              name: macos-bin-files
              path: dist/
          - name:
            run: | 
              ----- Create certificate files from secrets base64 -----
              echo ${{ secrets.DEVELOPER_ID_INSTALLER_CER }} | base64 --decode > certificate_installer.cer
              echo ${{ secrets.DEVELOPER_ID_INSTALLER_KEY }} | base64 --decode > certificate_installer.key
              echo ${{ secrets.DEVELOPER_ID_APPLICATION_CER }} | base64 --decode > certificate_application.cer
              echo ${{ secrets.DEVELOPER_ID_APPLICATION_KEY }} | base64 --decode > certificate_application.key
    
              ----- Create p12 file -----
              openssl pkcs12 -export -name zup -in certificate_installer.cer -inkey certificate_installer.key -passin pass:${{ secrets.KEY_PASSWORD }} -out certificate_installer.p12 -passout pass:${{ secrets.P12_PASSWORD }}
              openssl pkcs12 -export -name zup -in certificate_application.cer -inkey certificate_application.key -passin pass:${{ secrets.KEY_PASSWORD }} -out certificate_application.p12 -passout pass:${{ secrets.P12_PASSWORD }}
    
              ----- Configure Keychain -----
              KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
              security create-keychain -p "${{ secrets.KEYCHAIN_PASSWORD }}" $KEYCHAIN_PATH
              security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
              security unlock-keychain -p "${{ secrets.KEYCHAIN_PASSWORD }}" $KEYCHAIN_PATH
    
              ----- Import certificates on Keychain -----
              security import certificate_installer.p12 -P "${{ secrets.P12_PASSWORD }}" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
              security import certificate_application.p12 -P "${{ secrets.P12_PASSWORD }}" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
              security list-keychain -d user -s $KEYCHAIN_PATH
    
              ----- Codesign files with script -----
              use a script to sign each file from the artifact (ref: https://gist.github.com/GuillaumeFalourd/4efc73f1a6014b791c0ef223a023520a)
    
              ----- Generate PKG from codesigned files -----
              use a macos installer script (ref: https://github.com/KosalaHerath/macos-installer-builder/tree/master/macOS-x64)
    
              ----- Sign PKG file -----
              productsign --sign "${{ secrets.DEVELOPER_ID_INSTALLER_NAME }}" $INPUT_FILE_PATH $OUTPUT_FILE_PATH
    
              - name: "Notarize Release Build PKG"
                uses: devbotsxyz/xcode-notarize@v1 
                with:
                  product-path: $PATH_TO_PKG
                  appstore-connect-username: ${{ secrets.APPLE_ACCOUNT_USERNAME }}
                  appstore-connect-password: ${{ secrets.APPLE_ACCOUNT_PASSWORD }}
                  primary-bundle-id: 'BUNDLE_ID'
    
              - name: "Staple Release Build"
                uses: devbotsxyz/xcode-staple@v1
                with:
                  product-path: $PATH_TO_PKG
    
      [...]
    

    【讨论】:

      猜你喜欢
      • 2021-10-04
      • 2023-02-14
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 2020-01-14
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多