Skip to content

feat: honor --use-keyring together with --global-config - #32392

Merged
EhabY merged 1 commit into
mainfrom
feat/cli-1-keyring-with-global-config
Nov 20, 2026
Merged

EhabY merged 1 commit into
mainfrom
feat/cli-1-keyring-with-global-config

Conversation

@EhabY

@EhabY EhabY commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

An explicit --use-keyring flag or CODER_USE_KEYRING value now picks where the session token is stored, even when --global-config points at a custom directory. Previously a custom --global-config always forced file storage, and --use-keyring=true was silently ignored.

When --use-keyring is left at its default, a custom --global-config still uses <global-config>/session, so existing callers that rely on that file keep working.

--global-config --use-keyring Storage (macOS/Windows)
default unset keyring
custom unset file (unchanged)
custom true (flag or env) keyring (new)
any false file

Linux and other platforms keep using file storage.

The test-only RootCmd.UseKeyringWithGlobalConfig() override and the duplicate clitest.NewWithDefaultKeyringCommand helper are removed; cli/keyring_test.go is now one table-driven test over a shared server that covers unset, flag, env, and false values. Each case checks that login stores a working token in exactly one backend, coder login token reads it back, and logout removes it.

Closes #29105. Per-caller keyring namespaces (the second half of the issue) are tracked separately in CLI-83.

Implementation plan and decisions

Selection rule (ensureTokenBackend in cli/root.go):

  1. Keyring unsupported on this OS: file.
  2. --use-keyring set by flag or CODER_USE_KEYRING: use that value.
  3. Otherwise: file when --global-config is not the default directory, keyring otherwise.

"Set explicitly" means CODER_USE_KEYRING is present in the environment or the leaf command's parsed flags report use-keyring as changed. Serpent applies defaults through Value.Set, so the value itself cannot tell a default from an explicit setting.

Why keep the file default for a custom --global-config: CLI-1 requires existing callers to be unaffected unless they opt in. vscode-coder and JetBrains Toolbox already pass --use-keyring explicitly, but older extension versions and scripts may pass only --global-config and read <dir>/session.

Keyring keys: unchanged. All callers still share the coder-v2-credentials entry (keyed by host for https, full origin for http), so a keyring login with a custom --global-config shares its token with Coder Desktop and Toolbox.

Deferred to CLI-83: opt-in --keyring-namespace persisted in <global-config>/keyring-namespace, so callers can hold independent tokens without passing the namespace every time. Deriving the namespace from the config path was rejected (orphaned entries, breaks on move or rename, leaks paths into the keyring UI).

Verification:

  • go test ./cli/... passes on Linux. Keyring-backed expectations in TestUseKeyring are exercised on macOS and Windows CI.
  • With keyring support forced on locally: Flag and Env select the keyring, Unset/FlagFalse/EnvFalse select the file, and removing the default-file fallback makes Unset fail.
  • Manual check on Linux with keyring support forced on: a custom dir with no flag uses the file; --use-keyring before or after the subcommand, and CODER_USE_KEYRING=true, select the keyring; --use-keyring=false uses the file.
  • golangci-lint clean for linux, darwin, and windows; help goldens and docs/reference/cli/index.md regenerated.

Generated by Coder Agents on behalf of @EhabY.

@linear-code

linear-code Bot commented Nov 18, 2026

Copy link
Copy Markdown

CLI-1

An explicit --use-keyring flag or CODER_USE_KEYRING value now selects the
keyring backend even when --global-config points at a custom directory.
When --use-keyring is left at its default, a custom --global-config still
selects file storage so existing callers keep finding <dir>/session.

Removes the test-only RootCmd.UseKeyringWithGlobalConfig override and the
duplicate clitest.NewWithDefaultKeyringCommand helper.

Refs CLI-1, #29105
@EhabY
EhabY force-pushed the feat/cli-1-keyring-with-global-config branch from e5fe4b2 to 557d1ab Compare November 19, 2026 10:52
@EhabY
EhabY requested a review from a team November 19, 2026 22:02
@EhabY
EhabY merged commit d807abc into main Nov 20, 2026
37 of 38 checks passed
@EhabY
EhabY deleted the feat/cli-1-keyring-with-global-config branch November 20, 2026 16:02
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 2026

This branch had an error being deployed

1 failed and 1 inactive deployments
main — 557d1abf Deployed Nov 20, 2026 by EhabY via cla #261312
docs-preview — 557d1abf Deployed Nov 20, 2026 by EhabY via cleanup #284
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): allow keyring session token storage together with --global-config

2 participants