Skip to content

fix(desktop): Select Linux secret storage backend#2916

Open
mwolson wants to merge 1 commit into
pingdotgg:mainfrom
mwolson:fix/linux-secret-store-backend-v2
Open

fix(desktop): Select Linux secret storage backend#2916
mwolson wants to merge 1 commit into
pingdotgg:mainfrom
mwolson:fix/linux-secret-store-backend-v2

Conversation

@mwolson

@mwolson mwolson commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #2539.
Closes #2880.

This selects an encrypted Linux safeStorage backend before Electron is ready, so desktop SSH environment credentials can be persisted on Linux sessions Electron does not recognize automatically.

Problem and Fix

Problem and Why it Happened Fix
Electron 41 can fall back to basic_text on Linux sessions such as Niri or unversioned KDE/Plasma because the desktop name is not one of Electron's recognized backend selectors. Resolve a Linux password-store switch before app.ready and default unknown non-KDE sessions to gnome-libsecret, while using KWallet for KDE/Plasma sessions.
The desktop app did not have a pre-ready settings path for a user-selected Linux password-store override. Read the persisted linuxPasswordStore setting synchronously during early Electron startup, with unsupported values normalized to auto without dropping unrelated settings.
AppImage sessions can start without the session bus and desktop environment variables needed by Linux secret stores. Hydrate Linux session environment values from the login shell before re-resolving the runtime password-store switch.

Defensive Fixes

Problem and Why it Happened Fix
The desktop file protocol scheme registration was Effect-scoped, but Electron requires privileged scheme registration before ready. Sequence scheme privilege registration and pre-ready command-line switch setup before the broader desktop runtime layer can build.
Safe-storage failures were hard to diagnose on Linux. Log the configured password-store decision before ready and the selected backend after ready, without probing keyring availability during startup.

Application Startup Sequence

Before this change, main.ts only serialized scheme privilege registration before the broader runtime:

DesktopApp.program
  |
  v
ElectronProtocol.layerSchemePrivileges
  |
  |  serial barrier: scheme privileges registered first
  v
rest of desktop runtime

After this change, main.ts also requires the pre-ready command-line switch work to finish before the broader runtime:

DesktopApp.program
  |
  v
desktopElectronPreReadyLayer
  |
  +-- ElectronProtocol.layerSchemePrivileges
  +-- configureElectronBeforeReady
        |
        +-- read existing --password-store
        +-- read early Linux settings
        +-- append pre-ready command-line switches
        +-- provide DesktopPreReadyElectronOptions
  |
  |  serial barrier: all pre-ready setup completes before broader runtime
  v
rest of desktop runtime

Validation

  • bun fmt
  • bun lint
  • bun typecheck
  • bun run --filter @t3tools/desktop test -- linuxSecretStorage DesktopEarlyElectronStartup DesktopAppSettings DesktopShellEnvironment DesktopSavedEnvironments

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes: N/A, desktop startup and persistence behavior
  • I included a video for animation/interaction changes: N/A

Note

Medium Risk
Touches credential encryption and early Electron bootstrap on Linux; wrong backend or switch timing could still break secret persistence, but CLI overrides are respected and changes are covered by targeted tests.

Overview
Linux desktop now picks Electron safeStorage / --password-store before app.ready, so encrypted credentials work on sessions Electron does not auto-detect (e.g. Niri, unversioned KDE).

Startup is split into a pre-ready layer (main.ts): privileged scheme registration plus synchronous reads of desktop-settings.json for linuxPasswordStore, WM class, and optional --password-store (skipped when the user already passed --password-store on the CLI). After login-shell env hydration, DesktopApp can remove/re-apply password-store from persisted settings and logs the chosen backend before/after ready.

New linuxSecretStorage heuristics map autognome-libsecret or kwallet from desktop env vars; DesktopAppSettings persists linuxPasswordStore (default auto, invalid values normalized). DesktopShellEnvironment pulls more Linux session vars (including DBUS_SESSION_BUS_ADDRESS fallback via /run/user/$UID/bus). ElectronApp gains removeCommandLineSwitch; ElectronSafeStorage exposes selectedStorageBackend on Linux for diagnostics.

Reviewed by Cursor Bugbot for commit e9f8d2e. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Select Linux secret storage backend via pre-ready Electron command-line configuration

  • Adds resolveEarlyLinuxElectronOptions to compute the password-store and wmClass command-line switches before Electron is ready, by reading desktop-settings.json synchronously from the resolved state directory.
  • Introduces a linuxPasswordStore setting (default 'auto') to DesktopSettings, persisted and normalized via normalizeLinuxPasswordStorePreference.
  • Adds resolveLinuxPasswordStoreSwitch heuristic to choose between kwallet, gnome-libsecret, or no override depending on the detected desktop environment and user preference.
  • Extends ElectronApp with removeCommandLineSwitch and ElectronSafeStorage with selectedStorageBackend (Linux only) to support runtime inspection and reconfiguration.
  • Expands POSIX environment propagation in DesktopShellEnvironment to include XDG/Wayland/D-Bus variables, and auto-infers DBUS_SESSION_BUS_ADDRESS on Linux when unset.
  • Behavioral Change: the password-store command-line switch is now removed and re-applied on each startup based on resolved settings, overriding any previously set value unless already specified via CLI.

Macroscope summarized e9f8d2e.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0098132c-2baa-4079-a108-6bf94125c558

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 2, 2026
Comment thread apps/desktop/src/app/DesktopApp.ts
@macroscopeapp

macroscopeapp Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new Linux feature for secret storage backend selection, including new settings, desktop environment detection heuristics, D-Bus integration, and changes to Electron initialization. The scope and behavioral impact warrant human review despite the 'fix' prefix.

You can customize Macroscope's approvability policy. Learn more.

@mwolson mwolson marked this pull request as draft June 3, 2026 01:56
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch 3 times, most recently from 1ec83f0 to 57dcaa9 Compare June 3, 2026 14:00
@mwolson mwolson marked this pull request as ready for review June 3, 2026 14:37
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch from 57dcaa9 to 9bf124e Compare June 3, 2026 14:41
Comment thread apps/desktop/src/main.ts Outdated
@mwolson mwolson marked this pull request as draft June 3, 2026 14:57
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch 7 times, most recently from c4ee8d6 to 5f02a0e Compare June 3, 2026 17:33
@mwolson mwolson marked this pull request as ready for review June 3, 2026 17:58
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch from 5f02a0e to a8ab180 Compare June 3, 2026 18:02
@juliusmarminge juliusmarminge force-pushed the fix/linux-secret-store-backend-v2 branch from a8ab180 to f38b824 Compare June 4, 2026 00:57
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch 4 times, most recently from f9c8c69 to 219f76d Compare June 11, 2026 13:35
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch from 219f76d to 7704609 Compare June 12, 2026 02:10

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7704609. Configure here.

Comment thread apps/desktop/src/app/DesktopEarlyElectronStartup.ts
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch from 7704609 to e9f8d2e Compare June 12, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

1 participant