Skip to content

Use wildcard SSH host names #14986

Closed
Closed

Description

@code-asher

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 idessh sub-command that does this, maybe just rename vscodessh and 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 --wildcard and ssh --wildcard or some such).
  • Skip changing config-ssh for now, and add ssh --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

  1. code-asher commented on Oct 4, 2024

    @code-asher
    MemberAuthor

    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.

  2. code-asher commented on Oct 4, 2024

    @code-asher
    MemberAuthor

    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.

  3. self-assigned this
    on Oct 4, 2024
  4. code-asher commented on Oct 4, 2024

    @code-asher
    MemberAuthor

    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.

  5. ammario commented on Oct 5, 2024

    @ammario
    Member

    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>.

  6. code-asher commented on Oct 15, 2024

    @code-asher
    MemberAuthor

    Great point, I had not considered that. Hmmm maybe we can provide completions to compensate (coder ssh --completions or something, idk if there is some standard flag folks tend to use, but then this would be placed in /etc/bash_completions or wherever). 🤔

  7. ammario commented on Oct 15, 2024

    @ammario
    Member

    Ideally we would keep all completions coming in through coder completion.

  8. code-asher commented on Oct 15, 2024

    @code-asher
    MemberAuthor

    Oof 🤦 I missed that. Yup, makes sense.

  9. Emyrk commented on Oct 23, 2024

    @Emyrk
    Member

    Is there a way to do dynamic completions? Like can the autocomplete do a coder ls and pull from that list?

  10. code-asher commented on Oct 29, 2024

    @code-asher
    MemberAuthor

    Yup, it can be shell-dependent, but with Bash for example you can generate completions with:

    _ssh() 
    {
        local cur opts
        cur="${COMP_WORDS[COMP_CWORD]}"
        opts=$(coder ls --column workspace | tail -n +2)
        COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
        return 0
    }
    complete -F _ssh ssh

    In use:

    coder@dev27:~/coder$ ssh code-asher/
    code-asher/dev27           code-asher/dev31           code-asher/not-nix         code-asher/projector-test  code-asher/scala           code-asher/test
    

    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, ssh is 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 the coder. prefix.

  11. ethanndickson commented on Oct 30, 2024

    @ethanndickson
    Member

    Is there a way to do dynamic completions? Like can the autocomplete do a coder ls and pull from that list?

    Yep, you can override the completion handler in serpent to do it all without touching any shell :)

  12. code-asher commented on Oct 30, 2024

    @code-asher
    MemberAuthor

    Can it do it for a different command though or does it only work for itself? (Since we want completions for the regular ssh command.) Or will we have to generate those completions ourselves?

  13. 2 remaining items

  14. removed their assignment
    on Nov 1, 2024
  15. code-asher commented on Nov 1, 2024

    @code-asher
    MemberAuthor

    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.

  16. ethanndickson commented on Nov 2, 2024

    @ethanndickson
    Member

    ahh yeah I see, my bad!

  17. matifali commented on Jan 10, 2025

    @matifali
    Contributor

    @spikecurtis will this functionality change how Coder Desktop works?

  18. spikecurtis commented on Jan 10, 2025

    @spikecurtis
    Collaborator

    @spikecurtis will this functionality change how Coder Desktop works?

    With Coder Desktop, it won't be necessary to use the coder CLI binary to create the tunnel to your workspace.

    However, CoderVPN uses .coder as 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.

  19. matifali commented on Mar 12, 2025

    @matifali
    Contributor

    @bcpeinhardt, Can you help me decide if it's not already done? Thanks.

  20. bcpeinhardt commented on Mar 12, 2025

    @bcpeinhardt
    Contributor

    @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

  21. matifali commented on Mar 12, 2025

    @matifali
    Contributor

    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.

  22. octoxan commented on Mar 20, 2025

    @octoxan

    This broke so many things for us. This should have been optional.

  23. spikecurtis commented on Mar 20, 2025

    @spikecurtis
    Collaborator

    @octoxan Can you tell us any more information about what broke and how?

  24. octoxan commented on Mar 20, 2025

    @octoxan

    @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.

    Image

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    networking

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions