Skip to content

Commit 68986b0

Browse files
committed
make coderd and wsproxy use websockets for derp
1 parent ef2ad11 commit 68986b0

File tree

8 files changed

+32
-22
lines changed

8 files changed

+32
-22
lines changed

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ func New(options *Options) *API {
405405
options.Logger,
406406
options.DERPServer,
407407
api.DERPMap,
408+
options.DeploymentValues.DERP.Config.ForceWebSockets.Value(),
408409
func(context.Context) (tailnet.MultiAgentConn, error) {
409410
return (*api.TailnetCoordinator.Load()).ServeMultiAgent(uuid.New()), nil
410411
},

coderd/tailnet.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@ func NewServerTailnet(
4545
logger slog.Logger,
4646
derpServer *derp.Server,
4747
derpMapFn func() *tailcfg.DERPMap,
48+
derpForceWebSockets bool,
4849
getMultiAgent func(context.Context) (tailnet.MultiAgentConn, error),
4950
cache *wsconncache.Cache,
5051
traceProvider trace.TracerProvider,
5152
) (*ServerTailnet, error) {
5253
logger = logger.Named("servertailnet")
5354
originalDerpMap := derpMapFn()
5455
conn, err := tailnet.NewConn(&tailnet.Options{
55-
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
56-
DERPMap: originalDerpMap,
57-
Logger: logger,
56+
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
57+
DERPMap: originalDerpMap,
58+
DERPForceWebSockets: derpForceWebSockets,
59+
Logger: logger,
5860
})
5961
if err != nil {
6062
return nil, xerrors.Errorf("create tailnet conn: %w", err)

coderd/tailnet_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func setupAgent(t *testing.T, agentAddresses []netip.Prefix) (uuid.UUID, agent.A
232232
logger,
233233
derpServer,
234234
func() *tailcfg.DERPMap { return manifest.DERPMap },
235+
false,
235236
func(context.Context) (tailnet.MultiAgentConn, error) { return coord.ServeMultiAgent(uuid.New()), nil },
236237
cache,
237238
trace.NewNoopTracerProvider(),

coderd/workspaceagents.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,11 @@ func (api *API) _dialWorkspaceAgentTailnet(agentID uuid.UUID) (*codersdk.Workspa
734734

735735
derpMap := api.DERPMap()
736736
conn, err := tailnet.NewConn(&tailnet.Options{
737-
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
738-
DERPMap: api.DERPMap(),
739-
Logger: api.Logger.Named("net.tailnet"),
740-
BlockEndpoints: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
737+
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
738+
DERPMap: api.DERPMap(),
739+
DERPForceWebSockets: api.DeploymentValues.DERP.Config.ForceWebSockets.Value(),
740+
Logger: api.Logger.Named("net.tailnet"),
741+
BlockEndpoints: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
741742
})
742743
if err != nil {
743744
_ = clientConn.Close()

coderd/wsconncache/wsconncache_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ func setupAgent(t *testing.T, manifest agentsdk.Manifest, ptyTimeout time.Durati
179179
_ = closer.Close()
180180
})
181181
conn, err := tailnet.NewConn(&tailnet.Options{
182-
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
183-
DERPMap: manifest.DERPMap,
184-
Logger: slogtest.Make(t, nil).Named("tailnet").Leveled(slog.LevelDebug),
182+
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
183+
DERPMap: manifest.DERPMap,
184+
DERPForceWebSockets: manifest.DERPForceWebSockets,
185+
Logger: slogtest.Make(t, nil).Named("tailnet").Leveled(slog.LevelDebug),
185186
})
186187
require.NoError(t, err)
187188
clientConn, serverConn := net.Pipe()

enterprise/coderd/workspaceproxy.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,12 @@ func (api *API) workspaceProxyRegister(rw http.ResponseWriter, r *http.Request)
717717

718718
// aReq.New = updatedProxy
719719
httpapi.Write(ctx, rw, http.StatusCreated, wsproxysdk.RegisterWorkspaceProxyResponse{
720-
AppSecurityKey: api.AppSecurityKey.String(),
721-
DERPMeshKey: api.DERPServer.MeshKey(),
722-
DERPRegionID: regionID,
723-
DERPMap: api.AGPL.DERPMap(),
724-
SiblingReplicas: siblingsRes,
720+
AppSecurityKey: api.AppSecurityKey.String(),
721+
DERPMeshKey: api.DERPServer.MeshKey(),
722+
DERPRegionID: regionID,
723+
DERPMap: api.AGPL.DERPMap(),
724+
DERPForceWebSockets: api.DeploymentValues.DERP.Config.ForceWebSockets.Value(),
725+
SiblingReplicas: siblingsRes,
725726
})
726727

727728
go api.forceWorkspaceProxyHealthUpdate(api.ctx)

enterprise/wsproxy/wsproxy.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"reflect"
1212
"regexp"
1313
"strings"
14+
"sync/atomic"
1415
"time"
1516

1617
"github.com/go-chi/chi/v5"
@@ -121,7 +122,7 @@ type Server struct {
121122

122123
// DERP
123124
derpMesh *derpmesh.Mesh
124-
latestDERPMap *tailcfg.DERPMap
125+
latestDERPMap atomic.Pointer[tailcfg.DERPMap]
125126

126127
// Used for graceful shutdown. Required for the dialer.
127128
ctx context.Context
@@ -247,8 +248,9 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
247248
s.Logger,
248249
nil,
249250
func() *tailcfg.DERPMap {
250-
return s.latestDERPMap
251+
return s.latestDERPMap.Load()
251252
},
253+
regResp.DERPForceWebSockets,
252254
s.DialCoordinator,
253255
wsconncache.New(s.DialWorkspaceAgent, 0),
254256
s.TracerProvider,
@@ -455,7 +457,7 @@ func (s *Server) handleRegister(_ context.Context, res wsproxysdk.RegisterWorksp
455457
}
456458
s.derpMesh.SetAddresses(addresses, false)
457459

458-
s.latestDERPMap = res.DERPMap
460+
s.latestDERPMap.Store(res.DERPMap)
459461

460462
return nil
461463
}

enterprise/wsproxy/wsproxysdk/wsproxysdk.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ type RegisterWorkspaceProxyRequest struct {
207207
}
208208

209209
type RegisterWorkspaceProxyResponse struct {
210-
AppSecurityKey string `json:"app_security_key"`
211-
DERPMeshKey string `json:"derp_mesh_key"`
212-
DERPRegionID int32 `json:"derp_region_id"`
213-
DERPMap *tailcfg.DERPMap `json:"derp_map"`
210+
AppSecurityKey string `json:"app_security_key"`
211+
DERPMeshKey string `json:"derp_mesh_key"`
212+
DERPRegionID int32 `json:"derp_region_id"`
213+
DERPMap *tailcfg.DERPMap `json:"derp_map"`
214+
DERPForceWebSockets bool `json:"derp_force_websockets"`
214215
// SiblingReplicas is a list of all other replicas of the proxy that have
215216
// not timed out.
216217
SiblingReplicas []codersdk.Replica `json:"sibling_replicas"`

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy