Open source · Merged
Stop Keychain prompts on every launch
macOS kept asking for Keychain access and forgot the active team. The fix persists a team name — never a secret — and stops re-asking after a denial.
The issue
Shipyard Connect stores one App Store Connect API key per team. On macOS that means the Keychain, and the app was behaving as if it had forgotten that fact. It asked for Keychain access repeatedly, and after switching accounts it no longer knew which team was active.
The worst case was a denial: if someone declined the Keychain prompt, the app asked again on the next launch. And the next. A permission decision that should have been remembered forever was being re-litigated every time the app started.
Root cause
- No persisted team. Login state was derived from the Keychain on launch, but the last-selected team was never remembered, so the app had to rediscover it — and rediscovery meant touching the Keychain again.
- The legacy migration ran on every launch. The unscoped migration scan looked for pre-sandbox credentials each time, even after it had succeeded. A denial did not stop it, which is why the prompt kept coming back.
- Credentials were decoded again on every switch. Moving back to a team already used in the session hit the Keychain instead of a cache.
-
The team picker did not observe the selection.
selectedTeamwas not@Published, so switching accounts could leave the picker showing stale state. - Duplicate items. A re-added team could briefly appear twice: its new item and its orphaned pre-sandbox item shared the same name.
The fix
- Persist the name of the last-selected team in UserDefaults and restore it on launch. Secrets never leave the Keychain; a name is not a secret.
-
Run the legacy migration once ever, and set the flag only after a successful
pass. Back off permanently on
errSecAuthFailed/errSecInteractionNotAllowed, so a denial is respected. Transient errors still retry. - Cache decoded credentials per team, and keep a negative cache for unreadable teams so a denied team is not re-queried — and the user is not re-prompted — for the rest of the session.
-
Make
selectedTeam@Published; sort and dedupe the team list. -
Add
kSecAttrSynchronizable=falseso API secrets never sync to iCloud Keychain, and add akeychain-access-groupsentitlement so a sandboxed app keeps a stable identity across launches.
Tests and verification
This change is honest about what unit tests can and cannot prove. Keychain prompts need a signed, sandboxed app and a real user decision, so the verification was a Swift build plus a live probe.
- The Swift build passed.
- A live Keychain probe confirmed that existing items without the synchronizable attribute still match the new query. That mattered: adding an attribute to a query can silently orphan every credential already on disk.
- The denied-prompt path is covered by state: the migration flag is only written after success, and the denial branch is terminal for that install.
Trade-offs
- Storing a team name outside the Keychain is a deliberate split: convenience data in UserDefaults, secrets in the Keychain. The alternative — storing the credential — would have made the prompt problem worse, not better.
- Permanent backoff after denial means a user who changes their mind may need to reset the app's permission state. That is the right default: an ignored security prompt should not nag.
-
Pre-sandbox items become invisible to the sandboxed build. The PR documents the
cleanup: delete the orphan with
security delete-generic-passwordand re-add the team once.
Result: the active team is remembered across launches, credentials are read once per session, and a denied prompt is never asked twice.