# Keychain Prompts Hanging codesign

## Symptom & Root Cause

Unattended `codesign` or `xcodebuild archive` runs launched over SSH, CI runners, or background coding agents either hang indefinitely waiting for a GUI Keychain password dialog or fail immediately with `errSecInternalComponent` or `errSecInteractionNotAllowed` (`User interaction is not allowed`). macOS restricts private key access in `login.keychain-db` by process partition list and GUI session lock state, so any non-interactive signing invocation triggers an OS authorization prompt that headless tools cannot click.

## Exact Diagnostic & Fix Commands

Verify available signing identities and inspect Keychain lock status:

```sh
# List valid code signing identities in the active keychain search list
security find-identity -v -p codesigning

# Inspect keychain search list and lock settings
security list-keychains -d user
security show-keychain-info ~/Library/Keychains/login.keychain-db
```

If you must keep using `/usr/bin/codesign` in an existing script, unlock the keychain and grant partition access to Apple's signing tools:

```sh
# Unlock login keychain in the current session
security unlock-keychain -p "<KEYCHAIN_PASSWORD>" ~/Library/Keychains/login.keychain-db

# Allow codesign to access private keys without GUI prompts
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "<KEYCHAIN_PASSWORD>" ~/Library/Keychains/login.keychain-db
```

Import your Development identity into XCLoom once in an interactive TTY so background runs do not touch Keychain again (only pass `--include-distribution` on a dedicated release host):

```sh
# Inspect Keychain identities visible to XCLoom
xcloom sign list-keychain --json

# Run once in an interactive terminal (Development identity by default)
xcloom sign import-keychain --team-id <TEAM_ID>
# Dedicated release host only (adds Apple Distribution):
# xcloom sign import-keychain --team-id <TEAM_ID> --include-distribution
```

## How XCLoom Prevents Recurrence

Running `xcloom sign import-keychain` requires an interactive TTY (blocking headless agents from exporting Keychain credentials automatically). Development identities are imported by default, while Distribution and Release signing require explicit `--include-distribution` opt-in (omitting it returns `XCLOOM-SIGN-DISTRIBUTION-OPT-IN-REQUIRED`). XCLoom stores an encrypted `kc_<fp>.p12`, a `0600` `.p12.password` file, and a public `kc_<fp>.cer` inside a `0700` team-scoped directory excluded from Time Machine backups, zeroizing secret buffers on drop. That protects against stray plaintext `.key.pem` files, Time Machine leaks, other macOS accounts, and headless Keychain exports without a TTY; it does not isolate against other unsandboxed processes running as the same macOS user (since the sibling `.p12.password` enables unattended signing).

Subsequent `xcloom build`, `xcloom archive`, and `xcloom preview` commands compute CMS signatures directly in process without calling `Security.framework` Keychain UI prompts. On an `85 MB` app with 27 bundles, XCLoom completes self-signed CMS signing in `0.43s` (9-run median), produces output verified by `/usr/bin/codesign --verify --deep --strict`, and emits `XCLOOM-SIGN-KEYCHAIN-UNIMPORTED` early with an actionable command if an identity has not been imported yet.

Threat model boundary: because unattended local signing reads both the `0600` `.p12` and `.p12.password` under your macOS user account, any unsandboxed coding agent running as the same macOS user can access user-owned files. Keep coding-agent hosts on Development identities only, and isolate Apple Distribution signing to a dedicated user account or release host if you do not trust agent file reads.

## Frequently Asked Questions

### Are XCLoom CMS signatures accepted by macOS and App Store Connect?

XCLoom generates standard Mach-O code directories and CMS signature blobs that pass `/usr/bin/codesign --verify --deep --strict` on macOS (`0.43s` self-signed CMS 9-run median on an `85 MB` app with 27 bundles). Full Apple Distribution signing with RFC 3161 TSA timestamping, physical iPhone install, and App Store Connect acceptance is not yet measured on a device; standard `codesign` and `xcodebuild` remain available anytime for release signing.

### Do I need to embed my login keychain password in CI scripts?

No. Importing once in an interactive TTY with `xcloom sign import-keychain` (Development by default, or `--include-distribution` for Distribution/Release signing on a dedicated release user/host, or supplying `--p12` / `--cert` + `--key` explicitly on CI) removes the need to pass your macOS login keychain password to `security unlock-keychain`.

### What does `XCLOOM-SIGN-KEYCHAIN-UNIMPORTED` mean?

It means XCLoom detected a valid signing certificate for your `DEVELOPMENT_TEAM` in macOS Keychain that has not been imported yet. Run `xcloom sign import-keychain --team-id <TEAM_ID>` once interactively for Development signing, or add `--include-distribution` for Distribution and Release signing (omitting it when Distribution signing is required returns `XCLOOM-SIGN-DISTRIBUTION-OPT-IN-REQUIRED`).

## Related Links

- [ITMS-90046 & Late TestFlight Rejections](/errors/itms-90046-and-app-store-preflight/)
- [Why Claude Code Spent 70% of My iOS Sessions Waiting on Xcode](/blog/70-percent-xcode-wait-claude-code-ios/)
- [XCLoom Benchmarks](/benchmarks/)
- [All iOS Build & Simulator Errors](/errors/)
