Skip to content

feat: Allow unsetting ssh config options from deployment #6847

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 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cli/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (o *sshConfigOptions) addOptions(options ...string) error {
}

func (o *sshConfigOptions) addOption(option string) error {
key, _, err := codersdk.ParseSSHConfigOption(option)
key, value, err := codersdk.ParseSSHConfigOption(option)
if err != nil {
return err
}
Expand All @@ -77,11 +77,20 @@ func (o *sshConfigOptions) addOption(option string) error {
continue
}
if strings.EqualFold(existingKey, key) {
o.sshOptions[i] = option
if value == "" {
// Delete existing option.
o.sshOptions = append(o.sshOptions[:i], o.sshOptions[i+1:]...)
} else {
// Override existing option.
o.sshOptions[i] = option
}
return nil
}
}
o.sshOptions = append(o.sshOptions, option)
// Only append the option if it is not empty.
if value != "" {
o.sshOptions = append(o.sshOptions, option)
}
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions cli/configssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ func TestConfigSSH(t *testing.T) {

const hostname = "test-coder."
const expectedKey = "ConnectionAttempts"
const removeKey = "ConnectionTimeout"
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
ConfigSSH: codersdk.SSHConfigResponse{
HostnamePrefix: hostname,
SSHConfigOptions: map[string]string{
// Something we can test for
expectedKey: "3",
removeKey: "",
},
},
})
Expand Down Expand Up @@ -176,6 +178,7 @@ func TestConfigSSH(t *testing.T) {
fileContents, err := os.ReadFile(sshConfigFile)
require.NoError(t, err, "read ssh config file")
require.Contains(t, string(fileContents), expectedKey, "ssh config file contains expected key")
require.NotContains(t, string(fileContents), removeKey, "ssh config file should not have removed key")

home := filepath.Dir(filepath.Dir(sshConfigFile))
// #nosec
Expand Down