feat: support configurable CLI global config by EhabY · Pull Request #1011 · coder/vscode-coder · GitHub
Skip to content

feat: support configurable CLI global config#1011

Open
EhabY wants to merge 8 commits into
mainfrom
feat/global-config
Open

feat: support configurable CLI global config#1011
EhabY wants to merge 8 commits into
mainfrom
feat/global-config

Conversation

@EhabY

@EhabY EhabY commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds coder.globalConfig as a machine-scoped directory setting for the CLI --global-config path, with CODER_CONFIG_DIR fallback and existing per-deployment storage as the default.
  • Applies the resolved config directory consistently through PathResolver, CLI auth flags, credential file reads/writes/deletes, active remote reload prompts, and support bundle settings.
  • Preserves keyring precedence while allowing file-backed CLI credentials to be reused when keyring auth is not active.

Closes #185.

Testing

  • pnpm test:extension ./test/unit/cliConfig.test.ts ./test/unit/core/pathResolver.test.ts ./test/unit/core/cliCredentialManager.test.ts ./test/unit/login/loginCoordinator.test.ts ./test/unit/supportBundle/settings.test.ts
  • pnpm test
  • pnpm typecheck
  • pnpm lint
  • pnpm format:check
  • pnpm build
  • git diff --check

Generated by Coder Agents.

Implementation plan
  • Add a dedicated coder.globalConfig setting for a directory path and keep coder.globalFlags from overriding managed --global-config / --use-keyring flags.
  • Resolve global config path in PathResolver: coder.globalConfig first, then CODER_CONFIG_DIR, then the existing <globalStorage>/<safeHostname> default.
  • Preserve keyring precedence in CLI auth resolution; use --url for active supported keyring auth, otherwise --global-config <resolvedDir>.
  • Read file-backed CLI credentials from the resolved config directory when keyring auth is not active so CLI login can be shared with the extension.
  • Add reload prompt/support bundle handling for the setting.
  • Cover behavior with targeted unit tests for path resolution, CLI flags, credential manager, login fallback, and support bundle settings.

@EhabY EhabY self-assigned this Jun 17, 2026
@EhabY EhabY requested a review from code-asher June 17, 2026 12:46
Comment thread src/core/cliCredentialManager.ts Outdated
Comment thread src/core/cliCredentialManager.ts Outdated
Comment thread src/core/cliCredentialManager.ts Outdated
Comment thread src/core/pathResolver.ts Outdated
@EhabY EhabY requested a review from code-asher June 18, 2026 10:00
@EhabY EhabY force-pushed the feat/global-config branch 3 times, most recently from 9a72ccf to 6d03c00 Compare June 23, 2026 06:59
@EhabY

EhabY commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

@EhabY EhabY force-pushed the feat/global-config branch from 7e5d315 to 36cfde3 Compare June 24, 2026 09:48
EhabY and others added 5 commits June 25, 2026 12:47
Split src/util.ts into focused modules: src/util/uri.ts (toSafeHost,
removeTrailingSlashes, resolveUiUrl, openInBrowser) and
src/util/authority.ts (Remote SSH authority helpers), replacing
src/uri/utils.ts. Migrate all importers and mirror the unit tests.

Make CliCredentialManager.readToken return the token together with its
source ("keyring" | "files") so LoginCoordinator labels the login
method from the actual source instead of re-deriving it from whether
keyring is enabled.
…malization

- Add loginCoordinator test for the keyring_token method (source: "keyring")
- Add comprehensive toRemoteAuthority tests over varied URI types
- Test toSafeHost/normalizeUrl with Arabic alongside Japanese IDNs
- Consolidate the trim + strip-trailing-slashes logic into a shared
  normalizeUrl in util/uri, reused by resolveUiUrl and cliCredentialManager
Replace the dedicated `coder.globalConfig` setting with a `--global-config`
passthrough in `coder.globalFlags`, honored on 2.31.0+. The extension no longer
reads/writes the CLI credential files itself: it writes via `coder login`
(0.25.0+, `--use-token-as-session`), reads via `coder login token` (2.31.0+),
and deletes via `coder logout` (keyring or file with `--global-config`).
Direct file writes remain only as a pre-0.25 fallback. The binary cache no
longer follows the config dir.
@EhabY EhabY force-pushed the feat/global-config branch from 36cfde3 to b69b20b Compare June 25, 2026 09:47
EhabY added 2 commits June 25, 2026 13:43
- Bump the minimum supported deployment version to 0.25.0 (where `coder
  login` lives), gating on `featureSet.cliLogin`, and move the compatibility
  check before credential configuration so older servers get a clear message.
- Remove the pre-0.25 direct-file-write fallback; credential writes now always
  go through `coder login`. Drop the now-unused `vscodessh` feature flag and
  the dead `CredentialFileError` class plus its `filesystem`/`file` telemetry
  categories.
- Collapse the `resolveCli` overloads into one throwing resolver; the
  best-effort read path catches instead.
- Fix the stale `coder.globalConfig` CHANGELOG entry (the setting was dropped)
  and two pre-existing test typecheck breaks (`toSafeHost` import path and a
  `CliAuth.allowOverride` literal).
Routing file-mode credentials through `coder login`/`logout` means the
credential binary resolver now runs in the login and logout flows, not just on
connect. It previously fell back to `fetchBinary` on a cache miss, so a
file-mode user's login (including auto-login on startup) or logout could
trigger a surprise CLI download with a progress popup, where before it was
silent file I/O.

Make the resolver locate-only. The connect and CLI-command flows still fetch
the binary first, so credential ops become best-effort against an
already-present binary and never download on their own. If no binary exists
yet, credential sharing is simply skipped until a real connection fetches one.
Comment thread src/core/container.ts
Comment on lines +85 to +87
// Locate-only: never download from credential ops; the connect and
// CLI-command flows fetch the binary first.
return this.cliManager.locateBinary(url);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

locate-only means a keyring user with no binary yet won't get their terminal token picked up at first login until something fetches the binary (main would download for them). Keep it, or revert to download-on-demand?

I'm hesitant about downloading on login/logout because that doesn't seem very UX friendly

@code-asher code-asher Jun 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah I think this is good, if the binary is missing then there is no credential share/sync (yet) and that seems fair to me.

@code-asher code-asher Jun 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hrm I tested and I guess it could be a little weird for first time login because if you set a global config to share with a cli you already have downloaded and configured, it does not work because VS Code has not downloaded a binary yet.

@code-asher code-asher Jun 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which I think means the read feature will basically never be useful, because pretty much the one time you need to read the login is when you have never logged in before. 🤔 (I think??)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeaaah it's less useful now but consistent (CLI always does the action). It could be useful still if they login every day for example so they will have the CLI but the token will be taken from the CLI login

Comment thread src/settings/cli.ts Outdated
Comment on lines +56 to +61

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we not able to allow the override with the keyring?

Currently we happen to know the CLI only stores a url and token there, but this could change in the future. No harm in letting it be set, I think.

And to take it a bit further, IMO a config dir is better than --url because the user can run the CLI directly as well (like for example say we decide to expose it on PATH in the terminal or something so users can run commands directly).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because we have a setting coder.useKeyring, if we allow --global-config to pass through then this will result in hiding the user setting above. I am confused by the --url point though, like if we do not pass --global-config then the CLI defaults to keyring which is why we need to pass --url

Comment thread src/util/uri.ts Outdated
Comment thread src/util/uri.ts Outdated
Comment thread src/core/cliCredentialManager.ts Outdated
- rename FeatureSet.keyringTokenRead to tokenRead (token subcommand works for both stores)
- rename resolveUiUrl to resolveCoderDashboardUrl
- clarify openInBrowser docstring (connectionUrl is arbitrary)
- split buildGlobalFlags on auth mode to drop the nested ternary
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.

Add support for sharing login/auth between Coder CLI and VS Code extension

2 participants