Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
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
1 change: 0 additions & 1 deletion coder-sdk/workspace_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type KubernetesProvider struct {
EnvproxyAccessURL string `json:"envproxy_access_url" table:"Access URL" validate:"required"`
DevurlHost string `json:"devurl_host" table:"Devurl Host"`
OrgWhitelist []string `json:"org_whitelist" table:"-"`
EnableNetV2 bool `json:"enable_net_v2" table:"Enable NetV2"`
KubeProviderConfig `json:"config" table:"_"`
}

Expand Down
37 changes: 9 additions & 28 deletions internal/cmd/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -119,7 +118,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
return xerrors.Errorf("Failed to get executable path: %w", err)
}

newConfig := makeNewConfigs(binPath, user.Username, workspacesWithProviders, privateKeyFilepath)
newConfig := makeNewConfigs(binPath, workspacesWithProviders, privateKeyFilepath)

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

func makeNewConfigs(binPath, userName string, workspaces []coderutil.WorkspaceWithWorkspaceProvider, privateKeyFilepath string) string {
func makeNewConfigs(binPath string, workspaces []coderutil.WorkspaceWithWorkspaceProvider, privateKeyFilepath string) string {
newConfig := fmt.Sprintf("\n%s\n%s\n\n", sshStartToken, sshStartMessage)

sort.Slice(workspaces, func(i, j int) bool { return workspaces[i].Workspace.Name < workspaces[j].Workspace.Name })
Expand All @@ -240,24 +239,17 @@ func makeNewConfigs(binPath, userName string, workspaces []coderutil.WorkspaceWi
)
continue
}
u, err := url.Parse(workspace.WorkspaceProvider.EnvproxyAccessURL)
if err != nil {
clog.LogWarn("invalid access url", clog.Causef("malformed url: %q", workspace.WorkspaceProvider.EnvproxyAccessURL))
continue
}

useTunnel := workspace.WorkspaceProvider.SSHEnabled && workspace.WorkspaceProvider.EnableNetV2
newConfig += makeSSHConfig(binPath, u.Host, userName, workspace.Workspace.Name, privateKeyFilepath, useTunnel)
newConfig += makeSSHConfig(binPath, workspace.Workspace.Name, privateKeyFilepath)
}
newConfig += fmt.Sprintf("\n%s\n", sshEndToken)

return newConfig
}

func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath string, tunnel bool) string {
if tunnel {
host := fmt.Sprintf(
`Host coder.%s
func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string {
entry := fmt.Sprintf(
`Host coder.%s
HostName coder.%s
ProxyCommand "%s" tunnel %s 12213 stdio
StrictHostKeyChecking no
Expand All @@ -266,25 +258,14 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st
IdentityFile="%s"
`, workspaceName, workspaceName, binPath, workspaceName, privateKeyFilepath)

if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
host += ` ControlMaster auto
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
entry += ` ControlMaster auto
ControlPath ~/.ssh/.connection-%r@%h:%p
ControlPersist 600
`
}

return host
}

return fmt.Sprintf(
`Host coder.%s
HostName %s
User %s-%s
StrictHostKeyChecking no
ConnectTimeout=0
IdentitiesOnly yes
IdentityFile="%s"
`, workspaceName, host, userName, workspaceName, privateKeyFilepath)
return entry
}

func writeStr(filename, data string) error {
Expand Down