Code signing in CI without the pain: temporary keychains, profiles and API keys
A headless build cannot answer a keychain prompt. This guide covers what Apple code signing needs in CI: identities, a per-job keychain, profiles and the Xcode 16 folder change, manual versus automatic signing, API keys and common errors.

On a developer's laptop a person is usually present: the keychain is unlocked at login and permission dialogs can be answered. A CI job has nobody to click anything, so signing has to work without one.
The pieces: certificate, private key, profile
Apple's TN3161 defines a code-signing identity as a certificate plus the private key that matches its public key; the certificate alone cannot sign. When you or Xcode request a certificate, that key is generated on the Mac and kept in its login keychain. For CI you export the identity as a password-protected PKCS#12 file, usually .p12.
A provisioning profile, as TN3125 describes it, ties together who may sign (its certificates), which app (an App ID), where it runs (most profiles list devices), when it expires and which entitlements are allowed. It ships inside the app as embedded.mobileprovision, or Contents/embedded.provisionprofile on macOS. When signing fails, check these pieces against each other.
Why the login keychain is a trap
The login keychain is tied to an interactive login and may prompt for access, which a headless job cannot answer. Apple Developer Technical Support's post on errSecInternalComponent says this codesign error typically affects signing over SSH or on CI servers, and that logging in via SSH does not unlock the keychain. A keychain that the job creates, unlocks and configures itself avoids those prompts and, once deleted, leaves no secrets behind.
The steps follow GitHub's guide for macOS runners; option notes come from Apple's security man page source.
Creating and unlocking a temporary keychain
KEYCHAIN_PATH="$RUNNER_TEMP/app-signing.keychain-db"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security import "$CERTIFICATE_PATH" -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k "$KEYCHAIN_PATH"
security set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security list-keychain -d user -s "$KEYCHAIN_PATH"
What each step does:
create-keychainandunlock-keychaintake a password; GitHub suggests any newly generated random string.set-keychain-settings -lut 21600locks the keychain on sleep or after a six-hour timeout, so it stays open through long builds.importloads the.p12. The man page says-Alets any application access the key without warning, calling it "insecure, not recommended!"; the narrower-Tnames specific applications, as in the DTS post's-T /usr/bin/codesign.set-key-partition-listsets an access rule based on the calling tool's code signature; the man page saysapple:must be listed for/usr/bin/codesignto use the key.list-keychain -d user -ssets the user search list to the new keychain rather than adding to it; on machines you keep, restore the old list afterwards.
Keep the .p12 and its password in your CI secret store, never in the repository. GitHub-hosted runners are destroyed after each job; on a self-hosted runner, delete the keychain even after a failure, as GitHub's cleanup step does with if: ${{ always() }}.
security delete-keychain "$KEYCHAIN_PATH"
Where provisioning profiles go
GitHub's example copies the profile into the folder used by Xcode versions before 16:
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp build_pp.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles
In an accepted answer on the Apple Developer Forums, an Apple DTS engineer gives ~/Library/Developer/Xcode/UserData/Provisioning Profiles for Xcode 16 and later, so check which folder your Xcode reads and adjust the copy and cleanup steps. Use .mobileprovision for iOS and .provisionprofile for macOS targets, as GitHub notes, and remove profiles after the job on machines you keep.
Manual or automatic signing in xcodebuild
Manual signing
You pick the certificate and profile in the project's signing settings, and the job installs them. Explicit inputs make failures easier to trace, which suits CI well.
Automatic signing with an App Store Connect API key
Automatic signing needs xcodebuild to talk to the Apple Developer website, which -allowProvisioningUpdates permits, as Apple's WWDC21 session Distribute apps in Xcode with cloud signing explains. Signing in to Xcode on the machine also works, but that session persists only for a period of time. Since Xcode 13, according to its release notes, xcodebuild can instead authenticate with an App Store Connect API key, enabling automatic signing on build machines and in CI.
Create a team key in App Store Connect under Users and Access, Integrations, and note the key ID and issuer ID. Apple's documentation says the private key can be downloaded a single time and Apple doesn't keep a copy, and that individual keys cannot use the API's Provisioning endpoints. Pass the values like this:
xcodebuild ... -allowProvisioningUpdates \
-authenticationKeyPath "$API_KEY_PATH" \
-authenticationKeyID "$API_KEY_ID" \
-authenticationKeyIssuerID "$API_ISSUER_ID"
Here ... stands for your build or export arguments. Confirm the options with xcodebuild -help or man xcodebuild on your Xcode version, and test before relying on them. Apple advises against storing keys in a code repository, so write the key to a temporary path and delete it after the job.
Common errors and what to check
This table reflects common, unverified community experience, not an official Apple mapping, and message text varies between Xcode versions.
| Symptom | What to check |
|---|---|
codesign reports errSecInternalComponent, or signing stalls | Keychain unlocked and in the search list? Partition list set after the import? See the DTS post above. |
| No signing identity is found | Was the .p12 imported into the searched keychain, and does it contain the private key? |
| The profile lacks a certificate, device or entitlement | Update the profile in your developer account, then reinstall it. |
| No profile is found for the bundle ID | Right folder for your Xcode, right extension, matching App ID? |
| The profile or certificate has expired | Check the expiration dates; both expire. |
A short checklist
- Create and unlock a fresh keychain for each job.
- Import the
.p12, then set the partition list. - Install profiles where your Xcode version looks, with the right extension.
- Use manual signing, or automatic signing with an API key.
- Clean up the keychain, profiles and key file, even after a failure.
Sources
- GitHub Docs: Installing an Apple certificate on macOS runners for Xcode development
- Apple open source (apple-oss-distributions/Security): security(1) man page source
- Apple Developer: TN3161 Inside Code Signing: Certificates
- Apple Developer: TN3125 Inside Code Signing: Provisioning Profiles
- Apple Developer Forums: Resolving errSecInternalComponent errors during code signing (Apple DTS post)
- Apple Developer Forums: Xcode failed to provision target (accepted Apple DTS answer on profile folders)
- Apple Developer: WWDC21 session 10204, Distribute apps in Xcode with cloud signing
- Apple Developer: Xcode 13 Release Notes
- Apple Developer: Creating API Keys for App Store Connect API


