Skip to content

Commit f4a20d2

Browse files
authored
xds: NACK more invalid RDS responses (#4120)
1 parent 53788aa commit f4a20d2

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

xds/internal/client/client_rds_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,70 @@ func (s) TestRoutesProtoToSlice(t *testing.T) {
707707
}},
708708
wantErr: false,
709709
},
710+
{
711+
name: "unrecognized path specifier",
712+
routes: []*v3routepb.Route{
713+
{
714+
Match: &v3routepb.RouteMatch{
715+
PathSpecifier: &v3routepb.RouteMatch_ConnectMatcher_{},
716+
},
717+
},
718+
},
719+
wantErr: true,
720+
},
721+
{
722+
name: "unrecognized header match specifier",
723+
routes: []*v3routepb.Route{
724+
{
725+
Match: &v3routepb.RouteMatch{
726+
PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/a/"},
727+
Headers: []*v3routepb.HeaderMatcher{
728+
{
729+
Name: "th",
730+
HeaderMatchSpecifier: &v3routepb.HeaderMatcher_HiddenEnvoyDeprecatedRegexMatch{},
731+
},
732+
},
733+
},
734+
},
735+
},
736+
wantErr: true,
737+
},
738+
{
739+
name: "no cluster in weighted clusters action",
740+
routes: []*v3routepb.Route{
741+
{
742+
Match: &v3routepb.RouteMatch{
743+
PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/a/"},
744+
},
745+
Action: &v3routepb.Route_Route{
746+
Route: &v3routepb.RouteAction{
747+
ClusterSpecifier: &v3routepb.RouteAction_WeightedClusters{
748+
WeightedClusters: &v3routepb.WeightedCluster{}}}},
749+
},
750+
},
751+
wantErr: true,
752+
},
753+
{
754+
name: "all 0-weight clusters in weighted clusters action",
755+
routes: []*v3routepb.Route{
756+
{
757+
Match: &v3routepb.RouteMatch{
758+
PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/a/"},
759+
},
760+
Action: &v3routepb.Route_Route{
761+
Route: &v3routepb.RouteAction{
762+
ClusterSpecifier: &v3routepb.RouteAction_WeightedClusters{
763+
WeightedClusters: &v3routepb.WeightedCluster{
764+
Clusters: []*v3routepb.WeightedCluster_ClusterWeight{
765+
{Name: "B", Weight: &wrapperspb.UInt32Value{Value: 0}},
766+
{Name: "A", Weight: &wrapperspb.UInt32Value{Value: 0}},
767+
},
768+
TotalWeight: &wrapperspb.UInt32Value{Value: 0},
769+
}}}},
770+
},
771+
},
772+
wantErr: true,
773+
},
710774
}
711775

712776
cmpOpts := []cmp.Option{

xds/internal/client/client_xds.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger)
272272
case *v3routepb.RouteMatch_SafeRegex:
273273
route.Regex = &pt.SafeRegex.Regex
274274
default:
275-
logger.Warningf("route %+v has an unrecognized path specifier: %+v", r, pt)
276-
continue
275+
return nil, fmt.Errorf("route %+v has an unrecognized path specifier: %+v", r, pt)
277276
}
278277

279278
if caseSensitive := match.GetCaseSensitive(); caseSensitive != nil {
@@ -299,8 +298,7 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger)
299298
case *v3routepb.HeaderMatcher_SuffixMatch:
300299
header.SuffixMatch = &ht.SuffixMatch
301300
default:
302-
logger.Warningf("route %+v has an unrecognized header matcher: %+v", r, ht)
303-
continue
301+
return nil, fmt.Errorf("route %+v has an unrecognized header matcher: %+v", r, ht)
304302
}
305303
header.Name = h.GetName()
306304
invert := h.GetInvertMatch()
@@ -331,12 +329,18 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger)
331329
var totalWeight uint32
332330
for _, c := range wcs.Clusters {
333331
w := c.GetWeight().GetValue()
332+
if w == 0 {
333+
continue
334+
}
334335
clusters[c.GetName()] = w
335336
totalWeight += w
336337
}
337338
if totalWeight != wcs.GetTotalWeight().GetValue() {
338339
return nil, fmt.Errorf("route %+v, action %+v, weights of clusters do not add up to total total weight, got: %v, want %v", r, a, wcs.GetTotalWeight().GetValue(), totalWeight)
339340
}
341+
if totalWeight == 0 {
342+
return nil, fmt.Errorf("route %+v, action %+v, has no valid cluster in WeightedCluster action", r, a)
343+
}
340344
case *v3routepb.RouteAction_ClusterHeader:
341345
continue
342346
}

0 commit comments

Comments
 (0)