Skip to content
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
7 changes: 2 additions & 5 deletions xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
static boolean enableCircuitBreaking =
Strings.isNullOrEmpty(System.getenv("GRPC_XDS_EXPERIMENTAL_CIRCUIT_BREAKING"))
|| Boolean.parseBoolean(System.getenv("GRPC_XDS_EXPERIMENTAL_CIRCUIT_BREAKING"));
@VisibleForTesting
static boolean enableSecurity =
Strings.isNullOrEmpty(System.getenv("GRPC_XDS_EXPERIMENTAL_SECURITY_SUPPORT"))
|| Boolean.parseBoolean(System.getenv("GRPC_XDS_EXPERIMENTAL_SECURITY_SUPPORT"));

private static final Attributes.Key<ClusterLocalityStats> ATTR_CLUSTER_LOCALITY_STATS =
Attributes.Key.create("io.grpc.xds.ClusterImplLoadBalancer.clusterLocalityStats");

Expand Down Expand Up @@ -240,7 +237,7 @@ private List<EquivalentAddressGroup> withAdditionalAttributes(
for (EquivalentAddressGroup eag : addresses) {
Attributes.Builder attrBuilder = eag.getAttributes().toBuilder().set(
InternalXdsAttributes.ATTR_CLUSTER_NAME, cluster);
if (enableSecurity && sslContextProviderSupplier != null) {
if (sslContextProviderSupplier != null) {
attrBuilder.set(
InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
sslContextProviderSupplier);
Expand Down
30 changes: 4 additions & 26 deletions xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,8 @@ public void endpointAddressesAttachedWithClusterName() {
}
}

@Test
public void endpointAddressesAttachedWithTlsConfig_disableSecurity() {
boolean originalEnableSecurity = ClusterImplLoadBalancer.enableSecurity;
ClusterImplLoadBalancer.enableSecurity = false;
subtest_endpointAddressesAttachedWithTlsConfig(false);
ClusterImplLoadBalancer.enableSecurity = originalEnableSecurity;
}

@Test
public void endpointAddressesAttachedWithTlsConfig_securityEnabledByDefault() {
subtest_endpointAddressesAttachedWithTlsConfig(true);
}

private void subtest_endpointAddressesAttachedWithTlsConfig(boolean enableSecurity) {
UpstreamTlsContext upstreamTlsContext =
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true);
LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider();
Expand All @@ -566,11 +554,7 @@ private void subtest_endpointAddressesAttachedWithTlsConfig(boolean enableSecuri
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
SslContextProviderSupplier supplier =
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
if (enableSecurity) {
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
} else {
assertThat(supplier).isNull();
}
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
}

// Removes UpstreamTlsContext from the config.
Expand All @@ -597,20 +581,14 @@ private void subtest_endpointAddressesAttachedWithTlsConfig(boolean enableSecuri
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
SslContextProviderSupplier supplier =
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
if (enableSecurity) {
assertThat(supplier.isShutdown()).isFalse();
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
} else {
assertThat(supplier).isNull();
}
assertThat(supplier.isShutdown()).isFalse();
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
}
loadBalancer.shutdown();
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
SslContextProviderSupplier supplier =
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
if (enableSecurity) {
assertThat(supplier.isShutdown()).isTrue();
}
assertThat(supplier.isShutdown()).isTrue();
}
loadBalancer = null;
}
Expand Down