Skip to content

Commit

Permalink
xds: fix the transport-socket-name to match what control plane sends (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaypujare committed Oct 12, 2020
1 parent 46290ef commit b08ce41
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions xds/src/main/java/io/grpc/xds/EnvoyProtoData.java
Expand Up @@ -61,6 +61,7 @@
*/
// TODO(chengyuanzhang): put data types into smaller categories.
final class EnvoyProtoData {
static final String TRANSPORT_SOCKET_NAME_TLS = "envoy.transport_sockets.tls";

// Prevent instantiation.
private EnvoyProtoData() {
Expand Down
4 changes: 3 additions & 1 deletion xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java
Expand Up @@ -16,6 +16,8 @@

package io.grpc.xds;

import static io.grpc.xds.EnvoyProtoData.TRANSPORT_SOCKET_NAME_TLS;

import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.Any;
import com.google.protobuf.InvalidProtocolBufferException;
Expand Down Expand Up @@ -295,7 +297,7 @@ private static DownstreamTlsContext getTlsContextFromFilterChain(
io.envoyproxy.envoy.config.listener.v3.FilterChain filterChain)
throws InvalidProtocolBufferException {
if (filterChain.hasTransportSocket()
&& "tls".equals(filterChain.getTransportSocket().getName())) {
&& TRANSPORT_SOCKET_NAME_TLS.equals(filterChain.getTransportSocket().getName())) {
Any any = filterChain.getTransportSocket().getTypedConfig();
return DownstreamTlsContext.fromEnvoyProtoDownstreamTlsContext(
io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext.parseFrom(
Expand Down
4 changes: 3 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsClientImpl2.java
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static io.grpc.xds.EnvoyProtoData.TRANSPORT_SOCKET_NAME_TLS;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
Expand Down Expand Up @@ -783,7 +784,8 @@ private void handleCdsResponse(DiscoveryResponseData cdsResponse) {
@Nullable
private static EnvoyServerProtoData.UpstreamTlsContext getTlsContextFromCluster(Cluster cluster)
throws InvalidProtocolBufferException {
if (cluster.hasTransportSocket() && "tls".equals(cluster.getTransportSocket().getName())) {
if (cluster.hasTransportSocket()
&& TRANSPORT_SOCKET_NAME_TLS.equals(cluster.getTransportSocket().getName())) {
Any any = cluster.getTransportSocket().getTypedConfig();
return EnvoyServerProtoData.UpstreamTlsContext.fromEnvoyProtoUpstreamTlsContext(
any.unpack(UpstreamTlsContext.class));
Expand Down
Expand Up @@ -118,7 +118,7 @@ private static FilterChain createInFilter() {
.build())
.addApplicationProtocols("managed-mtls")
.build())
.setTransportSocket(TransportSocket.newBuilder().setName("tls")
.setTransportSocket(TransportSocket.newBuilder().setName("envoy.transport_sockets.tls")
.setTypedConfig(
Any.pack(CommonTlsContextTestsUtil.buildTestDownstreamTlsContext(
"google-sds-config-default", "ROOTCA")))
Expand Down
16 changes: 9 additions & 7 deletions xds/src/test/java/io/grpc/xds/XdsClientImplTestForListener.java
Expand Up @@ -786,15 +786,17 @@ static Listener buildListenerWithFilterChain(String name, int portValue, String
@SuppressWarnings("deprecation")
static FilterChain buildFilterChain(FilterChainMatch filterChainMatch,
DownstreamTlsContext tlsContext, Filter...filters) {
return
FilterChain.newBuilder()
.setFilterChainMatch(filterChainMatch)
.setTransportSocket(tlsContext == null
return FilterChain.newBuilder()
.setFilterChainMatch(filterChainMatch)
.setTransportSocket(
tlsContext == null
? TransportSocket.getDefaultInstance()
: TransportSocket.newBuilder().setName("tls").setTypedConfig(Any.pack(tlsContext))
: TransportSocket.newBuilder()
.setName("envoy.transport_sockets.tls")
.setTypedConfig(Any.pack(tlsContext))
.build())
.addAllFilters(Arrays.asList(filters))
.build();
.addAllFilters(Arrays.asList(filters))
.build();
}

static FilterChainMatch buildFilterChainMatch(int destPort, CidrRange...prefixRanges) {
Expand Down
4 changes: 3 additions & 1 deletion xds/src/test/java/io/grpc/xds/XdsClientTestHelper.java
Expand Up @@ -235,7 +235,9 @@ static Cluster buildSecureCluster(
}
if (upstreamTlsContext != null) {
clusterBuilder.setTransportSocket(
TransportSocket.newBuilder().setName("tls").setTypedConfig(Any.pack(upstreamTlsContext)));
TransportSocket.newBuilder()
.setName("envoy.transport_sockets.tls")
.setTypedConfig(Any.pack(upstreamTlsContext)));
}
return clusterBuilder.build();
}
Expand Down

0 comments on commit b08ce41

Please sign in to comment.