@@ -13,6 +13,7 @@ import (
13
13
"path/filepath"
14
14
"runtime"
15
15
"sort"
16
+ "strconv"
16
17
"strings"
17
18
18
19
"github.com/cli/safeexec"
@@ -46,9 +47,10 @@ const (
46
47
// sshConfigOptions represents options that can be stored and read
47
48
// from the coder config in ~/.ssh/coder.
48
49
type sshConfigOptions struct {
49
- waitEnum string
50
- userHostPrefix string
51
- sshOptions []string
50
+ waitEnum string
51
+ userHostPrefix string
52
+ sshOptions []string
53
+ disableAutostart bool
52
54
}
53
55
54
56
// addOptions expects options in the form of "option=value" or "option value".
@@ -106,7 +108,7 @@ func (o sshConfigOptions) equal(other sshConfigOptions) bool {
106
108
if ! slices .Equal (opt1 ,opt2 ) {
107
109
return false
108
110
}
109
- return o .waitEnum == other .waitEnum && o .userHostPrefix == other .userHostPrefix
111
+ return o .waitEnum == other .waitEnum && o .userHostPrefix == other .userHostPrefix && o . disableAutostart == other . disableAutostart
110
112
}
111
113
112
114
func (o sshConfigOptions )asList () (list []string ) {
@@ -116,6 +118,9 @@ func (o sshConfigOptions) asList() (list []string) {
116
118
if o .userHostPrefix != "" {
117
119
list = append (list ,fmt .Sprintf ("ssh-host-prefix: %s" ,o .userHostPrefix ))
118
120
}
121
+ if o .disableAutostart {
122
+ list = append (list ,fmt .Sprintf ("disable-autostart: %v" ,o .disableAutostart ))
123
+ }
119
124
for _ ,opt := range o .sshOptions {
120
125
list = append (list ,fmt .Sprintf ("ssh-option: %s" ,opt ))
121
126
}
@@ -392,6 +397,9 @@ func (r *RootCmd) configSSH() *clibase.Cmd {
392
397
if sshConfigOpts .waitEnum != "auto" {
393
398
flags += " --wait=" + sshConfigOpts .waitEnum
394
399
}
400
+ if sshConfigOpts .disableAutostart {
401
+ flags += " --disable-autostart=true"
402
+ }
395
403
defaultOptions = append (defaultOptions ,fmt .Sprintf (
396
404
"ProxyCommand %s --global-config %s ssh --stdio%s %s" ,
397
405
escapedCoderBinary ,escapedGlobalConfig ,flags ,workspaceHostname ,
@@ -566,6 +574,13 @@ func (r *RootCmd) configSSH() *clibase.Cmd {
566
574
Default :"auto" ,
567
575
Value :clibase .EnumOf (& sshConfigOpts .waitEnum ,"yes" ,"no" ,"auto" ),
568
576
},
577
+ {
578
+ Flag :"disable-autostart" ,
579
+ Description :"Disable starting the workspace automatically when connecting via SSH." ,
580
+ Env :"CODER_CONFIGSSH_DISABLE_AUTOSTART" ,
581
+ Value :clibase .BoolOf (& sshConfigOpts .disableAutostart ),
582
+ Default :"false" ,
583
+ },
569
584
{
570
585
Flag :"force-unix-filepaths" ,
571
586
Env :"CODER_CONFIGSSH_UNIX_FILEPATHS" ,
@@ -602,6 +617,9 @@ func sshConfigWriteSectionHeader(w io.Writer, addNewline bool, o sshConfigOption
602
617
if o .userHostPrefix != "" {
603
618
_ ,_ = fmt .Fprintf (& ow ,"# :%s=%s\n " ,"ssh-host-prefix" ,o .userHostPrefix )
604
619
}
620
+ if o .disableAutostart {
621
+ _ ,_ = fmt .Fprintf (& ow ,"# :%s=%v\n " ,"disable-autostart" ,o .disableAutostart )
622
+ }
605
623
for _ ,opt := range o .sshOptions {
606
624
_ ,_ = fmt .Fprintf (& ow ,"# :%s=%s\n " ,"ssh-option" ,opt )
607
625
}
@@ -634,6 +652,8 @@ func sshConfigParseLastOptions(r io.Reader) (o sshConfigOptions) {
634
652
o .userHostPrefix = parts [1 ]
635
653
case "ssh-option" :
636
654
o .sshOptions = append (o .sshOptions ,parts [1 ])
655
+ case "disable-autostart" :
656
+ o .disableAutostart ,_ = strconv .ParseBool (parts [1 ])
637
657
default :
638
658
// Unknown option, ignore.
639
659
}