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

[ch-13671] stop using global enable_netv2 in favor of workspace provider config #370

Merged
merged 2 commits into from
Jun 22, 2021
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: 1 addition & 0 deletions coder-sdk/workspace_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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
1 change: 0 additions & 1 deletion docs/coder_config-ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ coder config-ssh [flags]
```
--filepath string override the default path of your ssh config file (default "~/.ssh/config")
-h, --help help for config-ssh
--next (alpha) uses coder tunnel to proxy ssh connection
--remove remove the auto-generated Coder ssh config
```

Expand Down
29 changes: 5 additions & 24 deletions internal/cmd/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,21 @@ func configSSHCmd() *cobra.Command {
var (
configpath string
remove = false
next = false
)

cmd := &cobra.Command{
Use: "config-ssh",
Short: "Configure SSH to access Coder workspaces",
Long: "Inject the proper OpenSSH configuration into your local SSH config file.",
RunE: configSSH(&configpath, &remove, &next),
RunE: configSSH(&configpath, &remove),
}
cmd.Flags().StringVar(&configpath, "filepath", filepath.Join("~", ".ssh", "config"), "override the default path of your ssh config file")
cmd.Flags().BoolVar(&remove, "remove", false, "remove the auto-generated Coder ssh config")
cmd.Flags().BoolVar(&next, "next", false, "(alpha) uses coder tunnel to proxy ssh connection")

return cmd
}

func configSSH(configpath *string, remove *bool, next *bool) func(cmd *cobra.Command, _ []string) error {
func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
return func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
usr, err := user.Current()
Expand Down Expand Up @@ -115,29 +113,12 @@ func configSSH(configpath *string, remove *bool, next *bool) func(cmd *cobra.Com
return xerrors.New("SSH is disabled or not available for any workspaces in your Coder deployment.")
}

wconf, err := client.SiteConfigWorkspaces(ctx)
if err != nil {
return xerrors.Errorf("getting site workspace config: %w", err)
}
p2p := false
if wconf.EnableP2P {
if *next {
p2p = true
} else {
fmt.Println("Note: NetworkingV2 is enabled on the coder deployment, use --next to enable it for ssh")
}
} else {
if *next {
return xerrors.New("NetworkingV2 feature is not enabled, cannot use --next flag")
}
}

binPath, err := os.Executable()
if err != nil {
return xerrors.Errorf("Failed to get executable path: %w", err)
}

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

err = os.MkdirAll(filepath.Dir(*configpath), os.ModePerm)
if err != nil {
Expand Down Expand Up @@ -198,7 +179,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, p2p bool) string {
func makeNewConfigs(binPath, userName 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 @@ -217,7 +198,7 @@ func makeNewConfigs(binPath, userName string, workspaces []coderutil.WorkspaceWi
continue
}

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