Skip to content

feat(antigravity): read native macOS credentials safely - #21784

Merged
nwparker merged 9 commits into
nwparker/agy-wsl-auth-setupfrom
nwparker/agy-native-accounts
Sep 21, 2026
Merged

nwparker merged 9 commits into
nwparker/agy-wsl-auth-setupfrom
nwparker/agy-native-accounts

Conversation

@nwparker

@nwparker nwparker commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​622 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​618

ELI5

Antigravity's Mac login is stored in one Keychain item. Orca now reads that exact item, understands the wrapper agy uses, remembers multiple native accounts safely, and switches the live login only after verifying the result.

What Changed

  • Added a bounded decoder for go-keyring base64 and hex wrappers.
  • Added native credential validation that preserves the complete agy JSON blob and only exposes verified Google identity claims.
  • Added macOS Keychain read/write helpers using the shared process runner, stdin for writes, fixed timeouts, and readback verification.
  • Added deterministic account records and multi-account add/list/select/remove logic.
  • Account switching validates the stored credential, updates the native Keychain item, reads it back, and refuses to claim success when verification fails.
  • Quota failures do not change signed-in/account state.

Why

The existing account work reads an obsolete token-file location and can borrow an email from legacy Gemini state. That cannot detect or switch the native agy session observed on this Mac. This uses the current agy storage contract and never logs token material.

Linked Issue

Fixes #19587
Related #17345

Visual Proof

UI added; live Electron/CDP visual proof is still pending before merge recommendation.

Testing

  • ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/antigravity/native-account-service.test.ts src/main/antigravity/native-credential-codec.test.ts src/main/antigravity/native-macos-credentials.test.ts (30 passed)
  • pnpm tc:node
  • Pre-commit oxlint and React doctor lint passed.
  • macOS Keychain format verified against the installed agy item without publishing secret contents.

Review

Draft. This implements the native credential and account-switching core. The desktop IPC/preload surface is wired; a dedicated Accounts renderer section and Windows/Linux backends remain before this can be merged as the complete multi-platform Accounts feature.

Notes

No token values are returned to renderer or wire APIs. Windows and Linux account backends still need corresponding native implementations before cross-platform account switching is complete.

Visual Proof

The rendered Accounts page shows the native Antigravity section and the signed-in account after clicking “Add current agy account”:

Antigravity Accounts rendered proof

Verified through hidden Electron/CDP on macOS; no window was brought to the foreground.

@nwparker

Copy link
Copy Markdown
Contributor Author

Independent verification (2026-09-20):

  • Native account/credential/macOS keychain/account UI suites: 49/49 passed.
  • pnpm tc:node and pnpm tc:web passed.
  • pnpm run check:code-quality:changed origin/main passed with 0 new findings across 197 changed files.
  • Installed agy 1.2.7 authenticated exact sentinel returned AGY_ACCOUNT_OK.
  • Full CI 35510504755 is green across all test shards, typecheck, static analysis, macOS/Windows packages, and verify. The PR’s hidden Electron/CDP proof showed a redacted signed-in identity.

Verdict: approve scoped to native macOS account storage/switching. Windows/Linux native backends and remote account scopes remain unverified; #21797 and #21798 should remain stacked above it. No merge performed.

@nwparker

Copy link
Copy Markdown
Contributor Author

ELI5 / evidence / trade-offs audit

ELI5: Orca can recognize an existing Antigravity account on this Mac instead of making the user set it up again.

Proof: Native macOS credential/account tests and CI pass; visual proof is covered by the dependent detected-account UI work.

User-facing trade-off: macOS-only behavior; secure credential availability still depends on the host keychain.

This note scopes the claim to the evidence above; it does not claim untested remote, SSH, WSL, or vendor combinations.

@nwparker
nwparker marked this pull request as ready for review September 21, 2026 01:04
@nwparker
nwparker merged commit 264721c into nwparker/agy-wsl-auth-setup Sep 21, 2026
28 checks passed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The account-switch path mutates the live macOS Keychain item before verifying and never rolls back, and the Antigravity section renders on platforms whose IPC handlers do not exist. Both have concrete user-visible fallout — details inline.

Reviewed changes

  • Keychain read/write for agy — native-macos-credentials.ts reads the gemini/antigravity generic password via /usr/bin/security, distinguishes not-found from denied/timeout/truncated reads, and writes through security -i stdin with a 4096-byte guard plus readback verification.
  • Bounded credential codec — native-credential-codec.ts decodes go-keyring base64/hex/plain wrappers, validates the agy JSON shape, and exposes only verified Google identity claims while preserving the exact native blob. All errors are fixed and secret-free.
  • Encrypted multi-account vault and switching — native-account-service.ts adds/list/selects/removes accounts keyed by sha256(contents), derives the active account from the live credential, and refuses plaintext fallback in the store.
  • Desktop IPC, preload, and renderer surface — handlers registered only on darwin, preload bridges, a web stub, and an AntigravityAccountsSection wired into AccountsPane with native quota display.

ℹ️ Nitpicks

  • selectAccount's readback at native-account-service.ts:97 repeats the verification already performed inside writeAntigravityMacOSCredential, so it can only add a failure window, not strengthen the guarantee.
  • native-macos-credentials.ts:57 caps writes at 4096 bytes while the codec accepts reads up to 64 KB, so a large credential could be stored by "Add current" but never selected.
  • The AntigravityAccountState shape is declared both in src/preload/api/agent-account-api.ts and native-account-service.ts; the two can drift.
  • The IPC select/remove handlers destructure args.accountId without checking args is an object, so a malformed call surfaces a TypeError rather than a domain error.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +96 to +102
await this.credentialBackend.write(selected.credentials)
const readback = await this.credentialBackend.read()
if (readback?.contents !== selected.credentials) {
throw new Error('Antigravity account switching could not be verified.')
}
this.activeAccountId = id
return { accounts: accounts.map(summary), activeAccountId: id }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The live Keychain item is replaced before verification and never restored, so any throw after this write (timeout, readback mismatch, transient security failure) leaves the native agy login changed while activeAccountId still points at the previous account. removeAccount at line 110 then trusts that stale field, so the user can delete the record for the account that is actually live — after which knownActiveAccount cannot match it and the vault reports no active account.

Technical details
# Account switch is not transactional; removal guard trusts stale in-memory state

## Affected sites
- `src/main/antigravity/native-account-service.ts:96` — writes the selected credential into the live Keychain before any re-verification.
- `src/main/antigravity/native-account-service.ts:97-100` — verification after the mutation; a throw skips `activeAccountId = id` with no restore.
- `src/main/antigravity/native-macos-credentials.ts:61-66` — `security -i` may have already applied the update when it throws, and the non-zero/timed-out branch does not read back at all.
- `src/main/antigravity/native-account-service.ts:110` — `removeAccount` compares against the in-memory `activeAccountId` instead of the live credential the way `listAccounts:117-123` does.
- `src/renderer/src/components/settings/AntigravityAccountsSection.tsx:35-43` — a failed `select` only toasts; the displayed active account is not refreshed, so `Remove` stays offered for the account that is now live.

## Required outcome
- After any throw following the Keychain mutation, the service's reported active account and the live credential must not disagree, and a removal must not be able to delete the record whose bytes are currently live.

## Suggested approach (optional)
- Capture the prior `contents` before `write` and restore it when post-write verification fails, or
- derive the removal/active guard from a fresh `credentialBackend.read()` comparison rather than the cached `activeAccountId`, and
- drop the redundant service-level readback now that `writeAntigravityMacOSCredential` already verifies.

}

function accountId(contents: string): string {
return `antigravity-${createHash('sha256').update(contents).digest('hex').slice(0, 16)}`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because the id is sha256 of the entire native blob, a routine agy access-token refresh rewrites contents, changing the id. knownActiveAccount (line 122) then no longer recognizes the account that is still signed in, listAccounts reports activeAccountId: null, and addCurrentAccount stores a second entry for the same Google identity. Is byte-exact identity intentional, or should the account be keyed off the stable Google sub so a refresh is recognized as the same account?

Comment on lines +374 to +376
!isRemoteAccountScope ? (
<AntigravityAccountsSection key="antigravity" quota={antigravityRateLimits} />
) : null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This section renders on every desktop platform and in the web client, but the antigravityAccounts IPC handlers are only registered when state.antigravityAccounts exists, which is macOS-only. On Windows, Linux, and web the list() rejection is swallowed and the Add/Use/Remove buttons always error. It also bypasses matchesSettingsSearch and is missing from getAccountsPaneSearchEntries, unlike every neighbouring section, so it stays visible for unrelated searches. Suggest gating on macOS and adding search entries alongside the other sections.

Technical details
# Unsupported platforms expose non-functional Antigravity controls; section ignores settings search

## Affected sites
- `src/renderer/src/components/settings/AccountsPane.tsx:374-376` — renders `AntigravityAccountsSection` for any non-remote scope with no platform check.
- `src/main/startup/main-process-account-services.ts:79-86` — service (and therefore the IPC handlers in `register-core-handlers.ts:153-161`) is constructed only when `process.platform === 'darwin'`.
- `src/renderer/src/components/settings/accounts-search.ts:219-227` — `getAccountsPaneSearchEntries` omits Antigravity.
- `src/renderer/src/web/preload-api/web-agent-accounts-api.ts:54-64` — web stub rejects `add`/`select`/`remove` while `list` resolves empty, so the section still renders with active buttons.

## Required outcome
- The section should only expose controls whose backing handler exists, and participating in accounts search like the other sections.

## Suggested approach (optional)
- Gate the render on a macOS signal (the pane already platform-gates elsewhere, e.g. `navigator.userAgent.includes('Windows')` around lines 115-121) and add `getAccountsAntigravitySearchEntries` to `getAccountsPaneSearchEntries`.

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