Skip to content

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

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

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
Copy link
Copy Markdown
Contributor

@mwolson mwolson commented Jun 2, 2026

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 and fall back to /run/user/<uid>/bus when the DBus session bus exists but is not exported.

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. Expose and call a synchronous scheme privilege registration helper during process bootstrap.
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.

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

High Risk
Changes how Linux chooses Electron's encrypted credential backend at startup (DBus, password-store switches, and auto heuristics), which can affect whether existing users can read or write saved SSH secrets until they adjust keyring/KWallet setup.

Overview
Configures Linux desktop startup so Electron picks an encrypted safeStorage backend before app.ready, fixing SSH environment credential persistence on sessions Electron does not recognize (e.g. Niri, unversioned KDE).

Adds a persisted linuxPasswordStore setting (default auto) and reads it synchronously from desktop-settings.json during early bootstrap, alongside heuristics that map auto to gnome-libsecret or KWallet when needed. main.ts now applies Linux pre-ready switches (password-store, WM class, optional DBUS_SESSION_BUS_ADDRESS) and registers the desktop scheme privileges synchronously; DesktopApp can clear and re-apply password-store after login-shell hydration and logs the chosen store and selected backend after ready.

DesktopShellEnvironment pulls more session variables from the login shell and falls back to /run/user/<uid>/bus when DBus is unset. Supporting pieces include removeCommandLineSwitch, selectedStorageBackend on safe storage, shared path helpers, and targeted tests.

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

Note

Select Linux secret storage backend before Electron app ready

  • Reads a linuxPasswordStore setting (defaulting to 'auto') from desktop settings and resolves the appropriate Electron --password-store command-line switch before the app is ready.
  • Adds heuristics in linuxSecretStorage.ts to select the correct backend based on the active desktop environment when set to 'auto'.
  • Automatically detects and sets DBUS_SESSION_BUS_ADDRESS if unset and the default bus socket is found, and propagates additional session env vars (DISPLAY, XDG_CURRENT_DESKTOP, WAYLAND_DISPLAY, etc.) from the login shell on Linux.
  • Exposes ElectronApp.removeCommandLineSwitch and ElectronSafeStorage.selectedStorageBackend (Linux only, returns Option.none on non-Linux or error) to support runtime switch management and backend introspection.
  • Behavioral Change: Electron command-line switches (--class, --password-store) and protocol scheme privileges are now registered synchronously before app.ready instead of after.

Macroscope summarized 9bf124e. (Automatic summaries will resume when PR exits draft mode or review begins).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

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: e4871060-c04a-4328-a4fa-8f7b229d33d9

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
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Jun 2, 2026

Approvability

Verdict: Needs human review

This PR introduces new Linux secret storage backend selection functionality, which touches security-sensitive credential storage handling. Additionally, there's an unresolved review comment identifying a potential issue with DBUS session bus address handling that could affect secret-store backends.

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
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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 9bf124e. Configure here.

Comment thread apps/desktop/src/main.ts Outdated
if (linux !== null) {
if (linux.dbusSessionBusAddress !== null) {
process.env.DBUS_SESSION_BUS_ADDRESS = linux.dbusSessionBusAddress;
}
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.

Early DBUS blocks shell address

Medium Severity

During pre-ready Linux setup, a fallback DBUS_SESSION_BUS_ADDRESS is written when the default session socket exists. Later login-shell hydration only copies DBUS_SESSION_BUS_ADDRESS when it is unset, so an AppImage session that already got the fallback can never pick up a different address from the login shell, which can break secret-store backends that need the real session bus.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9bf124e. Configure here.

@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 from 9bf124e to f8925a5 Compare June 3, 2026 15:04
@mwolson mwolson force-pushed the fix/linux-secret-store-backend-v2 branch from f8925a5 to 19b1afe Compare June 3, 2026 16:02
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