Skip to content

Commit

Permalink
Permit routing to agentless nodes with non-UUID metadata.name
Browse files Browse the repository at this point in the history
We suggest that a UUID is used for agentless nodes metadata.name
field, but we do not enforce it. This causes several edge cases
and slightly weird UX in places that expect the name to be a UUID.
Most notably, this presents dialing problems for the web ui as
described in #50914.
To allowing dialing to function in all cases for these servers,
routing has been updated to permit matches on metadata.name, however,
the match is given a lower score then a match on a UUID. This should
permit dialing, though, it may still result in ambiguity.

Closes #50914.
  • Loading branch information
rosstimothy committed Jan 9, 2025
1 parent 588d024 commit 1c92537
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
8 changes: 8 additions & 0 deletions api/utils/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ func (m *SSHRouteMatcher) RouteToServerScore(server RouteableServer) (score int)
score = max(score, matchAddr(addr))
}

// Allow a match on name, even though it may not be a UUID or EC2 ID,
// to support agentless hosts that were created without their name being a UUID.
// The score however, is lower than a true direct match, to prevent any
// breaking changes to routing.
if server.GetName() == m.cfg.Host {
score = max(score, indirectMatch)
}

return score
}

Expand Down
15 changes: 14 additions & 1 deletion api/utils/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package utils

import (
"cmp"
"context"
"testing"

Expand Down Expand Up @@ -273,6 +274,7 @@ func TestSSHRouteMatcherScoring(t *testing.T) {
tts := []struct {
desc string
hostname string
name string
addrs []string
score int
}{
Expand Down Expand Up @@ -309,12 +311,23 @@ func TestSSHRouteMatcherScoring(t *testing.T) {
},
score: notMatch,
},
{
desc: "non-uuid name",
name: "foo.example.com",
hostname: "foo.com",
addrs: []string{
"0.0.0.0:0",
"1.1.1.1:0",
},
score: indirectMatch,
},
}

for _, tt := range tts {
t.Run(tt.desc, func(t *testing.T) {
name := cmp.Or(tt.name, uuid.NewString())
score := matcher.RouteToServerScore(mockRouteableServer{
name: uuid.NewString(),
name: name,
hostname: tt.hostname,
publicAddr: tt.addrs,
})
Expand Down
47 changes: 37 additions & 10 deletions lib/proxy/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func TestRouteScoring(t *testing.T) {
hostname: "blue.example.com",
addr: "2.3.4.5:22",
},
{
name: "not-a-uuid",
hostname: "test.example.com",
addr: "3.4.5.6:22",
},
})

// scoring behavior is independent of routing strategy so we just
Expand Down Expand Up @@ -205,6 +210,11 @@ func TestRouteScoring(t *testing.T) {
host: "red.example.com",
expect: "blue.example.com",
},
{
desc: "non-uuid name",
host: "not-a-uuid",
expect: "test.example.com",
},
}

for _, tt := range tts {
Expand Down Expand Up @@ -326,6 +336,21 @@ func TestGetServers(t *testing.T) {
},
})

servers = append(servers,
&types.ServerV2{
Kind: types.KindNode,
SubKind: types.SubKindOpenSSHNode,
Version: types.V2,
Metadata: types.Metadata{
Name: "agentless-node-1",
},
Spec: types.ServerSpecV2{
Addr: "1.2.3.4:22",
Hostname: "agentless-1",
},
},
)

// ensure tests don't have order-dependence
rand.Shuffle(len(servers), func(i, j int) {
servers[i], servers[j] = servers[j], servers[i]
Expand Down Expand Up @@ -432,15 +457,6 @@ func TestGetServers(t *testing.T) {
require.Equal(t, "alpaca", srv.GetHostname())
},
},
{
name: "failure on invalid addresses",
site: testSite{cfg: &unambiguousCfg, nodes: servers},
host: "lion",
errAssertion: require.NoError,
serverAssertion: func(t *testing.T, srv types.Server) {
require.Empty(t, srv)
},
},
{
name: "case-insensitive match",
site: testSite{cfg: &unambiguousInsensitiveCfg, nodes: servers},
Expand All @@ -462,6 +478,17 @@ func TestGetServers(t *testing.T) {
require.Empty(t, srv)
},
},
{
name: "agentless match by non-uuid name",
site: testSite{cfg: &unambiguousCfg, nodes: servers},
host: "agentless-node-1",
errAssertion: require.NoError,
serverAssertion: func(t *testing.T, srv types.Server) {
require.NotNil(t, srv)
require.Equal(t, "agentless-1", srv.GetHostname())
require.True(t, srv.IsOpenSSHNode())
},
},
}

ctx := context.Background()
Expand Down Expand Up @@ -625,7 +652,7 @@ func TestRouter_DialHost(t *testing.T) {
SubKind: types.SubKindOpenSSHNode,
Version: types.V2,
Metadata: types.Metadata{
Name: uuid.NewString(),
Name: "agentless",
},
Spec: types.ServerSpecV2{
Addr: "127.0.0.1:9001",
Expand Down

0 comments on commit 1c92537

Please sign in to comment.