Repository navigation
fix(desktop/auth): use the file-based keychain so beta sign-in works (Could not securely store sign-in tokens) - #9167
Conversation
…gn-in works Root cause of "Could not securely store sign-in tokens" (beta): DesktopKeychainStore opted into the data-protection keychain (kSecUseDataProtectionKeychain), which requires a keychain-access- groups entitlement. This non-sandboxed Developer ID app has no such entitlement (Omi-Release.entitlements: app-sandbox=false, no keychain-access-groups), so on the signed/ notarized build every SecItemAdd/Update failed with errSecMissingEntitlement (-34018) -> saveTokens() threw keychainTokenStorageUnavailable -> sign-in blocked. Dev builds use UserDefaults (usesKeychainTokenStorage = !isNonProduction), so it only ever failed on prod/beta. Fix: use the default file-based (login) keychain — a signed non-sandboxed app can read/write its own generic-password items without any keychain entitlement, and tokens still stay out of UserDefaults. Complements BasedHardware#9162's UserDefaults fallback (which unblocks sign-in but stores tokens in UserDefaults); with this the keychain actually succeeds, so the fallback isn't needed. - DesktopKeychainStore: drop kSecUseDataProtectionKeychain from the query. - AuthTokenStorageTests: source-guard against re-introducing the data-protection keychain (invisible to dev/CI since dev uses UserDefaults). - changelog. Verified: standalone SecItemAdd probe (data-protection -> -34018, file-based -> 0); build exit 0; AuthTokenStorageTests 5/5; and runtime — signed into a local named bundle with keychain forced on and the UserDefaults fallback disabled (so the outcome reflects the real keychain write). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
Fixes a production/beta-only desktop sign-in failure by switching the macOS token storage Keychain implementation away from the data-protection keychain (which requires entitlements this non-sandboxed Developer ID app doesn’t have) to the default file-based login keychain, and adds a regression guard to prevent reintroducing the problematic flag.
Changes:
- Removed
kSecUseDataProtectionKeychainfromDesktopKeychainStoreso signed builds can persist tokens withouterrSecMissingEntitlement (-34018). - Added a source-level regression test ensuring
DesktopKeychainStoredoes not opt into the data-protection keychain. - Updated fail-loud tests and added a desktop changelog entry describing the beta sign-in fix.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| desktop/macos/Desktop/Tests/FailLoudConfigTests.swift | Removes the now-obsolete assertion around using the data-protection keychain and documents where the new invariant is enforced. |
| desktop/macos/Desktop/Tests/AuthTokenStorageTests.swift | Adds a source-level regression test to prevent reintroducing kSecUseDataProtectionKeychain. |
| desktop/macos/Desktop/Sources/DesktopKeychainStore.swift | Drops the data-protection keychain opt-in so signed builds use the login keychain and avoid entitlement failures. |
| desktop/macos/changelog/unreleased/20260706-fix-beta-keychain-signin.json | Adds a changelog fragment for the beta sign-in/keychain storage fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 5/5
- In
desktop/macos/Desktop/Sources/DesktopKeychainStore.swift, the current comment appears broader than the actual dev/UserDefaults fallback and could mislead future edits aroundLocalAgentAPISettings; merged as-is, this is mainly a maintainability/documentation risk rather than a runtime one — narrow the wording to auth-token storage scope before or shortly after merge.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="desktop/macos/Desktop/Sources/DesktopKeychainStore.swift">
<violation number="1" location="desktop/macos/Desktop/Sources/DesktopKeychainStore.swift:14">
P3: This comment overstates the scope of the dev/UserDefaults behavior: `DesktopKeychainStore` is also used by `LocalAgentAPISettings` in dev builds. Narrowing the wording to auth token storage would avoid misleading future debugging of local-agent token keychain writes.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
cubic P3: the dev/UserDefaults caveat is specific to the auth-token path (usesKeychainTokenStorage = !isNonProduction). Note DesktopKeychainStore is also used by LocalAgentAPIServer on all builds, whose keychain writes hit the same entitlement failure and are fixed by the same change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Problem
On the signed/notarized beta, sign-in fails with "Could not securely store sign-in tokens. Please try again." — you cannot log in (screenshot from v0.12.37).
Root cause
DesktopKeychainStoreopted into the data-protection keychain (kSecUseDataProtectionKeychain: true), which on macOS requires akeychain-access-groupsentitlement. This app is a non-sandboxed Developer ID app with no such entitlement (Omi-Release.entitlements:app-sandbox=false, no keychain-access-groups). So on the signed build everySecItemAdd/SecItemUpdatereturnederrSecMissingEntitlement(-34018) →saveTokens()threwkeychainTokenStorageUnavailable→ sign-in blocked. Dev/named builds use UserDefaults (usesKeychainTokenStorage = !AppBuild.isNonProduction), which is why it only failed on prod/beta and slipped through CI.Fix
Drop
kSecUseDataProtectionKeychainso the store uses the default file-based (login) keychain — a signed non-sandboxed app can read/write its own generic-password items there without any keychain entitlement, and tokens still stay out of UserDefaults. (ClientDeviceServicealready uses this exact pattern in the same app.) This complements #9162's UserDefaults fallback: with the keychain actually succeeding, the fallback becomes a rare safety net instead of the norm.DesktopKeychainStore.swift: remove the data-protection flag from the shared query.AuthTokenStorageTests.swift: source-guard against re-introducing the data-protection keychain (this regression is invisible to dev/CI since dev uses UserDefaults).FailLoudConfigTests.swift: remove the now-invertedtestDesktopKeychainStoreUsesDataProtectionKeychain(its correct invariant now lives in the new guard).Verification
SecItemAddprobe: data-protection keychain →-34018; file-based →0.AuthTokenStorageTests5/5,FailLoudConfigTests6/6.🤖 Generated with Claude Code