xds: Unexpected types in server_features should be ignored

It was clearly defined in gRFC A30. The relevant text was copied as a
comment in the code.

As discovered due to grpc/grpc-go#7932
This commit is contained in:
Eric Anderson 2024-12-13 15:54:19 -08:00
parent 3b39a83621
commit e8ff6da2cf
2 changed files with 23 additions and 1 deletions

View File

@ -248,7 +248,9 @@ public abstract class BootstrapperImpl extends Bootstrapper {
Object implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri); Object implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri);
boolean ignoreResourceDeletion = false; boolean ignoreResourceDeletion = false;
List<String> serverFeatures = JsonUtil.getListOfStrings(serverConfig, "server_features"); // "For forward compatibility reasons, the client will ignore any entry in the list that it
// does not understand, regardless of type."
List<?> serverFeatures = JsonUtil.getList(serverConfig, "server_features");
if (serverFeatures != null) { if (serverFeatures != null) {
logger.log(XdsLogLevel.INFO, "Server features: {0}", serverFeatures); logger.log(XdsLogLevel.INFO, "Server features: {0}", serverFeatures);
ignoreResourceDeletion = serverFeatures.contains(SERVER_FEATURE_IGNORE_RESOURCE_DELETION); ignoreResourceDeletion = serverFeatures.contains(SERVER_FEATURE_IGNORE_RESOURCE_DELETION);

View File

@ -676,6 +676,26 @@ public class GrpcBootstrapperImplTest {
assertThat(serverInfo.ignoreResourceDeletion()).isTrue(); assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
} }
@Test
public void serverFeatures_ignoresUnknownValues() throws XdsInitializationException {
String rawData = "{\n"
+ " \"xds_servers\": [\n"
+ " {\n"
+ " \"server_uri\": \"" + SERVER_URI + "\",\n"
+ " \"channel_creds\": [\n"
+ " {\"type\": \"insecure\"}\n"
+ " ],\n"
+ " \"server_features\": [null, {}, 3, true, \"unexpected\", \"trusted_xds_server\"]\n"
+ " }\n"
+ " ]\n"
+ "}";
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
BootstrapInfo info = bootstrapper.bootstrap();
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
assertThat(serverInfo.isTrustedXdsServer()).isTrue();
}
@Test @Test
public void notFound() { public void notFound() {
bootstrapper.bootstrapPathFromEnvVar = null; bootstrapper.bootstrapPathFromEnvVar = null;