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: 7 additions & 0 deletions xds/src/main/java/io/grpc/xds/FilterRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.grpc.xds;

import com.google.common.annotations.VisibleForTesting;
import io.grpc.internal.GrpcUtil;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
Expand All @@ -32,12 +33,18 @@

private FilterRegistry() {}

static boolean isEnabledGcpAuthnFilter =
GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER", false);

static synchronized FilterRegistry getDefaultRegistry() {
if (instance == null) {
instance = newRegistry().register(
new FaultFilter.Provider(),
new RouterFilter.Provider(),
new RbacFilter.Provider());
if (isEnabledGcpAuthnFilter) {
instance.register(new GcpAuthenticationFilter.Provider());

Check warning on line 46 in xds/src/main/java/io/grpc/xds/FilterRegistry.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/FilterRegistry.java#L46

Added line #L46 was not covered by tests
}
}
return instance;
}
Expand Down
5 changes: 5 additions & 0 deletions xds/src/main/java/io/grpc/xds/GcpAuthenticationFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.grpc.xds;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.grpc.xds.FilterRegistry.isEnabledGcpAuthnFilter;
import static io.grpc.xds.XdsNameResolver.CLUSTER_SELECTION_KEY;
import static io.grpc.xds.XdsNameResolver.XDS_CONFIG_CALL_OPTION_KEY;

Expand Down Expand Up @@ -312,6 +313,10 @@
public AudienceWrapper parse(Any any) throws ResourceInvalidException {
Audience audience;
try {
if (!isEnabledGcpAuthnFilter) {
throw new InvalidProtocolBufferException("Environment variable for GCP Authentication "

Check warning on line 317 in xds/src/main/java/io/grpc/xds/GcpAuthenticationFilter.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/GcpAuthenticationFilter.java#L317

Added line #L317 was not covered by tests
+ "Filter is Not Set");
}
audience = any.unpack(Audience.class);
} catch (InvalidProtocolBufferException ex) {
throw new ResourceInvalidException("Invalid Resource in address proto", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -89,6 +90,11 @@ public class GcpAuthenticationFilterTest {
private static final RdsUpdate rdsUpdate = getRdsUpdate();
private static final CdsUpdate cdsUpdate = getCdsUpdate();

@Before
public void setUp() {
System.setProperty("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER", "true");
}

@Test
public void testNewFilterInstancesPerFilterName() {
assertThat(new GcpAuthenticationFilter("FILTER_INSTANCE_NAME1", 10))
Expand Down
13 changes: 9 additions & 4 deletions xds/src/test/java/io/grpc/xds/GrpcXdsClientImplDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,7 @@ public Object parse(Any value) {

@Test
public void processCluster_parsesAudienceMetadata() throws Exception {
FilterRegistry.isEnabledGcpAuthnFilter = true;
MetadataRegistry.getInstance();

Audience audience = Audience.newBuilder()
Expand Down Expand Up @@ -2460,10 +2461,14 @@ public void processCluster_parsesAudienceMetadata() throws Exception {
"FILTER_METADATA", ImmutableMap.of(
"key1", "value1",
"key2", 42.0));
assertThat(update.parsedMetadata().get("FILTER_METADATA"))
.isEqualTo(expectedParsedMetadata.get("FILTER_METADATA"));
assertThat(update.parsedMetadata().get("AUDIENCE_METADATA"))
.isInstanceOf(AudienceWrapper.class);
try {
assertThat(update.parsedMetadata().get("FILTER_METADATA"))
.isEqualTo(expectedParsedMetadata.get("FILTER_METADATA"));
assertThat(update.parsedMetadata().get("AUDIENCE_METADATA"))
.isInstanceOf(AudienceWrapper.class);
} finally {
FilterRegistry.isEnabledGcpAuthnFilter = false;
}
}

@Test
Expand Down