TExcelTAD

Code Signing & Provisioning

Android signing needs one thing: a key. Apple signing needs three that must agree with each other, and most failed iOS builds on CI are one of them disagreeing. This lesson is an overview of the moving parts and of how CI machines get them.

Note: non-run (macOS only). The concepts and commands follow Apple's developer documentation and man codesign / man security.

The pieces

Piece What it is Where it lives
Signing certificate + private key your team's identity: Apple Development (for running on devices) or Apple Distribution (for App Store, TestFlight, ad hoc) a .p12 file / the macOS keychain
App ID the bundle identifier registered for your team (com.example.hello), with its capabilities (push, iCloud, Sign in with Apple…) the developer portal
Provisioning profile a signed document from Apple that says this certificate may sign this App ID with these entitlements for this distribution method (and, for development/ad hoc, these devices) a .mobileprovision file
Entitlements the capabilities the binary claims (aps-environment, app groups, keychain groups) an .entitlements file in the project

A signed app is only accepted if all four agree: the binary's bundle ID matches the profile's App ID, the signing certificate is in the profile, the entitlements are a subset of what the profile allows, and (for development/ad hoc) the device is listed.

Profile type Certificate Installs on
Development Apple Development registered devices, from Xcode
Ad hoc (release-testing) Apple Distribution up to 100 registered devices per device type per year
App Store (app-store-connect) Apple Distribution TestFlight and the App Store, after upload
Enterprise (enterprise) Enterprise distribution any device of your organisation (Enterprise Program only)

Every extension (widgets, notification service, share extension) is a separate bundle ID with its own profile.

Automatic vs manual signing

Automatic (CODE_SIGN_STYLE = Automatic) Manual (CODE_SIGN_STYLE = Manual)
Who creates certificates and profiles Xcode, using the signed-in account or an App Store Connect API key you, or a tool such as Fastlane match
Build settings DEVELOPMENT_TEAM DEVELOPMENT_TEAM, CODE_SIGN_IDENTITY, PROVISIONING_PROFILE_SPECIFIER per target and configuration
On CI works with -allowProvisioningUpdates and an API key (-authenticationKeyPath/-ID/-IssuerID) deterministic; no portal changes during builds

Small teams often use automatic signing everywhere. Larger teams usually go manual for release builds, with certificates and profiles stored encrypted in one place and installed on CI: that's exactly what Fastlane match automates.

Setting up a CI machine by hand

A fresh macOS runner has no certificates. The usual sequence creates a temporary keychain, imports the .p12, allows codesign to use it without a password prompt, and installs the profile:

bash
KEYCHAIN="$RUNNER_TEMP/build.keychain-db"
KEYCHAIN_PW="$(uuidgen)"                                  # throwaway password for a throwaway keychain

security create-keychain -p "$KEYCHAIN_PW" "$KEYCHAIN"
security set-keychain-settings -lut 21600 "$KEYCHAIN"     # lock after 6 h instead of 5 min
security unlock-keychain -p "$KEYCHAIN_PW" "$KEYCHAIN"

echo "$DIST_CERT_P12_B64" | base64 --decode > "$RUNNER_TEMP/dist.p12"
security import "$RUNNER_TEMP/dist.p12" -k "$KEYCHAIN" -P "$DIST_CERT_PASSWORD" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PW" "$KEYCHAIN"
security list-keychains -d user -s "$KEYCHAIN" $(security list-keychains -d user | tr -d '"')

echo "$PROFILE_B64" | base64 --decode > "$RUNNER_TEMP/hello.mobileprovision"
security cms -D -i "$RUNNER_TEMP/hello.mobileprovision" > profile.plist   # decode to read Name/UUID/expiry
# copy it into the folder Xcode reads provisioning profiles from (named after its UUID)

security find-identity -v -p codesigning "$KEYCHAIN"       # should list "Apple Distribution: …"

set-key-partition-list is the step people forget: without it, codesign blocks waiting for a keychain password dialog that nobody will ever click, and the job times out. At the end of the job, security delete-keychain "$KEYCHAIN". GitHub-hosted runners are discarded after each job, but self-hosted Macs are not.

Inspecting signatures

bash
codesign --verify --deep --strict --verbose=2 Hello.app        # is the signature valid?
codesign -d --entitlements :- Hello.app                         # which entitlements were signed in?
codesign -dvv Hello.app 2>&1 | grep -E 'Identifier|Authority|TeamIdentifier'
security cms -D -i Hello.app/embedded.mobileprovision | plutil -p - | grep -E 'Name|ExpirationDate|application-identifier'

These answer the usual export errors: "No profiles for 'com.example.hello.widget' were found" (an extension's profile is missing), "Provisioning profile doesn't include the aps-environment entitlement" (capability enabled in Xcode but not in the profile; regenerate it), and "doesn't include signing certificate" (the profile was made for another certificate).

A runnable model of the agreement check

The four-way agreement as code, the same checks Xcode performs before it signs:

python · try it yourself
from fnmatch import fnmatch

profile = {
    "name": "Hello App Store",
    "app_id": "ABCDE12345.com.example.hello",
    "certificates": {"Apple Distribution: Example Ltd (ABCDE12345)"},
    "entitlements": {"aps-environment": "production", "com.apple.security.application-groups": ["group.com.example.hello"]},
    "expires": "2027-03-01",
}

def check(bundle_id, team, certificate, entitlements, build_date):
    problems = []
    if not fnmatch(f"{team}.{bundle_id}", profile["app_id"]):
        problems.append(f"profile {profile['name']!r} is for {profile['app_id']}, not {team}.{bundle_id}")
    if certificate not in profile["certificates"]:
        problems.append(f"profile doesn't include signing certificate {certificate!r}")
    for key in sorted(entitlements):
        if key not in profile["entitlements"]:
            problems.append(f"profile doesn't include the {key} entitlement")
    if build_date > profile["expires"]:
        problems.append(f"profile expired on {profile['expires']}")
    return problems or ["OK"]

dist = "Apple Distribution: Example Ltd (ABCDE12345)"
print("app:   ", check("com.example.hello", "ABCDE12345", dist, {"aps-environment"}, "2026-10-24"))
print("widget:", check("com.example.hello.widget", "ABCDE12345", dist, set(), "2026-10-24"))
print("icloud:", check("com.example.hello", "ABCDE12345", dist, {"com.apple.developer.icloud-services"}, "2026-10-24"))
print("dev:   ", check("com.example.hello", "ABCDE12345", "Apple Development: Ada (XYZ)", set(), "2027-04-01"))
app:    ['OK']
widget: ["profile 'Hello App Store' is for ABCDE12345.com.example.hello, not ABCDE12345.com.example.hello.widget"]
icloud: ["profile doesn't include the com.apple.developer.icloud-services entitlement"]
dev:    ["profile doesn't include signing certificate 'Apple Development: Ada (XYZ)'", 'profile expired on 2027-03-01']

(Wildcard App IDs such as ABCDE12345.com.example.* match several bundle IDs, which is why the model uses fnmatch; they can't carry most capabilities, so release profiles use explicit IDs.)

Test yourself

A CI job hangs at the codesign step until it times out. Most likely cause?

  1. The provisioning profile expired
  2. The private key's partition list wasn't set, so codesign waits for a keychain access prompt
  3. Xcode is too old
  4. The scheme isn't shared

Which object says that a given certificate may sign a given App ID with given entitlements?

  1. The .p12 file
  2. The provisioning profile
  3. ExportOptions.plist
  4. The Info.plist

Export fails with "No profiles for 'com.example.hello.widget' were found". What's missing?

  1. A new certificate
  2. A provisioning profile for the widget extension's own bundle ID
  3. A Package.resolved
  4. A new scheme