Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Refactor CLI config-ssh to Include configurations#1848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mafredri wants to merge1 commit intomainfrommafredri/ssh-config-refactor

Conversation

mafredri
Copy link
Member

WIP: This PR refactorscoder config-ssh to useInclude instead of block management, according to the proposal in#1326.

This is a quick Friday hack to prototype the experience, a lot of TODOs and cleanups remaining.

First run:

❯ coder config-ssh> The following line will be added to /home/maf/.ssh/config:    Include coder.d/host-*  And configuration files will be stored in ~/.ssh/coder.d  Continue? (yes/no) yes* Added Include directive to /home/maf/.ssh/config* Created configuration directory /home/maf/.ssh/coder.d* Created workspace configurations in /home/maf/.ssh/coder.dYou should now be able to ssh into your workspace.For example, try running:        $ ssh coder.work

SSH config contents:

❯ cat ~/.ssh/configHost github.com        HostName github.com        User gitInclude coder.d/host-*

Workspace config (each as separate files for more flexibility):

❯ cat ~/.ssh/coder.d/host-workHost coder.work        HostName coder.work        ConnectTimeout=0        StrictHostKeyChecking=no        UserKnownHostsFile=/dev/null        LogLevel ERROR        ProxyCommand "coder" --global-config "/home/maf/.config/coderv2" ssh --stdio work

Re-running the command:

❯ coder config-ssh* Created workspace configurations in /home/maf/.ssh/coder.dYou should now be able to ssh into your workspace.For example, try running:        $ ssh coder.work

// to manage other files in this folder as well, e.g. keys, vscode
// specific config (i.e. for only listing coder files in vscode),
// etc.
sshEnabledLine = "Include coder.d/host-*"
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to prefer multiple configurations over a single, larger one?

e.g.~/.ssh/coder

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I did have some thoughts in mind, one was to store a hash in the config file so we can detect user modifications and prompt to overwrite. Another is for the user to be able to include specific hosts into their config (example):

~/.ssh/vscode-ssh-config:

Include coder.d/host-ws1Include coder.d/host-ws2

In Code you could then set"remote.SSH.configFile": "~/.ssh/vscode-ssh-config".

Comment on lines +80 to +103
err = func() error {
exists := true
configRaw, err := os.Open(sshConfigFile)
if err != nil && !xerrors.Is(err, fs.ErrNotExist) {
return err
} else if xerrors.Is(err, fs.ErrNotExist) {
exists = false
}
defer configRaw.Close()

if exists {
s := bufio.NewScanner(configRaw)
for s.Scan() {
if strings.HasPrefix(s.Text(), sshEnabledLine) {
enabled = true
break
}
}
if s.Err() != nil {
return err
}
}
return nil
}()
Copy link
Member

Choose a reason for hiding this comment

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

🤔 make it its own func, perhaps?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Will do 👍🏻! (Lots of cleanup left to do here.)

Comment on lines -24 to +33
# To remove this blob, run:
#
# coder config-ssh --remove
#
# You should not hand-edit this section, unless you are deleting it.`
const sshEndToken = "# ------------END-CODER------------"
const (
// Include path is relative to `~/.ssh` and each workspace will
// have a separate file (e.g. `~/.ssh/coder.d/host-my-workspace`).
// By prefixing hosts as `host-` we give ourselves the flexibility
// to manage other files in this folder as well, e.g. keys, vscode
// specific config (i.e. for only listing coder files in vscode),
// etc.
sshEnabledLine = "Include coder.d/host-*"
// TODO(mafredri): Does this hold on Windows?
sshCoderConfigd = "~/.ssh/coder.d"
// TODO(mafredri): Write a README to the folder?
// sshCoderConfigdReadme = `Information, tricks, removal, etc.`
Copy link
Member

Choose a reason for hiding this comment

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

What kind of migration path will this have for users?
Will they have to remove the existing section of their ssh-configs?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Unfortunately, yes. The idea was originally that we'd get this changed early enough for that not to be a problem. But if it is, we can add a cleanup function (I'd have left it in but it wasn't implemented yet 😄.)

@mafredri
Copy link
MemberAuthor

This PR is replaced by a proper refactor in#1900.

@mafredrimafredri deleted the mafredri/ssh-config-refactor branchMay 30, 2022 15:03
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@johnstcnjohnstcnjohnstcn left review comments

@kylecarbskylecarbskylecarbs left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@mafredri@johnstcn@kylecarbs

[8]ページ先頭

©2009-2025 Movatter.jp