Skip to content

Commit 4974777

Browse files
committed
fix: revert "direct embedded derp traffic directly to the server"
Not sure why this is breaking deployments, but it seems likely to be the cause. See #6746.
1 parent dab4a0e commit 4974777

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

coderd/coderdtest/coderdtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
259259
stunAddr, stunCleanup := stuntest.ServeWithPacketListener(t, nettype.Std{})
260260
t.Cleanup(stunCleanup)
261261

262-
derpServer := derp.NewServer(key.NewNode(), tailnet.Logger(slogtest.Make(t, nil).Named("derp").Leveled(slog.LevelDebug)))
262+
derpServer := derp.NewServer(key.NewNode(), tailnet.Logger(slogtest.Make(t, nil).Named("derp")))
263263
derpServer.SetMeshKey("test-key")
264264

265265
// match default with cli default

coderd/workspaceagents.go

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package coderd
22

33
import (
4-
"bufio"
54
"context"
65
"database/sql"
76
"encoding/json"
@@ -418,29 +417,51 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*
418417
ctx := r.Context()
419418
clientConn, serverConn := net.Pipe()
420419

420+
derpMap := api.DERPMap.Clone()
421+
for _, region := range derpMap.Regions {
422+
if !region.EmbeddedRelay {
423+
continue
424+
}
425+
var node *tailcfg.DERPNode
426+
for _, n := range region.Nodes {
427+
if n.STUNOnly {
428+
continue
429+
}
430+
node = n
431+
break
432+
}
433+
if node == nil {
434+
continue
435+
}
436+
// TODO: This should dial directly to execute the
437+
// DERP server instead of contacting localhost.
438+
//
439+
// This requires modification of Tailscale internals
440+
// to pipe through a proxy function per-region, so
441+
// this is an easy and mostly reliable hack for now.
442+
cloned := node.Clone()
443+
// Add p for proxy.
444+
// This first node supports TLS.
445+
cloned.Name += "p"
446+
cloned.IPv4 = "127.0.0.1"
447+
cloned.InsecureForTests = true
448+
region.Nodes = append(region.Nodes, cloned.Clone())
449+
// This second node forces HTTP.
450+
cloned.Name += "-http"
451+
cloned.ForceHTTP = true
452+
region.Nodes = append(region.Nodes, cloned)
453+
}
454+
421455
conn, err := tailnet.NewConn(&tailnet.Options{
422456
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
423-
DERPMap: api.DERPMap,
457+
DERPMap: derpMap,
424458
Logger: api.Logger.Named("tailnet"),
425459
})
426460
if err != nil {
427461
_ = clientConn.Close()
428462
_ = serverConn.Close()
429463
return nil, xerrors.Errorf("create tailnet conn: %w", err)
430464
}
431-
conn.SetDERPRegionDialer(func(_ context.Context, region *tailcfg.DERPRegion) net.Conn {
432-
if !region.EmbeddedRelay {
433-
return nil
434-
}
435-
left, right := net.Pipe()
436-
go func() {
437-
defer left.Close()
438-
defer right.Close()
439-
brw := bufio.NewReadWriter(bufio.NewReader(right), bufio.NewWriter(right))
440-
api.DERPServer.Accept(ctx, right, brw, r.RemoteAddr)
441-
}()
442-
return left
443-
})
444465

445466
sendNodes, _ := tailnet.ServeCoordinator(clientConn, func(node []*tailnet.Node) error {
446467
err = conn.UpdateNodes(node, true)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ replace github.com/tcnksm/go-httpstat => github.com/kylecarbs/go-httpstat v0.0.0
4040

4141
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
4242
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
43-
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20230321171725-fed359a0cafa
43+
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20230307022319-1e5e724a3949
4444

4545
// Switch to our fork that imports fixes from http://github.com/tailscale/ssh.
4646
// See: https://github.com/coder/coder/issues/3371

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,12 @@ github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d h1:09JG37IgTB6n3ouX9
378378
github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d/go.mod h1:r+1J5i/989wt6CUeNSuvFKKA9hHuKKPMxdzDbTuvwwk=
379379
github.com/coder/ssh v0.0.0-20220811105153-fcea99919338 h1:tN5GKFT68YLVzJoA8AHuiMNJ0qlhoD3pGN3JY9gxSko=
380380
github.com/coder/ssh v0.0.0-20220811105153-fcea99919338/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
381-
github.com/coder/tailscale v1.1.1-0.20230321171725-fed359a0cafa h1:EjRGgTz7BUECmbV8jHTi1/rKdDjJESGSlm1Jp7evvCQ=
382-
github.com/coder/tailscale v1.1.1-0.20230321171725-fed359a0cafa/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
381+
github.com/coder/tailscale v1.1.1-0.20230307022319-1e5e724a3949 h1:8WfMfRTDaEpnmhCJWfFQ7JHz19GyP+EgFgLGu5ngdek=
382+
github.com/coder/tailscale v1.1.1-0.20230307022319-1e5e724a3949/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
383+
github.com/coder/terraform-provider-coder v0.6.15 h1:Llvh4RwxSQ/goy7ToTOeHf3tdEz+79qbyOh61hNnJs0=
384+
github.com/coder/terraform-provider-coder v0.6.15/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
385+
github.com/coder/terraform-provider-coder v0.6.17 h1:YvjM5nQx5RO+gXsYIv++CkiWCuJueQdJaPrsjnkZ4XQ=
386+
github.com/coder/terraform-provider-coder v0.6.17/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
383387
github.com/coder/terraform-provider-coder v0.6.21 h1:TIH6+/VQFreT8q/CkRvpHtbIeM5cOAhuDS5Sh1Nm21Q=
384388
github.com/coder/terraform-provider-coder v0.6.21/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
385389
github.com/coder/wgtunnel v0.1.5 h1:WP3sCj/3iJ34eKvpMQEp1oJHvm24RYh0NHbj1kfUKfs=

tailnet/conn.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,6 @@ func (c *Conn) SetDERPMap(derpMap *tailcfg.DERPMap) {
355355
c.wireguardEngine.SetNetworkMap(&netMapCopy)
356356
}
357357

358-
// SetDERPRegionDialer updates the dialer to use for connecting to DERP regions.
359-
func (c *Conn) SetDERPRegionDialer(dialer func(ctx context.Context, region *tailcfg.DERPRegion) net.Conn) {
360-
c.magicConn.SetDERPRegionDialer(dialer)
361-
}
362-
363358
func (c *Conn) RemoveAllPeers() error {
364359
c.mutex.Lock()
365360
defer c.mutex.Unlock()

0 commit comments

Comments
 (0)