Skip to content

Enforce credential ownership at the type level; move Runway-owned secrets in-process - #86

Merged
mstallone merged 45 commits into
keychain-read-coordinatorfrom
credential-ownership-model
Aug 4, 2026
Merged

mstallone merged 45 commits into
keychain-read-coordinatorfrom
credential-ownership-model

Conversation

@mstallone

@mstallone mstallone commented Aug 3, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #85 (keychain-read-coordinator), which is stacked on #84.

TL;DR: The ownership rule — only the app that owns a credential may modify it — is now enforced by the type system, and the one secret Runway actually owns moves to in-process Keychain storage with no subprocess and no secret in an argument list.

What was happening

  • Every store held the full read/write KeychainAccessing protocol, so nothing but discipline stopped a future change from writing another app's credential item — exactly the class of bug PR Make Claude credentials strictly read-only (no refresh, no writeback) #84 removed for Claude.
  • Runway's own secret (the iCloud-sync device id) was written through /usr/bin/security add-generic-password, which passes the value through the subprocess argument list (briefly visible to ps) and ACL-binds the item to the helper binary instead of Runway.

What this changes

  • Splits the Keychain protocol: KeychainReading (reads, probes, fingerprints) and KeychainAccessing: KeychainReading (writes). Stores that consume another app's credentials — Claude auth store, config-dir discovery, default-account observer, Copilot, Antigravity — now hold only KeychainReading, making a foreign-store write a compile error.
  • Adds RunwayOwnedKeychainStore for Runway-owned secrets: in-process SecItemAdd/SecItemCopyMatching/SecItemUpdate, a Runway-specific account, silent reads (the creating process's ACL), no subprocess.
  • Migrates the iCloud-sync device id to a Runway-owned v2 item with a one-time copy from the v1 item, so existing devices keep their iCloud record instead of minting a duplicate. The v1 item stays behind orphaned (its ACL belongs to the subprocess, so Runway cannot silently delete it) and is never read again once v2 exists.
  • Docs: a "Credential ownership" section in docs/architecture.md.

Heads-up

  • Deviation from the original plan: the plan said kSecUseDataProtectionKeychain. My first rationale for skipping it was wrong and has been corrected: release builds — and dev builds that find an iCloud provisioning profile — are signed with com.apple.application-identifier and keychain-access-groups (script/render_icloud_entitlements.sh), so the data-protection keychain would work there. The real constraint is that a plain local build signs with Runway.local.entitlements.plist, which carries neither; choosing per build flavor would split this item across two stores and mint a second iCloud sync identity for the same Mac. The login keychain behaves identically everywhere and already delivers what motivated the move (no subprocess, no argv exposure, app-owned ACL). An entitlement-gated migration with a copy-forward is viable follow-up.
  • Codex and Cursor still write their providers' stores (token rotation) and keep KeychainAccessing; extending the read-only ownership model to them is the planned follow-up after this stack, since it changes their refresh behavior the way Make Claude credentials strictly read-only (no refresh, no writeback) #84 changed Claude's.

Tests

  • Device-id migration: legacy v1 value is copied into the owned v2 item once and never consulted again; a missing id stays nil; dev/prod bundle scoping preserved.
  • RunwayOwnedKeychainStore round-trip + in-place update against a real login keychain (skips where unavailable).
  • The protocol split itself is compile-time enforcement; the existing Claude no-write regression tests from Make Claude credentials strictly read-only (no refresh, no writeback) #84 still pass on top.
  • swift test: 1,678 tests, 0 failures.

Review follow-up (later commit on this branch)

  • The legacy device-id migration no longer mints a duplicate identity. The existence gate used == true, so an unknown probe (locked keychain, suppressed UI) read as "no legacy item" — and with v2 and the saved preference both gone, resolveDeviceID minted a fresh UUID and published a second iCloud device record for a Mac that already had one. The probe is tri-state now: false migrates nothing (fresh install, no subprocess), unknown throws so the store surfaces its existing duplicate warning, true proceeds.

…rets in-process

- Split KeychainAccessing into read-only KeychainReading plus a writing
  refinement. Stores that consume another app's credentials (Claude,
  Copilot, Antigravity, config-dir discovery, the default-account
  observer) now hold only the read-only type, so writing a foreign
  credential store no longer compiles. Codex and Cursor keep the
  writing type until their own read-only audit (planned follow-up).
- New RunwayOwnedKeychainStore for secrets Runway itself owns: in-process
  SecItem calls, ACL-bound to Runway (silent reads), no /usr/bin/security
  subprocess, and no secret in an argument list. Not the data-protection
  keychain: that requires an entitlement the Developer ID build doesn't
  ship, and would fail with errSecMissingEntitlement.
- The iCloud-sync device id moves to a Runway-owned v2 item with a
  one-time copy from the v1 subprocess-created item, so existing devices
  keep their iCloud record.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c0f166585

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/architecture.md Resolved
…ychain read

Review finding: when the v2 item was missing, migration read the legacy
v1 item through the prompt-capable /usr/bin/security path at startup —
and a denial retried it on every launch. resolveDeviceID now seeds the
v2 item from the UserDefaults copy of the id (present on every normal
upgrade) without touching the Keychain; the legacy read runs only when
both are gone (a preferences reset), and at most once — after it either
the store holds an id or a freshly minted one is saved.
Review finding: v2-and-preference-both-absent describes a fresh install
as well as a preferences reset, so every fresh install spawned the
/usr/bin/security legacy read (silent for a missing item, but a locked
keychain could still raise an unlock prompt, and the subprocess is
pointless). The attributes-only existence probe now gates it: the
subprocess runs only when a v1 item actually exists.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef62a81583

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…dicting them

Cloud-review finding: the ownership section claimed Runway writes only
its own secrets and then immediately noted Codex/Cursor rotation. The
exceptions are now stated as exceptions — Runway-owned storage, and
Codex/Cursor's still-live writeback that the follow-up removes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5b7ac1f5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…rets

Cloud-review finding: the rejection premise was false. release.sh
embeds a provisioning profile and render_icloud_entitlements.sh adds
application-identifier + keychain-access-groups, so the data-protection
keychain WOULD work in release (and in dev builds that find a profile).
The actual constraint is that a plain local build signs with
Runway.local.entitlements.plist, which has neither — so choosing per
build flavor would split this item across two stores and mint a second
iCloud identity for the same device. Comment now says that, and notes
the entitlement-gated migration as viable follow-up.
Review finding (a regression from my own existence gate): the migration
used == true, so an UNKNOWN probe — locked keychain, suppressed UI —
read as 'no legacy item'. With v2 and the saved preference both gone,
resolveDeviceID then minted a fresh UUID and published a second iCloud
device record for a Mac that already had one. The probe is tri-state
now: false migrates nothing (fresh install, no subprocess), unknown
throws so the caller surfaces its existing duplicate warning, true
proceeds. It also probes the exact current-user item the read uses.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c3755e49a8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Review findings:
- Surfacing a warning was only half the fix. resolveDeviceID's catch
  still minted, persisted and (with sync on by default) PUBLISHED a
  fresh UUID, creating the very duplicate CloudKit record the tri-state
  probe was meant to prevent. An indeterminate lookup now yields a
  provisional identity: nothing is written to defaults, performWrite
  refuses to publish, and the user is told usage won't publish until
  Keychain access returns. A known saved id still publishes, since
  that id is correct — just not durable.
- The regression test disabled sync and only checked serviceError, so it
  never proved the important part. It now runs with sync ON and asserts
  zero writes and no persisted id.
- Moved the identity/migration tests and their doubles into
  ICloudDeviceIdentityTests.swift, bringing the oversized suite back
  under the repository's ~500-line guideline (712 → 498).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7bc1e0d87e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…n in-session

Review blocker + follow-on:
- The peer merge excluded only the freshly minted provisional UUID, so
  this Mac's OWN earlier cloud record looked remote and double-counted
  its local usage and spend. Provisional mode now contributes no peer
  history at all (the record still lists in Settings).
- The identity was immutable for the session while the notice promised
  publishing would resume 'when Keychain access is available again'.
  Each publish attempt now retries resolution first, so an unlock
  restores syncing without a relaunch.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d6081a4d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ional identity

Review finding: a provisional id is not the id this Mac published under,
so the opt-out delete removed nothing while the real record stayed in
CloudKit indefinitely — and turning sync off also stops the retries that
would have resolved the identity. The opt-out now retries resolution
first and, when it still can't identify the Mac, says the record wasn't
removed and what to do about it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b58fe1c3aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Review finding: the opt-out warning was written to serviceError, which
ICloudSyncSettingsSection renders only inside its enabled-only content —
so the user never saw that this Mac's existing record hadn't been
removed, and nothing retries while sync is off. The store now exposes
the subset of that state which outlives the toggle, and the section
renders it in the disabled case.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ed44fb736

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mstallone mstallone closed this Aug 4, 2026
@mstallone mstallone reopened this Aug 4, 2026
The opt-out retry work pushed both the store and its tests past ~500
lines. The device-id storage protocol and its Keychain implementation
are a self-contained concern, so they move to their own file, and the
opt-out lifecycle tests split from the identity/migration ones along
the seam they already had.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75a1d5b6d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The completed-deletion path cleared the pending flag and then cancelled
optOutRetryTask — while running inside that very task, immediately
before awaiting the republish. A cancellation-aware CloudKit write would
abort, leaving a re-enabled Mac's record absent until something else
scheduled a write.

Clearing the flag already ends the loop, so the retry no longer cancels
anything. The disable path still cancels, but after the republish rather
than before it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0dd6af1414

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Two problems the review found, both in the same shape — a deletion whose
failure was not remembered:

- The compensating deletion (a publish that lands after the user opted
  out) threw into the write catch, which records a write error and
  nothing else. The opt-out's own deletion had already succeeded and
  cleared the pending flag, so the user was told sync was off while
  their record was back in iCloud with nothing scheduled to remove it.
- The legacy device-id migration read through /usr/bin/security, so a
  Mac whose v1 item exists but isn't readable would spawn a
  prompt-capable subprocess on an automatic path — and again on every
  retry, since that item's ACL names the security helper, not Runway.
  It now uses the in-process prompt-free read; a failure leaves the
  identity provisional with its existing warning, which is honest.

deleteOwnRecord is now the only path that removes this Mac's record. It
persists the intent BEFORE trying, so a failure or a crash mid-flight is
remembered and retried instead of silently dropped.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0a55e898f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Three findings, all the same failure to converge on a Mac where nothing
else is running:

- The opt-out retry exhausted its backoff list after about 51 minutes
  and then stopped. It now keeps trying at the final interval for as
  long as the deletion is pending.
- A provisional identity was only retried from a publish, which needs a
  provider to refresh. The five-minute poll now retries it too, and
  publishes once it resolves.
- A device-id item present but not decodable as UTF-8 read as absent,
  which would mint a fresh UUID and publish a second record for a Mac
  that already had one. It now surfaces as a read error, leaving the
  identity provisional.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 375d2bf284

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mstallone

Copy link
Copy Markdown
Owner Author

External review: two iCloud blockers — both fixed

1. The legacy migration could still launch /usr/bin/security automatically. Existence-gating protected fresh installs, but a Mac whose v1 item exists and cannot be read still reached the subprocess — on an automatic path, and again on every retry, because that item's ACL names the security helper rather than Runway. migrateLegacyDeviceID now uses the prompt-free in-process read; a failure leaves the identity provisional with its existing warning, which is the honest outcome.

Consequence worth stating plainly: a Mac that lost its preferences and has an unreadable v1 item can no longer complete the migration silently. It keeps working, publishes nothing, and says so. Restoring that capability wants an explicit "Repair iCloud identity" action — additive UI, so it is left as an owner decision rather than smuggled in here.

2. An in-flight write could recreate the record after opt-out, undetected. If the opt-out deletion succeeded and a still-running write then landed, the compensating deletion removed it — but a failure of that compensating deletion threw into the write catch, which records a write error and nothing else. The pending flag had already been cleared, so the user was told sync was off while their record was back in iCloud with nothing scheduled to remove it.

deleteOwnRecord is now the only path that removes this Mac's record. It persists the intent before attempting, so a failure — or a crash mid-flight — is remembered and retried. testAFailedCompensatingDeletionIsRememberedRatherThanLost reproduces the race (opt-out deletion succeeds, compensating one fails) and fails against the previous code.

A v2 item holding readable text that is not a UUID normalized to nil,
which is indistinguishable from having no item at all — so with
preferences also gone, a fresh id would be minted and a second record
published for a Mac that already had one. It now fails into the same
provisional path an unreadable item takes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c50f717e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Both fixes landed without tests, which the repo's conventions ask for.
One proves a readable-but-not-a-UUID stored id reports an error and
neither persists a replacement nor publishes under one; the other proves
the owned store throws on a present-but-undecodable value instead of
reporting it absent. Verified both fail against the previous behavior.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5a0e7f1e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

normalizedDeviceID collapsed a non-UUID legacy value to nil, which then
took the fresh-install branch and minted a replacement — publishing a
second record for a Mac that already had one, and overwriting the
evidence that its real identity was never recovered. The v2 item already
had this guard; the legacy path now matches it and stays provisional.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@mstallone
mstallone merged commit bf8d6fc into main Aug 4, 2026
2 checks passed
mstallone added a commit that referenced this pull request Aug 4, 2026
…sr/bin/security (#87)

> Stacked on #86 (`credential-ownership-model`) → #85 → #84. Closes the
gap a post-stack review found: the exact `/usr/bin/security
find-generic-password` pattern behind the 2026-08-03 prompt loop was
still live for Copilot (and Antigravity), including at launch.

**TL;DR**: The read-only providers' Keychain reads (Copilot's
`gh:github.com`, Antigravity's `gemini`/`antigravity`) now run
in-process through the coordinator: automatic refreshes are prompt-free
by construction, and only a manual refresh may raise the approval dialog
— once, authorizing Runway itself.

## What was happening

- `CopilotAuthStore` and `AntigravityAuthStore` read their foreign
Keychain items through the `/usr/bin/security` subprocess — the
prompt-capable path whose dialogs authorize the helper binary instead of
Runway, so approvals never stick to the app and the prompt can recur
every cycle. Launch-time credential detection used the same path.
- The PR #85 coordinator only covered in-process reads, so these
subprocess reads bypassed the fingerprint gate, single-flight, and
circuit breaker entirely.

## What this changes

- `KeychainReading` gains account-scoped
`readGenericPasswordWithoutUserInteraction(service:account:)` and
`readGenericPasswordAllowingUserInteraction(service:account:)`;
`SecurityKeychainAccessor` serves both through the existing coordinated
in-process path (change-gated, single-flight, circuit-broken). Mock
defaults route them through the plain account read, so existing test
fakes are untouched.
- Copilot: `loadToken` / `loadBillingTokenCandidates` take
`allowKeychainInteraction` (default false). Automatic refresh and
`hasLocalCredentials` use the prompt-free form; a manual refresh uses
the interactive form. A denied interactive read is not retried through
the broader service-only lookup — that would just repeat the same
prompt.
- Antigravity: `loadKeychainToken` gets the same mode split; an
unauthorized item on the automatic path surfaces the existing friendly
"couldn't read credentials" error locally instead of prompting.
- Docs: prompt behavior notes in `docs/providers/copilot.md` and
`docs/providers/antigravity.md`.

## Heads-up

- **One-time migration friction**: users whose previous "Always Allow"
was granted to `/usr/bin/security` will see the Copilot/Antigravity
Keychain source report unavailable until one manual refresh re-approves
access for Runway itself. After that, reads are silent and survive
forever (the grant now sticks to the app). File-based sources (editor
config, `hosts.yml`) are unaffected and remain first in line.
- Also in this push (amendments from the same review, committed to their
own PRs): the fingerprint probe now runs **inside** the coordinator's
single flight (#85 — a late arriver no longer touches the Keychain at
all, not even the attributes query), and the iCloud device-id migration
seeds from the saved UserDefaults copy so the legacy prompt-capable read
runs only after a preferences reset, at most once (#86).
- After this PR, the only remaining `/usr/bin/security` reads (and
writes) belong to Codex and Cursor — the disclosed read-write ownership
audit that follows this stack.

## Tests

- `ReadModeTrackingKeychain` regression tests: automatic
Copilot/Antigravity loads perform only prompt-free reads and never the
subprocess-style path; manual loads use the interactive read; an
`.unavailable` item throws the friendly error without prompting.
- Coordinator: new test proving a late arriver behind a stuck read
performs no Keychain call at all (#85); iCloud tests proving the
saved-preference seed never touches the legacy path and legacy recovery
runs at most once (#86).
- `swift test`: 1,689 tests, 0 failures.

---

## Review follow-ups (later commits on this branch)

- **Copilot billing keeps the permission state.**
`loadBillingTokenCandidates` discarded `keychainPermissionRequired`, so
an org-managed seat fell back to an editor token that usually lacks
billing scopes and the card said "you need billing access" when an
existing credential just needed approval.
- **Antigravity gained a permission-specific error.** A protected item
mapped to `credentialStoreUnreadable`, whose text says unlock Keychain /
sign in again — neither fixes an unapproved ACL.
- **Corrected the CLI documentation twice.** `--force` is not equivalent
to ⌘R (it never prompts), *and* — the part I got wrong on the first pass
— approving an item in the app does **not** authorize the command,
because `runway` is a separately signed binary and macOS grants Keychain
access per binary. Keychain-only providers reach the CLI through the
app's shared snapshot instead.

### Correction

An earlier revision of this description said Codex/Cursor writes were
the only remaining `/usr/bin/security` use. That omitted the one-shot,
existence-gated **legacy iCloud device-id migration read**, which
remains after the whole stack. Also in later commits on this branch:
Copilot billing keeps its permission state, Antigravity distinguishes a
locked keychain from an unapproved ACL (they need opposite advice), and
`ProviderRefreshContext` carries `isForced` separately from `isManual`
so `runway --force` keeps bypassing negative caches without unlocking
credential UI.
mstallone added a commit that referenced this pull request Aug 4, 2026
…security (#89)

> Stacked on #88, the tail of the credential stack. Closes the "High"
finding from the latest post-stack review: Codex and Cursor could still
recreate the automatic password-prompt loop.

**TL;DR**: The last automatic prompt-capable `/usr/bin/security` reads —
Codex's keyring lookups (detection, refresh fallback, unattended
identity warming) and Cursor's two per-load reads — now run in-process
through the coordinator, prompt-free on every automatic path.

## What was happening

- `CodexAuthStore.loadKeychainAuth` and `CursorAuthStore`'s keychain
reads used the `/usr/bin/security` subprocess: prompt-capable, ACL'd to
the helper binary, uncoordinated, and running on launch detection, every
automatic refresh, and Codex's background identity-warm task.
- A protected item silently collapsed into "not logged in", so
keychain-only logins were undetectable and unapprovable.

## What this changes

- Codex `loadKeychainCredentials` / Cursor `loadCredentials` (tri-state
like Copilot's): automatic paths use the prompt-free in-process reads;
only a manual refresh may raise the approval prompt — once, authorizing
Runway itself.
- A protected item reports **permission-required**: it counts as a
credential footprint for seeding, and the card says "…login found in
Keychain. Refresh manually and choose Always Allow to connect it."
- Cross-login guard mirrors the Copilot fix: a protected exact item
(per-home Codex account item) never broadens to the service-only lookup,
which could silently select a different login. Other Codex homes are
still tried — each read targets its own exact account.
- The unattended identity-warm task keeps its collapse-to-nil behavior
(a protected home stays hidden with the existing log line) and is
prompt-free by construction.
- Docs: prompt behavior notes in `docs/providers/codex.md` /
`cursor.md`; `docs/architecture.md` now states every provider's
automatic Keychain reads are in-process and prompt-free.

## Also in this stack push (fixes from the same review, committed to
their PRs)

- **#85**: public existence/fingerprint probes now share the
coordinator's per-item flight — a probe of an item whose read is wedged
returns "unknown" within the bounded wait instead of stacking another
`SecItemCopyMatching` onto securityd.
- **#86**: the legacy device-id migration is gated on a prompt-free
existence probe, so a fresh install never spawns the `/usr/bin/security`
subprocess at all.

## Heads-up

- Same one-time migration friction as #87: an "Always Allow" previously
granted to `/usr/bin/security` doesn't carry over; the card shows the
permission-required message until one manual refresh re-approves for
Runway. The grant then sticks to the app permanently.
- After this PR the only `/usr/bin/security` invocations left are
Codex/Cursor **token-rotation writes** and the one-shot legacy device-id
migration (now existence-gated). The write side is the remaining
ownership audit — it decides whether Codex/Cursor become read-only like
Claude, which changes rotation behavior and deserves its own design
pass.

## Tests

- Codex + Cursor read-mode regression tests (shared
`ReadModeTrackingKeychain`): automatic loads perform only prompt-free
reads, manual loads only interactive ones, never the subprocess-style
path; protected items report permission-required and never broaden; a
coordinator test proves probes don't stack behind a wedged read; an
iCloud test proves fresh installs never spawn the legacy read.
- `swift test`: 1,698 tests, 0 failures.

---

## Review follow-ups (later commits on this branch)

- **Reset-credit claims can request approval.** `CodexResetClaimService`
loaded keyring credentials non-interactively and collapsed
permission-required to `nil`, so clicking **Use** reported a generic
"Couldn't reset usage" while the credential that could serve it sat
unread. Claiming is an explicit user action, so it may prompt exactly
like a manual refresh.
- **A denied Codex prompt stops the scan** on this branch too (it was
previously only fixed downstream), so this PR is correct standing alone:
an interactive denial returns `permissionRequired` immediately instead
of opening one dialog per remaining Codex home.
@mstallone
mstallone deleted the credential-ownership-model branch August 4, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant