mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: use client preferred URL for the default DERP (#18911)
The agentsdk currently does a remap of the DERP map to change the EmbeddedRelay node's URL to match the agent's access URL. This PR makes changes to the `workspacesdk` (used by clients like the CLI) and `vpn` (used by Coder Desktop) to match this behavior. This enables us the ability to try Coder clients in dogfood over a VPN without changing the global access URL.
This commit is contained in:
@@ -193,6 +193,15 @@ type DialAgentOptions struct {
|
||||
EnableTelemetry bool
|
||||
}
|
||||
|
||||
// RewriteDERPMap rewrites the DERP map to use the configured access URL of the
|
||||
// client as the "embedded relay" access URL.
|
||||
//
|
||||
// See tailnet.RewriteDERPMapDefaultRelay for more details on why this is
|
||||
// necessary.
|
||||
func (c *Client) RewriteDERPMap(derpMap *tailcfg.DERPMap) {
|
||||
tailnet.RewriteDERPMapDefaultRelay(context.Background(), c.client.Logger(), derpMap, c.client.URL)
|
||||
}
|
||||
|
||||
func (c *Client) DialAgent(dialCtx context.Context, agentID uuid.UUID, options *DialAgentOptions) (agentConn *AgentConn, err error) {
|
||||
if options == nil {
|
||||
options = &DialAgentOptions{}
|
||||
@@ -248,6 +257,8 @@ func (c *Client) DialAgent(dialCtx context.Context, agentID uuid.UUID, options *
|
||||
telemetrySink = basicTel
|
||||
controller.TelemetryCtrl = basicTel
|
||||
}
|
||||
|
||||
c.RewriteDERPMap(connInfo.DERPMap)
|
||||
conn, err := tailnet.NewConn(&tailnet.Options{
|
||||
Addresses: []netip.Prefix{netip.PrefixFrom(ip, 128)},
|
||||
DERPMap: connInfo.DERPMap,
|
||||
@@ -270,7 +281,7 @@ func (c *Client) DialAgent(dialCtx context.Context, agentID uuid.UUID, options *
|
||||
coordCtrl := tailnet.NewTunnelSrcCoordController(options.Logger, conn)
|
||||
coordCtrl.AddDestination(agentID)
|
||||
controller.CoordCtrl = coordCtrl
|
||||
controller.DERPCtrl = tailnet.NewBasicDERPController(options.Logger, conn)
|
||||
controller.DERPCtrl = tailnet.NewBasicDERPController(options.Logger, c, conn)
|
||||
controller.Run(ctx)
|
||||
|
||||
options.Logger.Debug(ctx, "running tailnet API v2+ connector")
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
"github.com/coder/coder/v2/coderd/httpapi"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/codersdk/agentsdk"
|
||||
"github.com/coder/coder/v2/codersdk/workspacesdk"
|
||||
"github.com/coder/coder/v2/tailnet"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
@@ -43,7 +42,7 @@ func TestWorkspaceRewriteDERPMap(t *testing.T) {
|
||||
}
|
||||
parsed, err := url.Parse("https://coconuts.org:44558")
|
||||
require.NoError(t, err)
|
||||
client := agentsdk.New(parsed)
|
||||
client := workspacesdk.New(codersdk.New(parsed))
|
||||
client.RewriteDERPMap(dm)
|
||||
region := dm.Regions[1]
|
||||
require.True(t, region.EmbeddedRelay)
|
||||
|
||||
Reference in New Issue
Block a user