Skip to content

Commit a0a739f

Browse files
authored
xds: ensure node ID is populated in errors from the server (#8140)
* xds: ensure node ID is populated in errors from the server * xds: cleanup server e2e tests * don't wrap status errors
1 parent 5668c66 commit a0a739f

13 files changed

+1473
-1493
lines changed

internal/testutils/xds/e2e/clientresources.go

-66
Original file line numberDiff line numberDiff line change
@@ -140,72 +140,6 @@ func marshalAny(m proto.Message) *anypb.Any {
140140
return a
141141
}
142142

143-
// filterChainWontMatch returns a filter chain that won't match if running the
144-
// test locally.
145-
func filterChainWontMatch(routeName string, addressPrefix string, srcPorts []uint32) *v3listenerpb.FilterChain {
146-
hcm := &v3httppb.HttpConnectionManager{
147-
RouteSpecifier: &v3httppb.HttpConnectionManager_Rds{
148-
Rds: &v3httppb.Rds{
149-
ConfigSource: &v3corepb.ConfigSource{
150-
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{Ads: &v3corepb.AggregatedConfigSource{}},
151-
},
152-
RouteConfigName: routeName,
153-
},
154-
},
155-
HttpFilters: []*v3httppb.HttpFilter{RouterHTTPFilter},
156-
}
157-
return &v3listenerpb.FilterChain{
158-
Name: routeName + "-wont-match",
159-
FilterChainMatch: &v3listenerpb.FilterChainMatch{
160-
PrefixRanges: []*v3corepb.CidrRange{
161-
{
162-
AddressPrefix: addressPrefix,
163-
PrefixLen: &wrapperspb.UInt32Value{
164-
Value: uint32(0),
165-
},
166-
},
167-
},
168-
SourceType: v3listenerpb.FilterChainMatch_SAME_IP_OR_LOOPBACK,
169-
SourcePorts: srcPorts,
170-
SourcePrefixRanges: []*v3corepb.CidrRange{
171-
{
172-
AddressPrefix: addressPrefix,
173-
PrefixLen: &wrapperspb.UInt32Value{
174-
Value: uint32(0),
175-
},
176-
},
177-
},
178-
},
179-
Filters: []*v3listenerpb.Filter{
180-
{
181-
Name: "filter-1",
182-
ConfigType: &v3listenerpb.Filter_TypedConfig{TypedConfig: marshalAny(hcm)},
183-
},
184-
},
185-
}
186-
}
187-
188-
// ListenerResourceThreeRouteResources returns a listener resource that points
189-
// to three route configurations. Only the filter chain that points to the first
190-
// route config can be matched to.
191-
func ListenerResourceThreeRouteResources(host string, port uint32, secLevel SecurityLevel, routeName string) *v3listenerpb.Listener {
192-
lis := defaultServerListenerCommon(host, port, secLevel, routeName, false)
193-
lis.FilterChains = append(lis.FilterChains, filterChainWontMatch("routeName2", "1.1.1.1", []uint32{1}))
194-
lis.FilterChains = append(lis.FilterChains, filterChainWontMatch("routeName3", "2.2.2.2", []uint32{2}))
195-
return lis
196-
}
197-
198-
// ListenerResourceFallbackToDefault returns a listener resource that contains a
199-
// filter chain that will never get chosen to process traffic and a default
200-
// filter chain. The default filter chain points to routeName2.
201-
func ListenerResourceFallbackToDefault(host string, port uint32, secLevel SecurityLevel) *v3listenerpb.Listener {
202-
lis := defaultServerListenerCommon(host, port, secLevel, "", false)
203-
lis.FilterChains = nil
204-
lis.FilterChains = append(lis.FilterChains, filterChainWontMatch("routeName", "1.1.1.1", []uint32{1}))
205-
lis.DefaultFilterChain = filterChainWontMatch("routeName2", "2.2.2.2", []uint32{2})
206-
return lis
207-
}
208-
209143
// DefaultServerListener returns a basic xds Listener resource to be used on the
210144
// server side. The returned Listener resource contains an inline route
211145
// configuration with the name of routeName.

test/xds/xds_server_rbac_test.go

+32-10
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,13 @@ func (s) TestServerSideXDS_RouteConfiguration(t *testing.T) {
265265
// This Unary Call should match to a route with an incorrect action. Thus,
266266
// this RPC should not go through as per A36, and this call should receive
267267
// an error with codes.Unavailable.
268-
if _, err = client.UnaryCall(ctx, &testpb.SimpleRequest{}); status.Code(err) != codes.Unavailable {
268+
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
269+
if status.Code(err) != codes.Unavailable {
269270
t.Fatalf("client.UnaryCall() = _, %v, want _, error code %s", err, codes.Unavailable)
270271
}
272+
if !strings.Contains(err.Error(), nodeID) {
273+
t.Fatalf("client.UnaryCall() = %v, want xDS node id %q", err, nodeID)
274+
}
271275

272276
// This Streaming Call should match to a route with an incorrect action.
273277
// Thus, this RPC should not go through as per A36, and this call should
@@ -276,8 +280,13 @@ func (s) TestServerSideXDS_RouteConfiguration(t *testing.T) {
276280
if err != nil {
277281
t.Fatalf("StreamingInputCall(_) = _, %v, want <nil>", err)
278282
}
279-
if _, err = stream.CloseAndRecv(); status.Code(err) != codes.Unavailable || !strings.Contains(err.Error(), "the incoming RPC matched to a route that was not of action type non forwarding") {
280-
t.Fatalf("streaming RPC should have been denied")
283+
_, err = stream.CloseAndRecv()
284+
const wantStreamingErr = "the incoming RPC matched to a route that was not of action type non forwarding"
285+
if status.Code(err) != codes.Unavailable || !strings.Contains(err.Error(), wantStreamingErr) {
286+
t.Fatalf("client.StreamingInputCall() = %v, want error with code %s and message %q", err, codes.Unavailable, wantStreamingErr)
287+
}
288+
if !strings.Contains(err.Error(), nodeID) {
289+
t.Fatalf("client.StreamingInputCall() = %v, want xDS node id %q", err, nodeID)
281290
}
282291

283292
// This Full Duplex should not match to a route, and thus should return an
@@ -286,8 +295,13 @@ func (s) TestServerSideXDS_RouteConfiguration(t *testing.T) {
286295
if err != nil {
287296
t.Fatalf("FullDuplexCall(_) = _, %v, want <nil>", err)
288297
}
289-
if _, err = dStream.Recv(); status.Code(err) != codes.Unavailable || !strings.Contains(err.Error(), "the incoming RPC did not match a configured Route") {
290-
t.Fatalf("streaming RPC should have been denied")
298+
_, err = dStream.Recv()
299+
const wantFullDuplexErr = "the incoming RPC did not match a configured Route"
300+
if status.Code(err) != codes.Unavailable || !strings.Contains(err.Error(), wantFullDuplexErr) {
301+
t.Fatalf("client.FullDuplexCall() = %v, want error with code %s and message %q", err, codes.Unavailable, wantFullDuplexErr)
302+
}
303+
if !strings.Contains(err.Error(), nodeID) {
304+
t.Fatalf("client.FullDuplexCall() = %v, want xDS node id %q", err, nodeID)
291305
}
292306
}
293307

@@ -826,7 +840,7 @@ func serverListenerWithBadRouteConfiguration(t *testing.T, host string, port uin
826840
}
827841
}
828842

829-
func (s) TestRBACToggledOn_WithBadRouteConfiguration(t *testing.T) {
843+
func (s) TestRBAC_WithBadRouteConfiguration(t *testing.T) {
830844
managementServer, nodeID, bootstrapContents, xdsResolver := setup.ManagementServerAndResolver(t)
831845

832846
lis, cleanup2 := setupGRPCServer(t, bootstrapContents)
@@ -867,11 +881,19 @@ func (s) TestRBACToggledOn_WithBadRouteConfiguration(t *testing.T) {
867881
defer cc.Close()
868882

869883
client := testgrpc.NewTestServiceClient(cc)
870-
if _, err := client.EmptyCall(ctx, &testpb.Empty{}); status.Code(err) != codes.Unavailable {
871-
t.Fatalf("EmptyCall() returned err with status: %v, if RBAC is disabled all RPC's should proceed as normal", status.Code(err))
884+
_, err = client.EmptyCall(ctx, &testpb.Empty{})
885+
if status.Code(err) != codes.Unavailable {
886+
t.Fatalf("EmptyCall() returned %v, want Unavailable", err)
887+
}
888+
if !strings.Contains(err.Error(), nodeID) {
889+
t.Fatalf("EmptyCall() = %v, want xDS node id %q", err, nodeID)
890+
}
891+
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
892+
if status.Code(err) != codes.Unavailable {
893+
t.Fatalf("UnaryCall() returned %v, want Unavailable", err)
872894
}
873-
if _, err := client.UnaryCall(ctx, &testpb.SimpleRequest{}); status.Code(err) != codes.Unavailable {
874-
t.Fatalf("UnaryCall() returned err with status: %v, if RBAC is disabled all RPC's should proceed as normal", status.Code(err))
895+
if !strings.Contains(err.Error(), nodeID) {
896+
t.Fatalf("UnaryCall() = %v, want xDS node id %q", err, nodeID)
875897
}
876898
}
877899

0 commit comments

Comments
 (0)