Home/Guides/How to upload iOS builds with an App Store Connect API key, with no 2FA prompts

How to upload iOS builds with an App Store Connect API key, with no 2FA prompts

Updated · airankrush

What this guide covers

When you finish, one command validates an ipa and uploads it to App Store Connect, with no account password or verification code at any point. You need: the Admin role in App Store Connect and an exported ipa.

Steps

  1. Generate the key on your own computer

    Following Apple's API keys documentation: sign in to App Store Connect, open the Integrations tab under Users and Access, choose App Store Connect API in the left column, click generate under Team Keys, enter a name and choose a role. Generating a team key requires an Admin account.

    Do this step in the browser on your own computer; there is no need to sign in to App Store Connect on the remote Mac. Give the key the lowest role that is enough for its purpose.

  2. The private key file can be downloaded only once

    Apple's documentation states that the private key can be downloaded only once and Apple keeps no copy. The download is a .p8 file; also note the Key ID and Issuer ID shown on the page.

    Store the .p8 in your own password manager or private storage first, and only then put a copy on the remote Mac. That way a reclaimed machine does not stop you from using the key.

  3. Put the key where altool looks for it

    The altool help explains that with --api-key, it searches ./private_keys, ~/private_keys, ~/.private_keys and ~/.appstoreconnect/private_keys, in that order, for a file named AuthKey_<Key ID>.p8. Create the directory on the remote Mac and tighten its permissions:

    mkdir -p ~/.appstoreconnect/private_keys
    chmod 700 ~/.appstoreconnect/private_keys

    Put the .p8 in it and keep the file name as downloaded.

  4. Validate first, then upload

    Apple's upload builds guide describes calling altool through xcrun to validate and upload. With an API key it looks like this:

    xcrun altool --validate-app -f App.ipa -t ios --api-key <Key ID> --api-issuer <Issuer ID>
    xcrun altool --upload-app -f App.ipa -t ios --api-key <Key ID> --api-issuer <Issuer ID>

    The options have changed between Xcode versions, so go by the output of xcrun altool --help on your machine. After a successful upload, the build has to be processed by Apple before it appears in TestFlight.

  5. Using it in fastlane

    According to the fastlane API key documentation, call app_store_connect_api_key in a lane with key_id, issuer_id and key_filepath, and later actions such as pilot use it automatically. You can also write those three items into a JSON file and pass it with --api_key_path.

    The supported tools listed in the documentation include pilot, deliver, sigh, cert and match. It also warns that individual keys cannot access the provisioning profile endpoints, so use a team key on build machines.

  6. Have xcodebuild use the same key

    The three xcodebuild options -authenticationKeyPath, -authenticationKeyID and -authenticationKeyIssuerID, together with -allowProvisioningUpdates, provide the portal access automatic signing needs on a machine with no signed-in account. As a result the whole build machine does not need any Apple Account signed in to Xcode.

  7. One key per machine, revoked when the rental ends

    Generate a separate key for each rented machine and state its purpose in the name. Before the rental ends, delete the .p8 from the machine, then revoke the key in App Store Connect. Apple's documentation also requires revoking immediately if you suspect a leak.

    Do not commit the key to a code repository, and do not paste it into a ticket or a chat. On a CI platform, keep it in a secret variable and have the job write it to a temporary file at run time.

FAQ

With an API key, do I still need to sign in to an account in Xcode?

Command-line archiving, signing and uploading can all run on the key alone. You only need an account signed in to Xcode if you want to upload from the Organizer in the graphical interface.

I am just a team member, not an Admin. What can I do?

Ask an Admin to generate a team key and pass it to you over a secure channel. Apple's documentation also describes individual keys, for which an Admin grants permission to generate, but their scope is narrower.

I lost the .p8 file. Can I download it again?

No. Revoke the old key, generate a new one, and update the configuration everywhere it is used.

The upload succeeded but the build is not showing in TestFlight. Why?

The build has to be processed by Apple, and the result is sent to the account's email address. For why processing failed, go by the email and what the App Store Connect page shows; it has nothing to do with which Mac did the upload.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All guides