Skip to content

Store session tokens in the OS keyring#808

Merged
EhabY merged 5 commits intomainfrom
add-keyring-support
Mar 4, 2026
Merged

Store session tokens in the OS keyring#808
EhabY merged 5 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
@EhabY EhabY force-pushed the add-keyring-support branch from f5ec9a3 to 45383e8 Compare February 25, 2026 23:21
@EhabY EhabY requested a review from zedkipp March 2, 2026 08:44
Copy link
Member

@ethanndickson ethanndickson left a comment

Choose a reason for hiding this comment

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

I gave this a quick sanity check on macOS since IIRC you don't have a mac and it worked great. The CLI was able to pickup the VS Code created credentials and vice-versa.
No blocking comments from me.

@EhabY EhabY force-pushed the add-keyring-support branch from 21481f3 to 60892cb Compare March 2, 2026 13:25
@EhabY EhabY force-pushed the add-keyring-support branch 2 times, most recently from 73b126c to 2c03884 Compare March 3, 2026 13:57
EhabY added 5 commits March 4, 2026 16:38
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 2c03884 to eb46d87 Compare March 4, 2026 13:38
@EhabY EhabY merged commit 80f0c0a into main Mar 4, 2026
6 checks passed
@EhabY EhabY deleted the add-keyring-support branch March 4, 2026 13:41
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.

4 participants