为 fastlane 安全存储 App Store Connect API 密钥?

Storing App Store Connect API key securely for fastlane?

我有一个 GitHub 操作运行 fastlane 来构建版本并将其部署到 CI 管道中的 TestFlight。我使用 App Store Connect API 密钥以非交互方式进行身份验证。

Apple's docs 明确地说:

Important

Keep your API keys secure and private. You should never share your keys, store keys in a code repository, or include keys in client-side code.

但我看到的每个示例都只是将 .p8 文件作为检入源代码管理的纯文本文件传递给 app_store_connect_api_key() 命令(通过 key_filepath 参数):

lane :release do
  app_store_connect_api_key(
    key_id: "D383SF739",
    issuer_id: "6053b7fe-68a8-4acb-89be-165aa6465141",
    key_filepath: "./AuthKey_D383SF739.p8"
  )

  pilot
end

或作为明文密钥本身(通过 key 参数):

lane :release do
  app_store_connect_api_key(
    key_id: "D383SF739",
    issuer_id: "6053b7fe-68a8-4acb-89be-165aa6465141",
    "key": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHknlhdlYdLu\n-----END PRIVATE KEY-----"
  )

  pilot
end

是否有更安全的方式来存储它并仍然在 CI 管道中使用它?

您可以将要保密的值存储为环境变量。据我所知,所有 CI/CD 服务都允许设置环境变量。您可以使用 ENV['XYZ'] 访问 Fastfile 中的任何环境变量。

查看更多信息:https://docs.fastlane.tools/best-practices/continuous-integration/github/