Skip to content

Store session tokens in the OS keyring#808

Open
EhabY wants to merge 2 commits intomainfrom
add-keyring-support
Open

Store session tokens in the OS keyring#808
EhabY wants to merge 2 commits intomainfrom
add-keyring-support

Conversation

@EhabY
Copy link
Collaborator

@EhabY EhabY commented Feb 25, 2026

Summary

  • On macOS and Windows with CLI >= 2.29.0, store session tokens in the OS keyring (Keychain / Credential Manager) instead of plaintext files, matching the Coder CLI's native keyring support
  • Pass --url instead of --global-config so the CLI reads tokens from the keyring
  • Fall back to file storage (with 0o600 permissions) on Linux, older CLIs, or if the keyring write fails
  • Read tokens from the keyring at login time so credentials written by coder login in the terminal are picked up automatically

How it works

  • KeyringStore wraps @napi-rs/keyring using the exact credential format the CLI expects (JSON map keyed by host, base64 on macOS, raw UTF-8 bytes on Windows)
  • CliAuth discriminated union ("global-config" | "url") is threaded through proxy command building and the workspace state machine
  • shouldUseKeyring() gates on CLI version, platform, and coder.useKeyring setting
  • remote.ts setup() is restructured so configure() runs after the CLI feature set is known
  • vendor-keyring.mjs copies native binaries into dist/node_modules/ at build time for VSIX packaging (vsce can't follow pnpm symlinks)

@EhabY EhabY self-assigned this Feb 25, 2026
@EhabY EhabY force-pushed the add-keyring-support branch 3 times, most recently from bbe05fe to f5ec9a3 Compare February 25, 2026 14:08
@jdomeracki-coder jdomeracki-coder self-requested a review February 25, 2026 14:30
@ethanndickson ethanndickson self-requested a review February 25, 2026 15:50
On macOS and Windows with CLI >= 2.29.0, write session tokens to the OS
keyring (Keychain / Credential Manager) instead of plaintext files.
The CLI reads from the keyring when invoked with --url instead of
--global-config. Falls back to file storage on Linux, older CLIs,
or if the keyring write fails.

Key changes:
- Add KeyringStore wrapping @napi-rs/keyring with the CLI's credential
  format (JSON map keyed by host, base64 on macOS, raw bytes on Windows)
- Add CliAuth discriminated union ("global-config" | "url") threaded
  through proxy command building and workspace state machine
- Add shouldUseKeyring() as single source of truth gating on CLI version,
  platform, and coder.useKeyring setting
- Restructure remote.ts setup() to call configure() after featureSet is
  known, so the keyring decision can be made
- Add keyring read fallback in LoginCoordinator for tokens written by
  `coder login` from the terminal
- Add vendor-keyring.mjs build script to copy native binaries into
  dist/node_modules/ for VSIX packaging (vsce can't follow pnpm symlinks)
- Harden file fallback with mode 0o600
@EhabY EhabY force-pushed the add-keyring-support branch from f5ec9a3 to 45383e8 Compare February 25, 2026 23:21
Comment on lines +35 to +40
const nativePackages = [
"keyring-darwin-arm64",
"keyring-darwin-x64",
"keyring-win32-arm64-msvc",
"keyring-win32-x64-msvc",
];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To make a universal VSIX, we have to package all of these (x64 and arm64 for macOS and Windows). Potentially we can split this into separate VSIXs (esp. when we have linux which has even more).

The universal VSIX went from 1.02MB to 1.80MB. Almost doubled but still acceptable IMO

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