Guide · fastlane

Use an App Store Connect key with fastlane

fastlane wants the path of a .p8 file. That file ends up in the repo folder, a Downloads folder or a backup, and it can sign in as your team.

In shortSave the .p8 as a key item, then run lk run --file ASC_KEY_PATH=shop/production/ASC_P8 -- fastlane beta. The command gets the path of a temporary file only you can read, and Latchkey deletes it when the command exits.

Why the .p8 file lingers

The App Store Connect key is a .p8 file, and fastlane reads it from a path. So the file gets saved somewhere and stays there: in the project, in a shared folder, in a backup, sometimes in Git. Anyone who can read it can use the key. Replacing it means finding every copy.

The tool needs a file, not a value in the environment. Latchkey stores the key as an item in iCloud Keychain and writes a file only for the length of the command. Your project folder never holds it, and neither does a backup of that folder.

Set it up

  1. Save the key as a key item

    Use the key kind, the one meant for SSH, GPG, .p8 and .pem files. The value is read from standard input. The file name below is an example.

    Terminal
    lk set shop/production/ASC_P8 --kind key < ~/Downloads/AuthKey_EXAMPLE.p8

    Saving asks for approval. Once the item is stored, delete the downloaded file. Key items are masked in command output, line by line, and only exact copies are hidden.

  2. Run fastlane with --file

    NAME=ID sets the variable NAME to the path of a temporary file holding the item's value. Use the name your lane reads for the key's path.

    Terminal
    lk run --file ASC_KEY_PATH=shop/production/ASC_P8 -- fastlane beta

    The file is readable only by you. Latchkey deletes it when the command exits. Temporary files for different item IDs get different paths, even if the final names match.

  3. Keep the setting in the project

    If you run the lane the same way every time, put it in an env file. NAME=latchkey-file://ID does the same as --file, and the file contains no value.

    .env.local
    ASC_KEY_PATH=latchkey-file://shop/production/ASC_P8
    Terminal
    lk run --env-file .env.local -- fastlane beta
  4. Check before a slow run

    lk check accepts the same options. It shows whether the item would be released without asking, would ask you, or is missing, and it releases nothing.

    Terminal
    lk check --file ASC_KEY_PATH=shop/production/ASC_P8

With an agent

The key item asks for approval each time unless it is agent-safe or a grant covers it. Keep a production signing key out of agent-safe and grant it narrowly if you let an agent run releases. The MCP tool latchkey_run can deliver key files too. See Give coding agents API keys safely.

What this doesn't do

The key files section and the security page have more.

Related