-
Notifications
You must be signed in to change notification settings - Fork 3.9k
xds: Implement GcpAuthenticationFilter #11638
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
Conversation
xds/src/main/java/io/grpc/xds/internal/GcpAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
@ejona86 I see there's one more mistake in this PR,
I wanted to put |
I suggest putting both in the same package ( (Personally, I'd generally put LruCache as a nested class of the Filter. Yes, you can think it can be reused, but reusable code is reusable when it is reused. Until then "reusable" is a lie and can be harmful if you make the wrong thing complex to make some code generic. We can always move the code out of the class. Even in this case, the |
(Although I'll also mention that in cases like this where it doesn't matter, it's mostly up to the author of the code to decide these sorts of things.) |
Alright, so we do check for <=0 values in our FYI, the highlighted message in this comment is from grpc/proposal#438 (comment) |
Well, There's no real downside to our limit. A thousand would be a heck of a lot and a million is outrageous. A billion is well beyond the realm of legitimate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Bazel build will need fixing. It looks like it needs a newer version of the protos. See MODULE.bazel and repositories.bzl (those duplicate each other's functionality, because of a Bazel ecosystem migration to bzlmod).
static final String TYPE_URL = | ||
"type.googleapis.com/envoy.extensions.filters.http.gcp_authn.v3.GcpAuthnFilterConfig"; | ||
|
||
public GcpAuthenticationFilter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to have this constructor. public qualifier in a package private class is also not useful.
cacheSize = cacheConfig.getCacheSize().getValue(); | ||
if (cacheSize == 0) { | ||
return ConfigOrError.fromError( | ||
"cache_config.cache_size must be in the range (0, INT64_MAX)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the part about int64_max. That's out-of-date.
@Test | ||
public void testParseFilterConfig_withInvalidMessageType() { | ||
GcpAuthenticationFilter filter = new GcpAuthenticationFilter(); | ||
Message invalidMessage = Mockito.mock(Message.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mock a Message. That won't behave correctly in many cases. A well-known type would be convenient for this test, like Empty.getInstance()
.
} | ||
|
||
@Test | ||
public void testBuildClientInterceptor() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test could use a better name. It seems to do more than the name suggests.
|
||
assertNull(result.config); | ||
assertNotNull(result.errorDetail); | ||
assertTrue(result.errorDetail.contains("Invalid config type")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertTrue()
produces particularly unhelpful error messages. Prefer Truth. assertThat(result.errorDetail).contains("Invalid config type")
produces much better results. You also then don't need the assertNotNull()
check.
@Test | ||
public void testParseFilterConfig_withValidConfig() { | ||
GcpAuthnFilterConfig config = GcpAuthnFilterConfig.newBuilder() | ||
.setCacheConfig(TokenCacheConfig.newBuilder().setCacheSize(UInt64Value.of(10))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a value other than the default? How else do you know the config was used?
assertNull(result.errorDetail); | ||
assertEquals(10L, | ||
((GcpAuthenticationFilter.GcpAuthenticationConfig) | ||
result.config).getCacheSize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unwrap some? It seems this will fit on the line above just fine, and then would be more readable.
This is a step towards gRFC A83.
When enabled for a listener, GcpAuthenticationFilter fetches JWT tokens from GCE Metadata Server for the cluster audience, creates Google Cloud CallCredentials using the token and attaches them to outgoing RPCs.