Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: reject RDS response containing match with case-sensitive false #3592

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions xds/internal/client/v2client_rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ func getClusterFromRouteConfiguration(rc *xdspb.RouteConfiguration, host string)
return "", fmt.Errorf("matched virtual host has no routes")
}
dr := vh.Routes[len(vh.Routes)-1]
if match := dr.GetMatch(); match == nil || (match.GetPrefix() != "" && match.GetPrefix() != "/") {
match := dr.GetMatch()
if match == nil {
return "", fmt.Errorf("matched virtual host's default route doesn't have a match")
}
if prefix := match.GetPrefix(); prefix != "" && prefix != "/" {
// The matched virtual host is invalid. Match is not "" or "/".
return "", fmt.Errorf("matched virtual host is invalid")
return "", fmt.Errorf("matched virtual host's default route is %v, want Prefix empty string or /", match)
}
if caseSensitive := match.GetCaseSensitive(); caseSensitive != nil && !caseSensitive.Value {
// The case sensitive is set to false. Not set or set to true are both
// valid.
return "", fmt.Errorf("matches virtual host's default route set case-sensitive to false")
}
if route := dr.GetRoute(); route != nil {
return route.GetCluster(), nil
Expand Down
20 changes: 20 additions & 0 deletions xds/internal/client/v2client_rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
xdspb "github.com/envoyproxy/go-control-plane/envoy/api/v2"
routepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/route"
"github.com/golang/protobuf/proto"
wrapperspb "github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc/xds/internal/testutils/fakeserver"
)
Expand Down Expand Up @@ -141,6 +142,25 @@ func (s) TestRDSGetClusterFromRouteConfiguration(t *testing.T) {
wantCluster: "",
wantError: true,
},
{
// default route's match sets case-sensitive to false.
name: "good-route-config-but-with-casesensitive-false",
rc: &xdspb.RouteConfiguration{
Name: goodRouteName1,
VirtualHosts: []*routepb.VirtualHost{{
Domains: []string{goodLDSTarget1},
Routes: []*routepb.Route{{
Match: &routepb.RouteMatch{
PathSpecifier: &routepb.RouteMatch_Prefix{Prefix: "/"},
CaseSensitive: &wrapperspb.BoolValue{Value: false},
},
Action: &routepb.Route_Route{
Route: &routepb.RouteAction{
ClusterSpecifier: &routepb.RouteAction_Cluster{Cluster: goodClusterName1},
}}}}}}},
wantCluster: "",
wantError: true,
},
{
name: "good-route-config-with-empty-string-route",
rc: goodRouteConfig1,
Expand Down