From 33a70d54a09bf490c060daa015d4861854f8e60f Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 22 Jan 2024 14:23:20 -0600 Subject: [PATCH] fix: code-server path based forwarding, defer to code-server Do not attempt to construct a path based port forward url. Always defer to code server, as it has it's own proxy method. --- agent/agentssh/agentssh.go | 6 +++++- coderd/agentapi/manifest.go | 10 ++++++---- coderd/agentapi/manifest_internal_test.go | 5 ++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/agent/agentssh/agentssh.go b/agent/agentssh/agentssh.go index 0e1328badd541..9bd0c2cf30556 100644 --- a/agent/agentssh/agentssh.go +++ b/agent/agentssh/agentssh.go @@ -681,7 +681,11 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string) // This adds the ports dialog to code-server that enables // proxying a port dynamically. - cmd.Env = append(cmd.Env, fmt.Sprintf("VSCODE_PROXY_URI=%s", manifest.VSCodePortProxyURI)) + // If this is empty string, do not set anything. Code-server auto defaults + // using its basepath to construct a path based port proxy. + if manifest.VSCodePortProxyURI != "" { + cmd.Env = append(cmd.Env, fmt.Sprintf("VSCODE_PROXY_URI=%s", manifest.VSCodePortProxyURI)) + } // Hide Coder message on code-server's "Getting Started" page cmd.Env = append(cmd.Env, "CS_DISABLE_GETTING_STARTED_OVERRIDE=true") diff --git a/coderd/agentapi/manifest.go b/coderd/agentapi/manifest.go index 2d81aef77580d..ddd562c969009 100644 --- a/coderd/agentapi/manifest.go +++ b/coderd/agentapi/manifest.go @@ -150,12 +150,14 @@ func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifest } func vscodeProxyURI(app appurl.ApplicationURL, accessURL *url.URL, appHost string) string { - // This will handle the ports from the accessURL or appHost. - appHost = appurl.SubdomainAppHost(appHost, accessURL) - // If there is no appHost, then we want to use the access url as the proxy uri. + // Proxying by port only works for subdomains. If subdomain support is not + // available, return an empty string. if appHost == "" { - appHost = accessURL.Host + return "" } + + // This will handle the ports from the accessURL or appHost. + appHost = appurl.SubdomainAppHost(appHost, accessURL) // Return the url with a scheme and any wildcards replaced with the app slug. return accessURL.Scheme + "://" + strings.ReplaceAll(appHost, "*", app.String()) } diff --git a/coderd/agentapi/manifest_internal_test.go b/coderd/agentapi/manifest_internal_test.go index 30d144d1e92a2..33e0cb7613099 100644 --- a/coderd/agentapi/manifest_internal_test.go +++ b/coderd/agentapi/manifest_internal_test.go @@ -35,19 +35,18 @@ func Test_vscodeProxyURI(t *testing.T) { Expected string }{ { - // No hostname proxies through the access url. Name: "NoHostname", AccessURL: coderAccessURL, AppHostname: "", App: basicApp, - Expected: coderAccessURL.String(), + Expected: "", }, { Name: "NoHostnameAccessURLPort", AccessURL: accessURLWithPort, AppHostname: "", App: basicApp, - Expected: accessURLWithPort.String(), + Expected: "", }, { Name: "Hostname",