Skip to content

feat: add --no-wildcard flag to coder config-ssh - #26753

Merged
BobbyHo merged 13 commits into
mainfrom
coder-17153-cli
Jun 30, 2026
Merged

BobbyHo merged 13 commits into
mainfrom
coder-17153-cli

Conversation

@BobbyHo

@BobbyHo BobbyHo commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator

Add --no-wildcard (CODER_CONFIGSSH_NO_WILDCARD) to coder config-ssh that generates an individual Host entry per workspace instead of a single wildcard block (Host *.coder).

The wildcard approach cannot be enumerated by third-party SSH clients, the VS Code Remote-SSH sidebar, or scripts that parse ~/.ssh/config to discover hosts. With --no-wildcard, each workspace gets its own entry so those tools work without Coder-specific extensions.

The flag is persisted in the config section header so re-running without it prompts the user about the option change. Workspaces are fetched with pagination before writing so the diff shows actual hostnames.

Manual testing

Unit tests (no server needed):

go test ./cli/ -run TestSSHConfigOptions_writeToBuffer -v
go test ./cli/ -run TestConfigSSH_NoWildcard -v

End-to-end with a dev server:

  1. Build: go build -o ./coder .
  2. Start dev server in a separate terminal: ./scripts/develop.sh
  3. Log in: ./coder login http://localhost:3000
  4. Create two workspaces
  5. Run both variants into temp files:
./coder config-ssh --no-wildcard --hostname-suffix coder --ssh-config-file /tmp/test-ssh-config --yes
./coder config-ssh --hostname-suffix coder --ssh-config-file /tmp/test-ssh-config-wildcard --yes
diff /tmp/test-ssh-config-wildcard /tmp/test-ssh-config
Output: --no-wildcard
# ------------START-CODER-----------
# This section is managed by coder. DO NOT EDIT.
#
# You should not hand-edit this section unless you are removing it, all
# changes will be lost when running "coder config-ssh".
#
# Last config-ssh options:
# :hostname-suffix=coder
# :no-wildcard=true
#
Host coder.myworkspace
    ConnectTimeout=0
    StrictHostKeyChecking=no
    UserKnownHostsFile=/dev/null
    LogLevel ERROR
    ProxyCommand <coder> --global-config <config> ssh --stdio --ssh-host-prefix coder. %h

Host coder.myworkspace2
    ConnectTimeout=0
    StrictHostKeyChecking=no
    UserKnownHostsFile=/dev/null
    LogLevel ERROR
    ProxyCommand <coder> --global-config <config> ssh --stdio --ssh-host-prefix coder. %h

Host myworkspace.coder
    ConnectTimeout=0
    StrictHostKeyChecking=no
    UserKnownHostsFile=/dev/null
    LogLevel ERROR

Match host myworkspace.coder !exec "<coder> connect exists %h"
    ProxyCommand <coder> --global-config <config> ssh --stdio --hostname-suffix coder %h

Host myworkspace2.coder
    ConnectTimeout=0
    StrictHostKeyChecking=no
    UserKnownHostsFile=/dev/null
    LogLevel ERROR

Match host myworkspace2.coder !exec "<coder> connect exists %h"
    ProxyCommand <coder> --global-config <config> ssh --stdio --hostname-suffix coder %h
# ------------END-CODER------------
Output: wildcard (default)
# ------------START-CODER-----------
# This section is managed by coder. DO NOT EDIT.
#
# You should not hand-edit this section unless you are removing it, all
# changes will be lost when running "coder config-ssh".
#
# Last config-ssh options:
# :hostname-suffix=coder
#
Host coder.*
    ConnectTimeout=0
    StrictHostKeyChecking=no
    UserKnownHostsFile=/dev/null
    LogLevel ERROR
    ProxyCommand <coder> --global-config <config> ssh --stdio --ssh-host-prefix coder. %h

Host *.coder
    ConnectTimeout=0
    StrictHostKeyChecking=no
    UserKnownHostsFile=/dev/null
    LogLevel ERROR

Match host *.coder !exec "<coder> connect exists %h"
    ProxyCommand <coder> --global-config <config> ssh --stdio --hostname-suffix coder %h
# ------------END-CODER------------
diff wildcard → --no-wildcard
8a9
> # :no-wildcard=true
10c11
< Host coder.*
---
> Host coder.myworkspace
17c18
< Host *.coder
---
> Host coder.myworkspace2
21a23
>     ProxyCommand <coder> ssh --stdio --ssh-host-prefix coder. %h
23c25,31
< Match host *.coder !exec "<coder> connect exists %h"
---
> Host myworkspace.coder
>     ConnectTimeout=0
>     StrictHostKeyChecking=no
>     UserKnownHostsFile=/dev/null
>     LogLevel ERROR
>
> Match host myworkspace.coder !exec "<coder> connect exists %h"

Closes #17153 (Phase 1: CLI flag)

Add --no-wildcard (CODER_CONFIGSSH_NO_WILDCARD) to coder config-ssh
that generates an individual Host entry per workspace instead of a
single wildcard block (Host *.coder).

The wildcard approach cannot be enumerated by third-party SSH clients,
the VS Code Remote-SSH sidebar, or scripts that parse ~/.ssh/config to
discover hosts. With --no-wildcard, each workspace gets its own entry
so those tools work without Coder-specific extensions.

The flag is persisted in the config section header so re-running without
it prompts the user about the option change. Workspaces are fetched with
pagination before writing so the diff shows actual hostnames.
@BobbyHo
BobbyHo marked this pull request as ready for review June 26, 2026 20:43
@coderagents

coderagents Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/user-guides/workspace-access/index.md - The SSH section mentions coder config-ssh but not --no-wildcard. Add a tip noting that users of third-party SSH clients (e.g., VS Code Remote-SSH sidebar, scripts parsing ~/.ssh/config) can use --no-wildcard to generate individual host entries that those tools can enumerate.
  • docs/user-guides/workspace-access/jetbrains/gateway.md - This page explicitly instructs users to check "Parse config file ~/.ssh/config" (line 167). A note about --no-wildcard would be relevant here since Gateway parses the config to discover hosts.

Automated review via Coder Agents

@github-actions

Copy link
Copy Markdown
Contributor

Docs preview

📖 View docs preview for docs/reference/cli/config-ssh.md

@BobbyHo BobbyHo changed the title feat(cli/configssh): add --no-wildcard flag to config-ssh feat: add --no-wildcard flag to coder config-ssh Jun 26, 2026

@johnstcn johnstcn left a comment

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.

Tried it out, and it works a treat. Some non-blocking comments below.

Comment thread cli/configssh_test.go Resolved
Comment thread cli/configssh_test.go Resolved
Comment thread cli/configssh.go Resolved
BobbyHo and others added 4 commits June 30, 2026 07:31
Pre-seed workspace and agent names in reverse lexical order so the test
proves entries are sorted by name rather than by creation order. Also
run the command a second time and verify the host-entry order is stable
across runs.
Replace scattered require.Contains and index comparisons with a single
cmp.Diff assertion against the complete, ordered list of expected Host
entries. With stable workspace names the full list is predictable, so
this gives a clearer failure diff when something changes. Apply the same
cmp.Diff style to the stability (second-run) check.
…uffer

The function has grown complex enough with manual buf.WriteString and
fmt.Fprintf calls that a text/template rewrite would improve readability.
@BobbyHo

BobbyHo commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you @johnstcn for reviewing this PR. I’ve updated configssh_test.go based on your suggestions. Would you mind taking another quick look when you have a moment? Thanks!

BobbyHo and others added 2 commits June 30, 2026 08:28
Move go-cmp into the same import group as testify and align inline
comments in the wantHosts slice to satisfy goimports formatting.
@BobbyHo
BobbyHo requested a review from johnstcn June 30, 2026 19:20
Comment thread cli/configssh.go Resolved
@BobbyHo
BobbyHo merged commit dcb120d into main Jun 30, 2026
32 of 33 checks passed
@BobbyHo
BobbyHo deleted the coder-17153-cli branch June 30, 2026 20:02
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 30, 2026
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.

A flag to NOT use a wildcard in the ssh config

2 participants