xds: remove env var for security enable/disable (#10243)

This commit is contained in:
sanjaypujare 2023-06-02 09:24:51 -07:00 committed by GitHub
parent 02ac6f4393
commit 639fd8edf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 31 deletions

View File

@ -69,10 +69,7 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
static boolean enableCircuitBreaking = static boolean enableCircuitBreaking =
Strings.isNullOrEmpty(System.getenv("GRPC_XDS_EXPERIMENTAL_CIRCUIT_BREAKING")) Strings.isNullOrEmpty(System.getenv("GRPC_XDS_EXPERIMENTAL_CIRCUIT_BREAKING"))
|| Boolean.parseBoolean(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 = private static final Attributes.Key<ClusterLocalityStats> ATTR_CLUSTER_LOCALITY_STATS =
Attributes.Key.create("io.grpc.xds.ClusterImplLoadBalancer.clusterLocalityStats"); Attributes.Key.create("io.grpc.xds.ClusterImplLoadBalancer.clusterLocalityStats");
@ -240,7 +237,7 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
for (EquivalentAddressGroup eag : addresses) { for (EquivalentAddressGroup eag : addresses) {
Attributes.Builder attrBuilder = eag.getAttributes().toBuilder().set( Attributes.Builder attrBuilder = eag.getAttributes().toBuilder().set(
InternalXdsAttributes.ATTR_CLUSTER_NAME, cluster); InternalXdsAttributes.ATTR_CLUSTER_NAME, cluster);
if (enableSecurity && sslContextProviderSupplier != null) { if (sslContextProviderSupplier != null) {
attrBuilder.set( attrBuilder.set(
InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER, InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
sslContextProviderSupplier); sslContextProviderSupplier);

View File

@ -528,20 +528,8 @@ public class ClusterImplLoadBalancerTest {
} }
} }
@Test
public void endpointAddressesAttachedWithTlsConfig_disableSecurity() {
boolean originalEnableSecurity = ClusterImplLoadBalancer.enableSecurity;
ClusterImplLoadBalancer.enableSecurity = false;
subtest_endpointAddressesAttachedWithTlsConfig(false);
ClusterImplLoadBalancer.enableSecurity = originalEnableSecurity;
}
@Test @Test
public void endpointAddressesAttachedWithTlsConfig_securityEnabledByDefault() { public void endpointAddressesAttachedWithTlsConfig_securityEnabledByDefault() {
subtest_endpointAddressesAttachedWithTlsConfig(true);
}
private void subtest_endpointAddressesAttachedWithTlsConfig(boolean enableSecurity) {
UpstreamTlsContext upstreamTlsContext = UpstreamTlsContext upstreamTlsContext =
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true); CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true);
LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider(); LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider();
@ -566,11 +554,7 @@ public class ClusterImplLoadBalancerTest {
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) { for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
SslContextProviderSupplier supplier = SslContextProviderSupplier supplier =
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER); eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
if (enableSecurity) { assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
} else {
assertThat(supplier).isNull();
}
} }
// Removes UpstreamTlsContext from the config. // Removes UpstreamTlsContext from the config.
@ -597,20 +581,14 @@ public class ClusterImplLoadBalancerTest {
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) { for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
SslContextProviderSupplier supplier = SslContextProviderSupplier supplier =
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER); eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
if (enableSecurity) { assertThat(supplier.isShutdown()).isFalse();
assertThat(supplier.isShutdown()).isFalse(); assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
} else {
assertThat(supplier).isNull();
}
} }
loadBalancer.shutdown(); loadBalancer.shutdown();
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) { for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
SslContextProviderSupplier supplier = SslContextProviderSupplier supplier =
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER); eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
if (enableSecurity) { assertThat(supplier.isShutdown()).isTrue();
assertThat(supplier.isShutdown()).isTrue();
}
} }
loadBalancer = null; loadBalancer = null;
} }