Skip to content

Commit 36f3151

Browse files
authored
fix(enterprise/tailnet): properly detect legacy agents (#10083)
1 parent 03a7d2f commit 36f3151

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

enterprise/tailnet/pgcoord.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net"
99
"net/http"
10+
"net/netip"
1011
"strings"
1112
"sync"
1213
"time"
@@ -143,10 +144,27 @@ func NewPGCoord(ctx context.Context, logger slog.Logger, ps pubsub.Pubsub, store
143144
return c, nil
144145
}
145146

147+
// This is copied from codersdk because importing it here would cause an import
148+
// cycle. This is just temporary until wsconncache is phased out.
149+
var legacyAgentIP = netip.MustParseAddr("fd7a:115c:a1e0:49d6:b259:b7ac:b1b2:48f4")
150+
146151
func (c *pgCoord) ServeMultiAgent(id uuid.UUID) agpl.MultiAgentConn {
147152
ma := (&agpl.MultiAgent{
148-
ID: id,
149-
AgentIsLegacyFunc: func(agentID uuid.UUID) bool { return true },
153+
ID: id,
154+
AgentIsLegacyFunc: func(agentID uuid.UUID) bool {
155+
if n := c.Node(agentID); n == nil {
156+
// If we don't have the node at all assume it's legacy for
157+
// safety.
158+
return true
159+
} else if len(n.Addresses) > 0 && n.Addresses[0].Addr() == legacyAgentIP {
160+
// An agent is determined to be "legacy" if it's first IP is the
161+
// legacy IP. Agents with only the legacy IP aren't compatible
162+
// with single_tailnet and must be routed through wsconncache.
163+
return true
164+
} else {
165+
return false
166+
}
167+
},
150168
OnSubscribe: func(enq agpl.Queue, agent uuid.UUID) (*agpl.Node, error) {
151169
err := c.addSubscription(enq, agent)
152170
return c.Node(agent), err

0 commit comments

Comments
 (0)