Skip to content

fix: Use smarter quoting for ProxyCommand in config-ssh #3755

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 30, 2022

Conversation

mafredri
Copy link
Member

This change takes better into account how OpenSSH executes
ProxyCommands and applies quoting accordingly.

This supercedes #3664, which was reverted.

Fixes #2853


Bonus commit:

  • fix: Ensure ~/.ssh directory exists

This change takes better into account how OpenSSH executes
`ProxyCommand`s and applies quoting accordingly.

This supercedes #3664, which was reverted.

Fixes #2853
@mafredri mafredri self-assigned this Aug 30, 2022
@mafredri mafredri requested a review from a team August 30, 2022 15:44
cli/configssh.go Outdated
Comment on lines 530 to 547
func sshConfigExecEscape(path string) (string, error) {
// This is unlikely to ever happen, but newlines are allowed on
// certain filesystems, but cannot be used inside ssh config.
if strings.ContainsAny(path, "\n") {
return "", xerrors.Errorf("invalid path: %s", path)
}
// In the unlikely even that a path contains quotes, they must be
// escaped so that they are not interpreted as shell quotes.
if strings.Contains(path, "\"") {
path = strings.ReplaceAll(path, "\"", "\\\"")
}
// A space or a tab requires quoting, but tabs must not be escaped
// (\t) since OpenSSH interprets it as a literal \t, not a tab.
if strings.ContainsAny(path, " \t") {
path = fmt.Sprintf("\"%s\"", path)
}
return path, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

So --- and hear me out here 😳 --- could we test this by creating a hello-world batch or shell script (platform-dependent) under a temp path that contains a space, attempting to execute /bin/bash -c '<path of thing>', and validating that it executes successfully?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see why not, good idea! In theory, we'd want to test all the shells.. but then again, I think we're unlikely to run into that many edge cases with this unless people do really fringe stuff with their filesystems/folder structures. 😅

Copy link
Member

Choose a reason for hiding this comment

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

I think testing /bin/sh and/or cmd.exe is all we should do tbh

@mafredri mafredri force-pushed the mafredri/fix-coder-configssh-proxycmd-quoting branch from a5ae539 to 73e6a84 Compare August 30, 2022 16:54
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

🚀

@mafredri mafredri merged commit 1dc0485 into main Aug 30, 2022
@mafredri mafredri deleted the mafredri/fix-coder-configssh-proxycmd-quoting branch August 30, 2022 18:08
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.

Windows: ssh coder.workspace not working after running coder config-ssh
2 participants