-
Notifications
You must be signed in to change notification settings - Fork 905
fix: config-ssh panic when ssh config is malformed #5859
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
Conversation
I somehow ended up with a `~/.ssh/config` file that had an `END-CODER` token before `START-CODER` (probably a bad edit on my side). This causes `coder config-ssh` to panic. Fix this panic by simplifying and combining `sshConfigGetCoderSection` and `sshConfigSplitOnCoderSection` to look for the tokens in order with `bytes.Cut`.
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request |
Thanks for the fix @aaronlehmann 🥳 |
This is a good find, and we should handle this more gracefully. What should the behavior be 🤔? This does fix the panic, but introduces the possibility of removing lines not added by Coder. If the headers are out of order:
The result is this:
Which if I feed back in as input, the first
I think if we detect these are out of order, we should maybe just return a message to the user that their ssh config is malformed and needs to be fixed by hand? One option is to make It is better than accidentally removing something we did not write imo. Unit testWe should add this unit test case to https://github.com/coder/coder/blob/main/cli/configssh_test.go#L531-L531 {
name: "Start/End out of order",
matches: []match{
{match: "Continue?", write: "yes"},
},
writeConfig: writeConfig{
ssh: strings.Join([]string{
"# Content before coder block",
headerEnd,
headerStart,
"# Content after coder block",
}, "\n"),
},
wantConfig: wantConfig{
ssh: strings.Join([]string{
// TODO: What is the expected behavior here?
}, "\n"),
},
wantErr: false,
}, |
@aaronlehmann what do you think about returning an error if the headers are out of order and return an error if there is more than 1 header in the config? |
That sounds good to me. I'm currently waiting to confirm my employer doesn't object to me agreeing to the CLA, but if you want to tackle this that's fine with me (or feel free to wait until I hear back about the CLA, then I can take a look). |
@aaronlehmann I have some other things going on, so won't be able to touch this for a bit (days). Will keep and eye on this thread and will post here if I do any work on it though 👍 |
This Pull Request is becoming stale. In order to minimize WIP, prevent merge conflicts and keep the tracker readable, I'm going close to this PR in 3 days if there isn't more activity. |
I am making a branch that fixes this by throwing an error if the ssh config is malformed. |
Fixed here: #6000 |
Thanks! |
I somehow ended up with a
~/.ssh/config
file that had anEND-CODER
token beforeSTART-CODER
(probably a bad edit on my side). This causescoder config-ssh
to panic. Fix this panic by simplifying and combiningsshConfigGetCoderSection
andsshConfigSplitOnCoderSection
to look for the tokens in order withbytes.Cut
.