Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 8e15d36

Browse files
committed
Merge remote-tracking branch 'origin/master' into stevenmasley/ch15591/webrtc_sh
2 parents 22a6958 + 3ebd102 commit 8e15d36

File tree

12 files changed

+431
-78
lines changed

12 files changed

+431
-78
lines changed

docs/coder_config-ssh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ coder config-ssh [flags]
1515
```
1616
--filepath string override the default path of your ssh config file (default "~/.ssh/config")
1717
-h, --help help for config-ssh
18+
-o, --option strings additional options injected in the ssh config (ex. disable caching with "-o ControlPath=none")
1819
--remove remove the auto-generated Coder ssh config
1920
```
2021

docs/coder_workspaces.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Perform operations on the Coder workspaces owned by the active user.
2626
* [coder workspaces edit](coder_workspaces_edit.md) - edit an existing workspace and initiate a rebuild.
2727
* [coder workspaces edit-from-config](coder_workspaces_edit-from-config.md) - change the template a workspace is tracking
2828
* [coder workspaces ls](coder_workspaces_ls.md) - list all workspaces owned by the active user
29+
* [coder workspaces ping](coder_workspaces_ping.md) - ping Coder workspaces by name
2930
* [coder workspaces policy-template](coder_workspaces_policy-template.md) - Set workspace policy template
3031
* [coder workspaces rebuild](coder_workspaces_rebuild.md) - rebuild a Coder workspace
3132
* [coder workspaces rm](coder_workspaces_rm.md) - remove Coder workspaces by name

docs/coder_workspaces_ping.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## coder workspaces ping
2+
3+
ping Coder workspaces by name
4+
5+
### Synopsis
6+
7+
ping Coder workspaces by name
8+
9+
```
10+
coder workspaces ping <workspace_name> [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
coder workspaces ping front-end-workspace
17+
```
18+
19+
### Options
20+
21+
```
22+
-c, --count int stop after <count> replies
23+
-h, --help help for ping
24+
-s, --scheme strings customize schemes to filter ice servers (default [stun,stuns,turn,turns])
25+
```
26+
27+
### Options inherited from parent commands
28+
29+
```
30+
-v, --verbose show verbose output
31+
```
32+
33+
### SEE ALSO
34+
35+
* [coder workspaces](coder_workspaces.md) - Interact with Coder workspaces
36+

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ require (
2525
github.com/rjeczalik/notify v0.9.2
2626
github.com/spf13/cobra v1.2.1
2727
github.com/stretchr/testify v1.7.0
28+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
2829
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
2930
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
30-
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015
31+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1
3132
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
3233
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
3334
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U
430430
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
431431
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
432432
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
433-
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
434433
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
434+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
435+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
435436
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
436437
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
437438
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -590,8 +591,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
590591
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
591592
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
592593
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
593-
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E=
594594
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
595+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
596+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
595597
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
596598
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
597599
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

internal/cmd/agent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ coder agent start --coder-url https://my-coder.com --token xxxx-xxxx
8484
return xerrors.Errorf("listen: %w", err)
8585
}
8686
defer func() {
87+
log.Info(ctx, "closing wsnet listener")
8788
err := listener.Close()
8889
if err != nil {
8990
log.Error(ctx, "close listener", slog.Error(err))

internal/cmd/cmd.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ func Make() *cobra.Command {
2222
}
2323

2424
app.AddCommand(
25+
agentCmd(),
26+
completionCmd(),
27+
configSSHCmd(),
28+
envCmd(), // DEPRECATED.
29+
genDocsCmd(app),
30+
imgsCmd(),
2531
loginCmd(),
2632
logoutCmd(),
33+
providersCmd(),
34+
resourceCmd(),
35+
satellitesCmd(),
2736
sshCmd(),
28-
usersCmd(),
29-
tagsCmd(),
30-
configSSHCmd(),
31-
envCmd(), // DEPRECATED.
32-
workspacesCmd(),
3337
syncCmd(),
34-
urlCmd(),
38+
tagsCmd(),
3539
tokensCmd(),
36-
resourceCmd(),
37-
completionCmd(),
38-
imgsCmd(),
39-
providersCmd(),
40-
genDocsCmd(app),
41-
agentCmd(),
4240
tunnelCmd(),
43-
satellitesCmd(),
41+
urlCmd(),
42+
usersCmd(),
43+
workspacesCmd(),
4444
)
4545
app.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output")
4646
return app

internal/cmd/configssh.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,24 @@ const sshEndToken = "# ------------END-CODER-ENTERPRISE------------"
3333

3434
func configSSHCmd() *cobra.Command {
3535
var (
36-
configpath string
37-
remove = false
36+
configpath string
37+
remove = false
38+
additionalOptions []string
3839
)
3940

4041
cmd := &cobra.Command{
4142
Use: "config-ssh",
4243
Short: "Configure SSH to access Coder workspaces",
4344
Long: "Inject the proper OpenSSH configuration into your local SSH config file.",
44-
RunE: configSSH(&configpath, &remove),
45+
RunE: configSSH(&configpath, &remove, &additionalOptions),
4546
}
4647
cmd.Flags().StringVar(&configpath, "filepath", filepath.Join("~", ".ssh", "config"), "override the default path of your ssh config file")
4748
cmd.Flags().BoolVar(&remove, "remove", false, "remove the auto-generated Coder ssh config")
4849

4950
return cmd
5051
}
5152

52-
func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
53+
func configSSH(configpath *string, remove *bool, additionalOptions *[]string) func(cmd *cobra.Command, _ []string) error {
5354
return func(cmd *cobra.Command, _ []string) error {
5455
ctx := cmd.Context()
5556
usr, err := user.Current()
@@ -118,7 +119,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
118119
return xerrors.Errorf("Failed to get executable path: %w", err)
119120
}
120121

121-
newConfig := makeNewConfigs(binPath, workspacesWithProviders, privateKeyFilepath)
122+
newConfig := makeNewConfigs(binPath, workspacesWithProviders, privateKeyFilepath, *additionalOptions)
122123

123124
err = os.MkdirAll(filepath.Dir(*configpath), os.ModePerm)
124125
if err != nil {
@@ -226,7 +227,7 @@ func writeSSHKey(ctx context.Context, client coder.Client, privateKeyPath string
226227
return ioutil.WriteFile(privateKeyPath, []byte(key.PrivateKey), 0600)
227228
}
228229

229-
func makeNewConfigs(binPath string, workspaces []coderutil.WorkspaceWithWorkspaceProvider, privateKeyFilepath string) string {
230+
func makeNewConfigs(binPath string, workspaces []coderutil.WorkspaceWithWorkspaceProvider, privateKeyFilepath string, additionalOptions []string) string {
230231
newConfig := fmt.Sprintf("\n%s\n%s\n\n", sshStartToken, sshStartMessage)
231232

232233
sort.Slice(workspaces, func(i, j int) bool { return workspaces[i].Workspace.Name < workspaces[j].Workspace.Name })
@@ -240,32 +241,41 @@ func makeNewConfigs(binPath string, workspaces []coderutil.WorkspaceWithWorkspac
240241
continue
241242
}
242243

243-
newConfig += makeSSHConfig(binPath, workspace.Workspace.Name, privateKeyFilepath)
244+
newConfig += makeSSHConfig(binPath, workspace.Workspace.Name, privateKeyFilepath, additionalOptions)
244245
}
245246
newConfig += fmt.Sprintf("\n%s\n", sshEndToken)
246247

247248
return newConfig
248249
}
249250

250-
func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string {
251-
entry := fmt.Sprintf(
252-
`Host coder.%s
253-
HostName coder.%s
254-
ProxyCommand %s
255-
StrictHostKeyChecking no
256-
ConnectTimeout=0
257-
IdentitiesOnly yes
258-
IdentityFile="%s"
259-
`, workspaceName, workspaceName, proxyCommand(binPath, workspaceName, true), privateKeyFilepath)
251+
func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string, additionalOptions []string) string {
252+
// Custom user options come first to maximizessh customization.
253+
options := []string{}
254+
if len(additionalOptions) > 0 {
255+
options = []string{
256+
"# Custom options. Duplicated values will always prefer the first!",
257+
}
258+
options = append(options, additionalOptions...)
259+
options = append(options, "# End custom options.")
260+
}
261+
options = append(options,
262+
fmt.Sprintf("HostName coder.%s", workspaceName),
263+
fmt.Sprintf("ProxyCommand %s", proxyCommand(binPath, workspaceName, true)),
264+
"StrictHostKeyChecking no",
265+
"ConnectTimeout=0",
266+
"IdentitiesOnly yes",
267+
fmt.Sprintf("IdentityFile=%q", privateKeyFilepath),
268+
)
260269

261270
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
262-
entry += ` ControlMaster auto
263-
ControlPath ~/.ssh/.connection-%r@%h:%p
264-
ControlPersist 600
265-
`
271+
options = append(options,
272+
"ControlMaster auto",
273+
"ControlPath ~/.ssh/.connection-%r@%h:%p",
274+
"ControlPersist 600",
275+
)
266276
}
267277

268-
return entry
278+
return fmt.Sprintf("Host coder.%s\n\t%s\n\n", workspaceName, strings.Join(options, "\n\t"))
269279
}
270280

271281
func proxyCommand(binPath, workspaceName string, quoted bool) string {

0 commit comments

Comments
 (0)