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 aggregate cluster with empty cluster list #32238

Merged
merged 1 commit into from
Feb 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/ext/xds/xds_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ XdsClusterResource::Aggregate AggregateClusterParse(
const upb_StringView* clusters =
envoy_extensions_clusters_aggregate_v3_ClusterConfig_clusters(
aggregate_cluster_config, &size);
if (size == 0) {
ValidationErrors::ScopedField field(errors, ".clusters");
errors->AddError("must be non-empty");
}
for (size_t i = 0; i < size; ++i) {
aggregate.prioritized_cluster_names.emplace_back(
UpbStringToStdString(clusters[i]));
Expand Down
23 changes: 23 additions & 0 deletions test/core/xds/xds_cluster_resource_type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,29 @@ TEST_F(ClusterTypeTest, AggregateClusterUnparseableProto) {
<< decode_result.resource.status();
}

TEST_F(ClusterTypeTest, AggregateClusterEmptyClusterList) {
Cluster cluster;
cluster.set_name("foo");
cluster.mutable_cluster_type()->set_name("envoy.clusters.aggregate");
cluster.mutable_cluster_type()->mutable_typed_config()->PackFrom(
ClusterConfig());
std::string serialized_resource;
ASSERT_TRUE(cluster.SerializeToString(&serialized_resource));
auto* resource_type = XdsClusterResourceType::Get();
auto decode_result =
resource_type->Decode(decode_context_, serialized_resource);
ASSERT_TRUE(decode_result.name.has_value());
EXPECT_EQ(*decode_result.name, "foo");
EXPECT_EQ(decode_result.resource.status().code(),
absl::StatusCode::kInvalidArgument);
EXPECT_EQ(decode_result.resource.status().message(),
"errors validating Cluster resource: ["
"field:cluster_type.typed_config.value["
"envoy.extensions.clusters.aggregate.v3.ClusterConfig].clusters "
"error:must be non-empty]")
<< decode_result.resource.status();
}

//
// LB policy tests
//
Expand Down