Skip to content

fix(desktop): use the mock keychain in the development sandbox - #39

Merged
wolfiesch merged 2 commits into
mainfrom
fix/desktop-dev-sandbox-keychain
Jul 25, 2026
Merged

fix(desktop): use the mock keychain in the development sandbox#39
wolfiesch merged 2 commits into
mainfrom
fix/desktop-dev-sandbox-keychain

Conversation

@wolfiesch

Copy link
Copy Markdown
Owner

What

main.ts now routes sandbox startup through one helper, applyDevelopmentSandbox, which keeps the existing userData redirect and additionally appends Chromium's --use-mock-keychain on macOS.

Why

The development sandbox redirects HOME, and macOS resolves the default keychain from $HOME. The sandbox home has no keychain, so Electron safeStorage cannot store its <product> Key item and securityd raises a modal on every launch:

A keychain cannot be found to store “Electron Key.”

The modal is the visible half. After dismissing it, safeStorage.isEncryptionAvailable() is false, so lifecycle.ts skips DeviceCredentialStore entirely and stores.ts reports the projection cache as unavailable. Every sandbox session was therefore dogfooding the degraded path, with pairing credentials and projection cache persistence silently absent.

Evidence for the cause:

  • HOME=$(mktemp -d) security default-keychain fails with SecKeychainCopyDefault: A default keychain could not be found., so keychain resolution follows the redirected HOME.
  • The item label is derived from the product name, which is Electron for an unpackaged run, and security find-generic-password -l "Electron Key" finds no such item in the login keychain: the key was never stored.

Testing

  • Isolated Electron 41.5.0 launched against a sandbox HOME: with the switch appended at module scope, isEncryptionAvailable() is true and encryptString/decryptString round trips; without it, false.
  • Built dist-electron/main.cjs launched with real T4_DEV_SANDBOX and T4_DEV_SANDBOX_ROOT: the app reaches window creation and writes device-credentials.json and projection-cache.json under the sandbox user data, which is only reachable when encryption is available.
  • @t4-code/desktop: 195 pass, including three new cases covering macOS, non-macOS, and no sandbox.
  • tsgo --noEmit and vp lint --deny-warnings clean.

Scope

Development sandbox only, gated on developmentSandboxServiceConfig(). Plain pnpm dev, packaged builds, and non-macOS platforms are unchanged; the switch is a macOS-only Chromium switch. Sandbox ciphertext is mock-key material and is not portable to a real login keychain, which docs/DEVELOPMENT.md now states alongside the instruction to verify real keychain behavior with a packaged build.

The sandbox redirects HOME, and macOS resolves the default keychain from
HOME, so safeStorage could not store its key. securityd raised a modal on
every launch and the app then ran with no credential store and no
projection cache. Start the sandboxed app with Chromium's mock keychain on
macOS so those paths stay exercised.
@wolfiesch
wolfiesch marked this pull request as draft July 25, 2026 08:12
@wolfiesch
wolfiesch marked this pull request as ready for review July 25, 2026 08:12

@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: 2cb13c7967

ℹ️ 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 apps/desktop/src/main.ts
pnpm dogfood:mac launches the packaged app with sandboxEnvironment, so it
runs with the same redirected HOME and inherits the mock keychain. The
previous note implied a packaged build verifies real keychain behavior,
which only holds for a launch outside any sandbox.
@wolfiesch
wolfiesch merged commit dcb1946 into main Jul 25, 2026
11 checks passed
@wolfiesch
wolfiesch deleted the fix/desktop-dev-sandbox-keychain branch July 25, 2026 08:23
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