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 4 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
33 changes: 7 additions & 26 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 @@ -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