diff --git a/.semgrep/rpc_endpoint.yml b/.semgrep/rpc_endpoint.yml index 6c0c8c0e47c1..29d594756763 100644 --- a/.semgrep/rpc_endpoint.yml +++ b/.semgrep/rpc_endpoint.yml @@ -103,7 +103,6 @@ rules: - pattern-not: '"CSIPlugin.List"' - pattern-not: '"Status.Leader"' - pattern-not: '"Status.Peers"' - - pattern-not: '"Status.RPCServers"' - pattern-not: '"Status.Version"' message: "RPC method $METHOD appears to be unauthenticated" languages: diff --git a/nomad/status_endpoint.go b/nomad/status_endpoint.go index 5f049c42cb5f..f5b53a5c99c1 100644 --- a/nomad/status_endpoint.go +++ b/nomad/status_endpoint.go @@ -78,33 +78,6 @@ func (s *Status) Peers(args *structs.GenericRequest, reply *[]string) error { return nil } -// RPCServers is used to get all the RPC server addresses in a region -func (s *Status) RPCServers(args *structs.GenericRequest, reply *structs.RPCServersResponse) error { - // note: we're intentionally throwing away any auth error here and only - // authenticate so that we can measure rate metrics - s.srv.Authenticate(s.ctx, args) - s.srv.MeasureRPCRate("status", structs.RateMetricList, args) - - if args.Region == "" { - args.Region = s.srv.config.Region - } - if done, err := s.srv.forward("Status.RPCServers", args, args, reply); done { - return err - } - - future := s.srv.raft.GetConfiguration() - if err := future.Error(); err != nil { - return err - } - - for _, server := range future.Configuration().Servers { - if peer, ok := s.srv.localPeers[server.Address]; ok { - reply.Addresses = append(reply.Addresses, peer.RPCAddr.String()) - } - } - return nil -} - // Members return the list of servers in a cluster that a particular server is // aware of func (s *Status) Members(args *structs.GenericRequest, reply *structs.ServerMembersResponse) error { diff --git a/nomad/status_endpoint_test.go b/nomad/status_endpoint_test.go index c0009ce9e7d1..805fbad5cdbb 100644 --- a/nomad/status_endpoint_test.go +++ b/nomad/status_endpoint_test.go @@ -1,12 +1,9 @@ package nomad import ( - "fmt" - "net" "testing" msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" - "github.com/shoenig/test/must" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -77,54 +74,6 @@ func TestStatusPeers(t *testing.T) { } } -func TestStatus_RPCServers(t *testing.T) { - ci.Parallel(t) - - advAddr1 := "127.0.1.1:1234" - adv1, err := net.ResolveTCPAddr("tcp", advAddr1) - must.NoError(t, err) - - s1, cleanupS1 := TestServer(t, func(c *Config) { - c.Region = "region1" - c.ClientRPCAdvertise = adv1 - }) - defer cleanupS1() - - s2, cleanupS2 := TestServer(t, func(c *Config) { - c.Region = "region2" - }) - defer cleanupS2() - - // Join them together - s2Addr := fmt.Sprintf("127.0.0.1:%d", s2.config.SerfConfig.MemberlistConfig.BindPort) - n, err := s1.Join([]string{s2Addr}) - must.NoError(t, err, must.Sprintf("Failed joining: %v (%d joined)", err, n)) - - codec := rpcClient(t, s1) - - t.Run("own region", func(t *testing.T) { - arg := &structs.GenericRequest{ - QueryOptions: structs.QueryOptions{Region: "region1"}, - } - var resp *structs.RPCServersResponse - must.NoError(t, msgpackrpc.CallWithCodec(codec, "Status.RPCServers", arg, &resp)) - must.NotNil(t, resp) - must.Len(t, 1, resp.Addresses) - must.Eq(t, advAddr1, resp.Addresses[0]) - }) - - t.Run("other region", func(t *testing.T) { - arg := &structs.GenericRequest{ - QueryOptions: structs.QueryOptions{Region: "region2"}, - } - var resp *structs.RPCServersResponse - must.NoError(t, msgpackrpc.CallWithCodec(codec, "Status.RPCServers", arg, &resp)) - must.NotNil(t, resp) - must.Len(t, 1, resp.Addresses) - must.Eq(t, s2.clientRpcAdvertise.String(), resp.Addresses[0]) - }) -} - func TestStatusMembers(t *testing.T) { ci.Parallel(t) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 71828e299fcd..91f6db052abd 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1171,11 +1171,6 @@ type PeriodicForceRequest struct { WriteRequest } -// RPCServersResponse contains the list of RPC addresses for servers in this region -type RPCServersResponse struct { - Addresses []string -} - // ServerMembersResponse has the list of servers in a cluster type ServerMembersResponse struct { ServerName string