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
s2a: Add gRPC S2A #11113
base: master
Are you sure you want to change the base?
s2a: Add gRPC S2A #11113
Conversation
e83fee8
to
1991e37
Compare
Thanks @rmehta19. Can you PTAL at the test failures? |
604f9a0
to
3c867c9
Compare
@matthewstevenson88, I made 2 changes and it looks like 2/3 linux runs are passing. tests(11) is failing with an error in code that was not affected by this PR, so I don't think that failure is related. The changes:
|
@@ -0,0 +1,79 @@ | |||
// Copyright 2022 Google LLC |
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.
Just to confirm, this proto will be removed from this PR once the other PR is merged?
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.
I believe we will maintain a copy of the protos in this directory. IIUC, there is an automated process that syncs protos in grpc-proto to protos here. Context: grpc/grpc-proto#12
E.g. ALTS protos are maintained here: alts/src/main/proto/grpc/gcp
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.
Makes sense, thanks for clarifying!
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.
You'll want to add s2a
to the list of modules we copy protos for:
grpc-java/buildscripts/sync-protos.sh
Line 11 in 06df25b
for project in alts grpclb services rls interop-testing; do |
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.
Done
b7b51bc
to
73cc37a
Compare
Done -- thank you for the review @matthewstevenson88! |
Channel getChannel(); | ||
|
||
/** Returns a channel to the channel pool. */ | ||
void returnChannel(Channel channel); |
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.
Not really sure about naming conventions here, but does 'releaseChannel' or 'returnToPool' sound better?
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.
Changed naming to returnToPool.
See commit: S2AChannelPool returnChannel --> returnToPool name change.
*/ | ||
@ThreadSafe | ||
public final class S2AGrpcChannelPool implements S2AChannelPool { | ||
private static final int MAX_NUMBER_USERS_OF_CACHED_CHANNEL = 100000; |
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.
Are we ok to keep it hardcoded instead of exposing it via some param/flag?
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.
hardcoding 100000 seems fine to me, @matthewstevenson88 WDYT?
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.
If it's OK with you all, I'd prefer to keep it hardcoded until we have a use case that requires us to expose it.
public synchronized Channel getChannel() { | ||
checkState(state.equals(State.OPEN), "Channel pool is not open."); | ||
checkState( | ||
numberOfUsersOfCachedChannel >= 0, |
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.
I'm not sure how numberOfUsersOfCachedChannel can be negative. It's a private var, and you decrease it by -1 in LOC 96 after checking that it's >0 in LOC 93. Am I missing something?
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.
You are right, thanks for pointing this out -- removed this unnecessary state check.
public final class S2AHandshakerServiceChannel { | ||
private static final ConcurrentMap<String, Resource<Channel>> SHARED_RESOURCE_CHANNELS = | ||
Maps.newConcurrentMap(); | ||
private static final Duration DELEGATE_TERMINATION_TIMEOUT = Duration.ofSeconds(2); |
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.
Are we ok to keep these 2 hardcoded instead of exposing it via some param/flag?
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.
Hardcoding these two timeouts is ok with me, keeping it as is might help readability. @matthewstevenson88 WDYT?
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.
If it's OK with you all, I'd prefer to keep it hardcoded until we have a use case that requires us to expose it.
|
||
/** Indicates that a connection has been closed. */ | ||
@SuppressWarnings("serial") // This class is never serialized. | ||
final class ConnectionIsClosedException extends IOException { |
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.
Never seen such naming, typically in Java it's 'ConnectionClosedException'
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.
Done. Changed to ConnectionClosedException.
} | ||
|
||
/** Returns the proto {@link Identity} representation of this identity instance. */ | ||
public Identity identity() { |
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.
Looks like a getter, should it be 'getIdentity'?
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.
Done.
description = "The access token used to authenticate to S2A.") | ||
private static String accessToken = System.getenv(ENVIRONMENT_VARIABLE); | ||
|
||
public synchronized void reset() { |
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.
I'm not sure I understand why 'synchronized' is needed here.
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 code doesn't exist anymore, as we removed the dependency on Jcommander and replaced it with a private field & setter
distinguished_name = req_distinguished_name | ||
req_extensions = req_ext | ||
|
||
[req_distinguished_name] |
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.
Could you add the values you entered while generating certs?
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.
Done, as discussed offline, I updated the README with the the values used to populate these fields.
@ejona86, does this sound ok to you? @erm-g pointed me to something similar he has done in go: https://github.com/grpc/grpc-go/pull/6670/files#diff-ac85255b49c8d65b03b560d9959b99c6d9338de1400da6fc2d4133a434a376ad
@BeforeClass | ||
public static void setUpClass() { | ||
// Set the token that the client will use to authenticate to the S2A. | ||
JCommander.newBuilder().addObject(FLAGS).build().parse(SET_TOKEN); |
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.
You're using jcommander to just set a static field. This is many more steps than just having a package-private field/setter. Let's not add a dependency on jcommander.
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.
Done: refactored and removed the JCommander dependency.
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.
To make sure I understand, s2a is the public API, and s2a/channel and s2a/handshaker are internal APIs. Are those internal APIs to be used anywhere, even within Google?
* Configures gRPC to use S2A for transport security when establishing a secure channel. Only for | ||
* use on the client side of a gRPC connection. | ||
*/ | ||
@NotThreadSafe |
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.
Credentials must be thread-safe. Should this be on the Builder instead?
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.
Yes, the Builder is the one that's not thread safe -- done.
@@ -0,0 +1,79 @@ | |||
// Copyright 2022 Google LLC |
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.
You'll want to add s2a
to the list of modules we copy protos for:
grpc-java/buildscripts/sync-protos.sh
Line 11 in 06df25b
for project in alts grpclb services rls interop-testing; do |
Correct s2a is the public api, s2a/handshaker and s2a/channel are internal APIs to only be used within the s2a package. |
d52ee0c
to
38f72be
Compare
Add S2A Java client to gRPC Java.
Context: https://github.com/google/s2a-go/blob/main/README.md