DEV Community

MacBuildCloud
MacBuildCloud

Posted on

Why your CI keeps creating iOS certificates (and how to stop it)

I'm on the MacBuildCloud team. We run Mac build machines, and this is a bug we shipped into our own pipeline and then took back out. Nothing here depends on our product; every fix below works on GitHub Actions, a self-hosted runner, or any CI that throws its Mac away after each job.

The symptom

Open developer.apple.com, go to Certificates, and look for entries named like this:

Apple Development: Created via API

If you see one you don't remember making, and especially if you see several, there is a good chance a CI job made them.

We found ours during our own TestFlight test. The build passed. The .ipa was fine. Then we checked the team's certificate list and there was a new development certificate that nobody had asked for.

Why it happens

Three things combine:

  1. The project uses automatic signing. That's the Xcode default, so most projects do.
  2. The build runs xcodebuild archive with -allowProvisioningUpdates plus an App Store Connect API key. This is the common advice for "signing without a Mac", and it does work.
  3. The build machine is brand new every time. A fresh VM or a hosted runner has an empty keychain.

During archive, automatic signing wants a development identity on the machine. There isn't one, and -allowProvisioningUpdates tells Xcode it may fix that. So it generates a private key in the VM's keychain and asks Apple for a new development certificate to match.

Then the job ends and the VM is deleted, private key and all.

The certificate is still listed in your account, but nothing anywhere can sign with it any more, because the key that goes with it is gone. The next run starts with an empty keychain again and has the same problem.

We stopped after the first one, so I can't show you a screenshot of fifty. But nothing about the next run can reuse a certificate whose private key was destroyed. At best you collect clutter that makes it hard to tell which certificate is real. Apple's documentation doesn't publish a number for how many development certificates a team can hold, so I won't guess one; it isn't a pile you want to find out about.

The CI is also quietly holding a key that can create certificates in your team. Most build jobs don't need that.

Fix 1: don't sign at archive time

This is the change that fixed it for us, and it's small. Archive without signing, then sign once, at export:

xcodebuild \
  -workspace MyApp.xcworkspace -scheme MyApp \
  -destination "generic/platform=iOS" \
  -archivePath build/MyApp.xcarchive \
  CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" \
  archive

xcodebuild -exportArchive \
  -archivePath build/MyApp.xcarchive \
  -exportOptionsPlist ExportOptions.plist \
  -exportPath build/ipa
Enter fullscreen mode Exit fullscreen mode

The export step needs a distribution certificate and an App Store profile, which is the part you were going to need anyway. No development identity is involved, so there is nothing for Xcode to invent.

ExportOptions.plist is a plain text file you can write on any OS:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
  <key>method</key> <string>app-store-connect</string>
  <key>teamID</key> <string>YOURTEAMID</string>
  <key>signingStyle</key> <string>manual</string>
  <key>provisioningProfiles</key>
  <dict>
    <key>com.example.myapp</key><string>MyApp AppStore</string>
  </dict>
</dict>
</plist>
Enter fullscreen mode Exit fullscreen mode

The value under provisioningProfiles is the profile's name as Apple shows it, not the filename. If the app has extensions (a widget, a share extension, a watch app), each bundle ID needs its own entry and its own profile. Ours had a widget, and a missing widget profile is the error that's easiest to misread, because the message names the extension's bundle ID, not the app's.

For Flutter it's the same idea: flutter build ipa --no-codesign (or flutter build ios --no-codesign plus your own archive step), then -exportArchive.

Now you need to get that distribution certificate onto the machine. There are a few honest ways, with different trade-offs.

Option A: a .p12 in your CI secrets

Export your Apple Distribution certificate with its private key as a .p12, store it as a secret, and import it into a throwaway keychain at the start of each job. GitHub's documentation has a complete example; the core of it is:

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
Enter fullscreen mode Exit fullscreen mode

Then copy the .mobileprovision into the profiles directory. On a self-hosted runner that is reused between jobs, delete the keychain and the profile at the end, even when the job fails.

Two things that cost people time:

  • The .p12 has to contain the private key, not just the certificate. In Keychain Access, expand the certificate and select it together with the key underneath before exporting. A .p12 without the key imports without complaint and fails later at codesign.
  • If the build has two profiles that were both downloaded as profile.mobileprovision, one can silently overwrite the other. Give them distinct names.

Good for: small teams, one app, people who want to see exactly what's happening.
Trade-off: you rotate the .p12 by hand when it expires, and anyone who can read CI secrets can sign as your team.

Option B: fastlane match

match keeps your certificates and profiles encrypted in a private git repo (or a Google Cloud or S3 bucket) and installs them on each machine. Its documentation recommends running it in readonly mode on CI, so CI can fetch certificates but never create or revoke them. The setup_ci action creates a temporary keychain and switches match to read-only for you.

I haven't run match in our pipeline, so I'll leave the details to its docs. The point that matters here: readonly on CI is exactly the rule this whole post is about. The machine that gets destroyed is never the one that creates certificates.

Good for: teams with several developers and several apps.
Trade-off: one more tool and one more encrypted store to look after.

Option C: Apple's cloud signing

Since Xcode 13, Apple can sign distribution builds with a cloud-managed certificate: the private key stays with Apple, not on your machine. In CI this means giving xcodebuild an App Store Connect API key and -allowProvisioningUpdates at export time. Nesim Razon describes this setup in a recent DEV post about shipping a Kotlin Multiplatform app from Windows; in that write-up an App Manager key wasn't enough for cloud signing and an Admin key was.

We haven't tested this path ourselves, so two things to check if you use it:

  • Keep archive unsigned (Fix 1). Cloud signing covers distribution, but an automatically signed archive on a fresh machine can still go looking for a development identity, and that's where our stray certificate came from.
  • An Admin-role key can do a lot more than sign. Weigh that against storing a .p12.

Good for: people with no Mac at all who don't want to handle a .p12.
Trade-off: a high-privilege key lives in CI.

Option D: don't sign in CI

Build with CODE_SIGNING_ALLOWED=NO and sign on a machine you control. You still get compilation, tests and artifacts from CI, and your signing identity never leaves your laptop. If you have a Mac and ship once a week, this is a perfectly good answer.

Cleaning up what's already there

On developer.apple.com, Certificates, look at the development certificates named "Created via API" and check the dates against your CI history. Apple's docs say that any provisioning profile containing a revoked certificate becomes invalid, so before revoking, make sure no development profile you still use on your own machine includes it. Revoking stray development certificates doesn't touch apps already on the App Store, which are signed with your distribution certificate.

The rule we took away

A machine that is destroyed after the job should never be allowed to create anything in your Apple account. Credentials go in read-only; nothing comes out. Our check now isn't "did this build pass", it's "did the certificate count stay the same". A build that passes while it leaves something behind in a third-party account is the hardest kind of bug to notice.


This article was written with the help of AI and checked against our own build logs and the official Apple, GitHub and fastlane documentation.

Top comments (0)