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: make channel creds required in bootstrap file #7396

Merged
merged 4 commits into from Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions xds/src/main/java/io/grpc/xds/Bootstrapper.java
Expand Up @@ -101,19 +101,19 @@ public static BootstrapInfo parseConfig(String rawData) throws IOException {
logger.log(XdsLogLevel.INFO, "xDS server URI: {0}", serverUri);
List<ChannelCreds> channelCredsOptions = new ArrayList<>();
List<?> rawChannelCredsList = JsonUtil.getList(serverConfig, "channel_creds");
// List of channel creds is optional.
if (rawChannelCredsList != null) {
List<Map<String, ?>> channelCredsList = JsonUtil.checkObjectList(rawChannelCredsList);
for (Map<String, ?> channelCreds : channelCredsList) {
String type = JsonUtil.getString(channelCreds, "type");
if (type == null) {
throw new IOException("Invalid bootstrap: 'xds_servers' contains server with "
+ "unknown type 'channel_creds'.");
}
logger.log(XdsLogLevel.INFO, "Channel credentials option: {0}", type);
ChannelCreds creds = new ChannelCreds(type, JsonUtil.getObject(channelCreds, "config"));
channelCredsOptions.add(creds);
if (rawChannelCredsList == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about?

if (rawChannelCredsList == null || rawChannelCredsList.isEmpty())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair. Updated to not allow empty list.

throw new IOException("Invalid bootstrap: 'channel_creds' required");
}
List<Map<String, ?>> channelCredsList = JsonUtil.checkObjectList(rawChannelCredsList);
for (Map<String, ?> channelCreds : channelCredsList) {
String type = JsonUtil.getString(channelCreds, "type");
if (type == null) {
throw new IOException("Invalid bootstrap: 'xds_servers' contains server with "
+ "unknown type 'channel_creds'.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case of type not being set as opposed to "unknown type".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean here is for "type unspecified". Reading bootstrap file should not contain the logic for interpreting the type that gRPC supports, that should be done at the time when the channel creds is actually used.

Say the bootstrap file provides 100 channel creds options, the parser should not try to look up and check one by one. Only at the time this information is used, it would interpret it: going through the list to find the first one that gRPC supports. If none can be found, the gRPC client fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to see "unknown type" while type not provided.

"unknown type" sounds more like user provides a type but it's not recognized.

"with type unspecified" might be more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed the message.

}
logger.log(XdsLogLevel.INFO, "Channel credentials option: {0}", type);
ChannelCreds creds = new ChannelCreds(type, JsonUtil.getObject(channelCreds, "config"));
channelCredsOptions.add(creds);
}
List<String> serverFeatures = JsonUtil.getListOfStrings(serverConfig, "server_features");
if (serverFeatures != null) {
Expand Down
11 changes: 9 additions & 2 deletions xds/src/test/java/io/grpc/xds/BootstrapperTest.java
Expand Up @@ -24,6 +24,7 @@
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.GrpcUtil.GrpcBuildVersion;
import io.grpc.xds.Bootstrapper.BootstrapInfo;
import io.grpc.xds.Bootstrapper.ChannelCreds;
import io.grpc.xds.Bootstrapper.ServerInfo;
import io.grpc.xds.EnvoyProtoData.Locality;
import io.grpc.xds.EnvoyProtoData.Node;
Expand Down Expand Up @@ -234,7 +235,10 @@ public void parseBootstrap_minimalUsableData() throws IOException {
String rawData = "{\n"
+ " \"xds_servers\": [\n"
+ " {\n"
+ " \"server_uri\": \"trafficdirector.googleapis.com:443\"\n"
+ " \"server_uri\": \"trafficdirector.googleapis.com:443\",\n"
+ " \"channel_creds\": [\n"
+ " {\"type\": \"insecure\"}\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ "}";
Expand All @@ -243,7 +247,10 @@ public void parseBootstrap_minimalUsableData() throws IOException {
assertThat(info.getServers()).hasSize(1);
ServerInfo serverInfo = Iterables.getOnlyElement(info.getServers());
assertThat(serverInfo.getServerUri()).isEqualTo("trafficdirector.googleapis.com:443");
assertThat(serverInfo.getChannelCredentials()).isEmpty();
assertThat(serverInfo.getChannelCredentials()).hasSize(1);
ChannelCreds creds = Iterables.getOnlyElement(serverInfo.getChannelCredentials());
assertThat(creds.getType()).isEqualTo("insecure");
assertThat(creds.getConfig()).isNull();
assertThat(info.getNode()).isEqualTo(getNodeBuilder().build());
}

Expand Down