Repository navigation
Description
I would like to propose that we configure SSH with a wildcard instead of individual host names. For example:
coder.*
ProxyCommand coder %h
And in ssh.go we trim out the coder. prefix.
Mainly, this is to support the IDEs. VS Code already does this with a special vscodessh sub-command but I think we should roll that up into ssh, then JetBrains can also benefit.
The main reason is that the IDEs support connecting to anyone's workspace (for admins). That means potentially hundreds of SSH config entries, and potentially hundreds of calls to template resources, since that has to be done for every workspace, at least the ones that are off, to get the agent names.
It would eventually remove the need for the Gateway and VS Code plugins to implement their own versions of config-ssh as they currently do, but this would need one more tweak to include the deployment URL in the host (for example coder-vscode.dev.coder.com--* is generated by the VS Code plugin).
It would eliminate the resource fetch loop in config-ssh as well.
As one data point, I tested with 138 off workspaces and configuring SSH took 20 seconds.
Alternatives:
- A separate
idesshsub-command that does this, maybe just renamevscodesshand add a deprecated alias, but I believe it also has some VS Code-specific logic that would need to be figured out. - Gate it behind flags (
config-ssh --wildcardandssh --wildcardor some such). - Skip changing
config-sshfor now, and addssh --strip-prefix=coder-vscode.dev.coder.com--or some such flag to at least allow the IDEs to configure their own wildcard host. - From the IDEs, we could instead do some inline shell magic to strip out the prefix, but I am not sure what Windows support looks like.
coder-vscode.dev.coder.com--*
ProxyCommand coder $(echo "%h" | sed 's/coder-vscode.dev.coder.com--//')
Edit: I presented the prefix flag as an alternative, but actually no matter what we will need a prefix flag for ssh because we want unique hosts for the plugins so they can add different SSH configuration if necessary (for example the session type env var, although that is deprecated). I also learned that config-ssh already has an ssh-prefix-host flag, so it makes sense to add that same flag to ssh. Then we can use ProxyCommand coder ssh --ssh-prefix-host coder-gateway.dev.coder.com. %h and emit a single wildcard entry in the plugins.
I think we should still eventually change config-ssh to use wildcards, and switch the plugins to use config-ssh instead of replicating that effort, but that can be done later.
Activity
code-asher commentedon Oct 4, 2024
Another alternative that at least partially works around the slowness, in JetBrains we could only add hosts to the config for the currently connected workspace and any in the recent connections, instead of blindly adding every single one. A wildcard would be nice but maybe this could be a temporary bandaid.
code-asher commentedon Oct 4, 2024
Or, if we actually parse the host names, we can more smartly update the config and only make requests for workspaces that are new. Currently we interact with the config as one big block, so we have to update the whole thing at once as we have no knowledge of what might need to be added.
I think wildcard would still be nice, but if we decide to take one of these other routes I will create an issue in the JetBrains repo instead and close this one.
code-asher commentedon Oct 4, 2024
Another alternative, if the main workspaces query included all the agents even for off workspaces, this would at least make it faster probably, giant SSH config notwithstanding.
ammario commentedon Oct 5, 2024
I enjoy this idea and think we should strive for one opinionated method for SSH configuration. The one drawback to wildcards (which might be a worthwhile cost) is users lose autocomplete when typing
ssh coder.<TAB>.code-asher commentedon Oct 15, 2024
Great point, I had not considered that. Hmmm maybe we can provide completions to compensate (
coder ssh --completionsor something, idk if there is some standard flag folks tend to use, but then this would be placed in/etc/bash_completionsor wherever). 🤔ammario commentedon Oct 15, 2024
Ideally we would keep all completions coming in through
coder completion.code-asher commentedon Oct 15, 2024
Oof 🤦 I missed that. Yup, makes sense.
Emyrk commentedon Oct 23, 2024
Is there a way to do dynamic completions? Like can the autocomplete do a
coder lsand pull from that list?code-asher commentedon Oct 29, 2024
Yup, it can be shell-dependent, but with Bash for example you can generate completions with:
In use:
We may also need to read the SSH config to get other hosts, since it looks like this replaces completions rather than augments them. 🤔 Edit: in my workspace,
sshis not completing host names by default anyway...We could make the workspace list static to avoid an API call every time you
TAB, that would be equivalent to how it works today. Or only make the calls when you have typed thecoder.prefix.ethanndickson commentedon Oct 30, 2024
Yep, you can override the completion handler in serpent to do it all without touching any shell :)
code-asher commentedon Oct 30, 2024
Can it do it for a different command though or does it only work for itself? (Since we want completions for the regular
sshcommand.) Or will we have to generate those completions ourselves?2 remaining items
code-asher commentedon Nov 1, 2024
Unassigned from myself for now due to time constraints, if this gets reassigned and it is not me then please let me know, happy to chat with whoever gets it to make sure my thoughts came across correctly, and I want to make sure whatever comes out is usable for the plugins.
ethanndickson commentedon Nov 2, 2024
ahh yeah I see, my bad!
feat: parse structured hostname arguments to "coder ssh"
matifali commentedon Jan 10, 2025
@spikecurtis will this functionality change how Coder Desktop works?
spikecurtis commentedon Jan 10, 2025
With Coder Desktop, it won't be necessary to use the
coderCLI binary to create the tunnel to your workspace.However, CoderVPN uses
.coderas a suffix to host names, not a prefix like our SSH config. So, we should start the work to migrate our ssh configuration to follow this pattern, since it tracks the semantic meaning of DNS order, and should avoid name collisions.feat: add --ssh-host-prefix flag for "coder ssh" (#16088)
matifali commentedon Mar 12, 2025
@bcpeinhardt, Can you help me decide if it's not already done? Thanks.
bcpeinhardt commentedon Mar 12, 2025
@matifali I would say the title of the issue (use wildcard SSH host names) is complete in 2.19 of Coder, but there's other work present in the comments worth looking at (mainly Spikes point about our current configuration not really following the semantics of DNS order). I wonder if we already have an issue for that 🤔
cc @code-asher
matifali commentedon Mar 12, 2025
Thanks @bcpeinhardt. Yes, for following the semantics of DNS, we now have #16828.
So, I am closing this as completed.
Also, tagging @ThomasK33 to have more context on why we are switching to a suffix.
octoxan commentedon Mar 20, 2025
This broke so many things for us. This should have been optional.
spikecurtis commentedon Mar 20, 2025
@octoxan Can you tell us any more information about what broke and how?
octoxan commentedon Mar 20, 2025
@spikecurtis There are many tools we use (Tabby, Tinkerwell, etc and various automations we've built) that give you an option to connect to different remotes by parsing your ~/.ssh/config. Before it was very easy to not have to maintain this list manually in every single app as the way Coder was doing it before worked universally across many tools.
Now when I go to start working on a project I need to manually add it to half a dozen different apps manually.
Also, this update made it so we have to delete every single workspace connection in the Jetbrains plugin and recreate them. It no longer connects to any saved workspaces that were added to Jetbrains Gateway prior to 2.19, which is a major pain when you have so many workspaces.
Here's Tinkerwell for one example of an app, which used to have a nice drop down of 100+ connections I could use automatically, and now this list needs manually added to and things removed all the time.
Some flag to not do the wildcard and do the verbose method would save all of us over here a great deal of time lol
fix: write agent host entries with `config-ssh --no-wildcard` (#31192)