diff --git a/cli/configssh.go b/cli/configssh.go
index 952120c30b477..67fbd19ef3f69 100644
--- a/cli/configssh.go
+++ b/cli/configssh.go
@@ -45,8 +45,10 @@ const (
// sshConfigOptions represents options that can be stored and read
// from the coder config in ~/.ssh/coder.
type sshConfigOptions struct {
- waitEnum string
+ waitEnum string
+ // Deprecated: moving away from prefix to hostnameSuffix
userHostPrefix string
+ hostnameSuffix string
sshOptions []string
disableAutostart bool
header []string
@@ -97,7 +99,11 @@ func (o sshConfigOptions) equal(other sshConfigOptions) bool {
if !slicesSortedEqual(o.header, other.header) {
return false
}
- return o.waitEnum == other.waitEnum && o.userHostPrefix == other.userHostPrefix && o.disableAutostart == other.disableAutostart && o.headerCommand == other.headerCommand
+ return o.waitEnum == other.waitEnum &&
+ o.userHostPrefix == other.userHostPrefix &&
+ o.disableAutostart == other.disableAutostart &&
+ o.headerCommand == other.headerCommand &&
+ o.hostnameSuffix == other.hostnameSuffix
}
// slicesSortedEqual compares two slices without side-effects or regard to order.
@@ -119,6 +125,9 @@ func (o sshConfigOptions) asList() (list []string) {
if o.userHostPrefix != "" {
list = append(list, fmt.Sprintf("ssh-host-prefix: %s", o.userHostPrefix))
}
+ if o.hostnameSuffix != "" {
+ list = append(list, fmt.Sprintf("hostname-suffix: %s", o.hostnameSuffix))
+ }
if o.disableAutostart {
list = append(list, fmt.Sprintf("disable-autostart: %v", o.disableAutostart))
}
@@ -314,6 +323,10 @@ func (r *RootCmd) configSSH() *serpent.Command {
// Override with user flag.
coderdConfig.HostnamePrefix = sshConfigOpts.userHostPrefix
}
+ if sshConfigOpts.hostnameSuffix != "" {
+ // Override with user flag.
+ coderdConfig.HostnameSuffix = sshConfigOpts.hostnameSuffix
+ }
// Write agent configuration.
defaultOptions := []string{
@@ -518,6 +531,12 @@ func (r *RootCmd) configSSH() *serpent.Command {
Description: "Override the default host prefix.",
Value: serpent.StringOf(&sshConfigOpts.userHostPrefix),
},
+ {
+ Flag: "hostname-suffix",
+ Env: "CODER_CONFIGSSH_HOSTNAME_SUFFIX",
+ Description: "Override the default hostname suffix.",
+ Value: serpent.StringOf(&sshConfigOpts.hostnameSuffix),
+ },
{
Flag: "wait",
Env: "CODER_CONFIGSSH_WAIT", // Not to be mixed with CODER_SSH_WAIT.
@@ -568,6 +587,9 @@ func sshConfigWriteSectionHeader(w io.Writer, addNewline bool, o sshConfigOption
if o.userHostPrefix != "" {
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "ssh-host-prefix", o.userHostPrefix)
}
+ if o.hostnameSuffix != "" {
+ _, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "hostname-suffix", o.hostnameSuffix)
+ }
if o.disableAutostart {
_, _ = fmt.Fprintf(&ow, "# :%s=%v\n", "disable-autostart", o.disableAutostart)
}
@@ -607,6 +629,8 @@ func sshConfigParseLastOptions(r io.Reader) (o sshConfigOptions) {
o.waitEnum = parts[1]
case "ssh-host-prefix":
o.userHostPrefix = parts[1]
+ case "hostname-suffix":
+ o.hostnameSuffix = parts[1]
case "ssh-option":
o.sshOptions = append(o.sshOptions, parts[1])
case "disable-autostart":
diff --git a/cli/configssh_test.go b/cli/configssh_test.go
index 3b88ab1e54db7..84399ddc67949 100644
--- a/cli/configssh_test.go
+++ b/cli/configssh_test.go
@@ -432,6 +432,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
"# Last config-ssh options:",
"# :wait=yes",
"# :ssh-host-prefix=coder-test.",
+ "# :hostname-suffix=coder-suffix",
"# :header=X-Test-Header=foo",
"# :header=X-Test-Header2=bar",
"# :header-command=printf h1=v1 h2=\"v2\" h3='v3'",
@@ -447,6 +448,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
"--yes",
"--wait=yes",
"--ssh-host-prefix", "coder-test.",
+ "--hostname-suffix", "coder-suffix",
"--header", "X-Test-Header=foo",
"--header", "X-Test-Header2=bar",
"--header-command", "printf h1=v1 h2=\"v2\" h3='v3'",
diff --git a/cli/testdata/coder_config-ssh_--help.golden b/cli/testdata/coder_config-ssh_--help.golden
index ebbfb7a11676c..86f38db99e84a 100644
--- a/cli/testdata/coder_config-ssh_--help.golden
+++ b/cli/testdata/coder_config-ssh_--help.golden
@@ -33,6 +33,9 @@ OPTIONS:
unix-like shell. This flag forces the use of unix file paths (the
forward slash '/').
+ --hostname-suffix string, $CODER_CONFIGSSH_HOSTNAME_SUFFIX
+ Override the default hostname suffix.
+
--ssh-config-file string, $CODER_SSH_CONFIG_FILE (default: ~/.ssh/config)
Specifies the path to an SSH config.
diff --git a/docs/reference/cli/config-ssh.md b/docs/reference/cli/config-ssh.md
index 937bcd061bd05..c9250523b6c28 100644
--- a/docs/reference/cli/config-ssh.md
+++ b/docs/reference/cli/config-ssh.md
@@ -79,6 +79,15 @@ Specifies whether or not to keep options from previous run of config-ssh.
Override the default host prefix.
+### --hostname-suffix
+
+| | |
+|-------------|-----------------------------------------------|
+| Type | string
|
+| Environment | $CODER_CONFIGSSH_HOSTNAME_SUFFIX
|
+
+Override the default hostname suffix.
+
### --wait
| | |