Home/Guides/Code signing hangs on a CI Mac: unlock the keychain or use a dedicated one

Code signing hangs on a CI Mac: unlock the keychain or use a dedicated one

Updated · airankrush

What this guide covers

When you finish, unattended build jobs can sign without any pop-up. You need: the distribution certificate's .p12 and its password, the matching provisioning profile, and a build agent.

Steps

  1. First understand why it hangs

    When signing, codesign uses a private key in the keychain. In the graphical desktop you are logged in to, the login keychain is unlocked, and the first use pops up a window where you click Allow. In a background service nobody clicks that window, so the job waits indefinitely. In some sessions the login keychain is simply locked, and the error says no signing identity was found.

    The approach: give CI a dedicated keychain it can unlock itself, and authorize Apple's tools in advance to use the private key in it.

  2. Create a dedicated keychain

    The flow below matches the script in GitHub's official documentation on installing an Apple certificate on runners and applies in any CI system:

    security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
    security set-keychain-settings -lut <timeout in seconds> "$KEYCHAIN_PATH"
    security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"

    -t is the auto-lock timeout in seconds; pick a value longer than your longest build. Use a randomly generated value for the keychain password and keep it in CI's secret variables. Do not use this Mac's login password.

  3. Import the certificate and authorize it

    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"

    The first imports the .p12 into the dedicated keychain. The second sets the private key's partition list, allowing Apple's own signing tools to use it without a pop-up. The .p12 is usually stored as encoded text in a CI secret variable and restored to a temporary file when the job starts.

  4. Add it to the search list without pushing out the login keychain

    security list-keychains -d user
    security list-keychains -d user -s "$KEYCHAIN_PATH" ~/Library/Keychains/login.keychain-db

    -s means "set" the search list to the keychains that follow, not append to it. If you list only the dedicated keychain, the login keychain disappears from the list, and your other apps in the graphical interface can no longer find the passwords saved there. So use the first command to see the existing list, then include the existing entries as well.

  5. Verify the identity is usable

    security find-identity -v -p codesigning "$KEYCHAIN_PATH"

    If it lists your distribution certificate, the import succeeded. The provisioning profile has to be placed separately where Xcode can find it; see the script in the GitHub documentation above.

  6. Clean up when the job ends

    GitHub's documentation specifically warns that on self-hosted runners the temporary directory is cleared when the job ends, but the keychain and provisioning profile may remain on the machine, so add a cleanup step that runs whether the job succeeds or fails:

    security delete-keychain "$KEYCHAIN_PATH"

    delete-keychain deletes the keychain and removes it from the search list. If you use fastlane, setup_ci creates a temporary keychain for match to use; the principle is the same.

  7. Boundaries on a rented machine

    Work only with keychains you created yourself and your own account's login keychain. Do not modify the System keychain (the one under /Library/Keychains) or delete entries in it that you do not recognize; it may hold items the platform's management needs.

    security unlock-keychain -p can be used to unlock the login keychain, but that means handing the Mac login password to CI in plain text. The tool itself warns that this is insecure, and we do not recommend it. Before the rental ends, delete the dedicated keychain and confirm the original .p12 is in your own storage.

FAQ

The error says no signing identity was found. What should I check?

Check three things in order: whether the keychain is unlocked, whether it is in the search list, and whether it contains a certificate with a private key. Confirm each one with the find-identity command.

The build just sits at signing with no error. What is happening?

It is waiting on an authorization window nobody is clicking. Connecting to the remote desktop usually shows that pop-up. The lasting fix is to set the partition list on the private key rather than clicking Allow each time.

Can I just use the login keychain instead of creating a dedicated one?

Yes, provided the agent runs in a logged-in graphical session and you have already clicked Always Allow for the relevant tools in the interface. The downside is that the state is opaque, and you have to do it all again on a new machine.

Signing failed after I changed the Mac login password. What should I do?

The login keychain's password is tied to the login password, so keychain prompts may appear after a change. Note the text of the prompt and contact Contact support; do not empty the keychain yourself. A dedicated keychain is not affected by this.

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

Back to home · All guides