Skip to content
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

alts: Make GoogleDefaultChannelCredentials take a CallCredentials #8548

Merged
merged 12 commits into from Nov 15, 2021

Conversation

mohanli-ml
Copy link
Contributor

@mohanli-ml mohanli-ml commented Sep 22, 2021

DirectPath is going to support non-default service account. This PR allows users to pass CallCredentials to GoogleDefaultChannelCredentials. See design in https://docs.google.com/document/d/1JmyqJBFlVKjPvceJ0-QCDrqNHXxAHbelzrohtZp9YmE/edit?resourcekey=0-FqL0OJdgTsgxX5jbMsPuVg#heading=h.8wyuqdk8ouwm.

@ejona86
Copy link
Member

ejona86 commented Sep 27, 2021

I'm delaying reviewing this until the design is worked out for all the languages.

@mohanli-ml
Copy link
Contributor Author

I added a Builder class to ComputeEngineChannelCredentials, PTAL. Thanks!

"Compute Engine Credentials can only be used on Google Cloud Platform"));
}
if (callCredentials == null) {
callCredentials = MoreCallCredentials.from(ComputeEngineCredentials.create());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mutate the builder. Instead, use a local variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

callCredentials =
new FailingCallCredentials(
Status.INTERNAL.withDescription(
"Compute Engine Credentials can only be used on Google Cloud Platform"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... This is a bit interesting, as if the user is providing call credentials we could actually work on non-GCE.

I wonder if we are modifying the wrong API, and should be modifying GoogleDefaultChannelCredentials instead. CC @menghanl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, or we should just add a general purpose API that accepts callCreds.
And both GoogleDefaultCreds and ComputeEngineCreds should be built on that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this? grpc/grpc-go#4830

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gax-java and google-api-go-client will check the GCP environment before attempting DirectPath

So what? That has little to do with the implementation and times it could be used. The point is that this API has no dependency on GCE when you provide the credentials.

And both GoogleDefaultCreds and ComputeEngineCreds should be built on that.

I think that is essentially "GoogleDefaultCreds with passed call creds" like I was suggesting. And it seems that is the approach you took with grpc/grpc-go#4830, so I think we are on the same page.

We should modify GoogleDefaultChannelCredentials in Java instead of ComputeEngineChannelCredentials.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I have two concerns here:

  1. Your opinion is from the perspective of API design, which makes sense to me. However, if you look from the perspective of DirectPath, since DirectPath can only be used on GCE, removing the checking on GCE in credentials (i.e., using GoogleDefaultCreds instead of ComputeEngineCreds) means that we relies on client libraries (i.e., the two links above) to check the GCE environment. I doubt if this is a good design, and I feel the secure solution here is to rename ComputeEngineCreds in this PR to DirectPathCreds (if ComputeEngineCreds is only used by DirectPath, and if not we can just create a new API), so that it will makes sense that the new API can take call credentials while also have dependency on GCE. WDYT? Also @menghanl

  2. I remember originally we first developed GoogleDefaultCreds, but as client libraries owners wanted to know for sure what mechanism would be used to retrieve the OAuth token, so we then developed ComputeEngineCreds. @apolcyn Alex may have more context here. If after discussing Q1 we still want to use GoogleDefaultCreds for DirectPath, we should reach to client libraries owners as same concerns may still exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since DirectPath can only be used on GCE

For 1, as you mention, the only reason ComputeEngineChannelCredentials exists is because the client libraries wanted to convert from their version of ComputeEngine creds and guarantee that GoogleDefaultChannelCredentials didn't use some other sort of cred. GoogleDefaultChannelCredentials was designed to run anywhere.

For 2, if the client libraries are explicitly passing the call credentials they expect to be used, then there's no mis-alignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with 2.

For 1 I want to double check, you think it is OK that DirectPath will use GoogleDefaultChannelCredentials, and since GoogleDefaultChannelCredentials does not do the on GCE check, we rely on client libraries to do the on GCE check, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how I can say this any differently. GoogleDefaultChannelCredentials is fine to use outside of GCE. If client libraries only want to use it for GCE, that is fine and up to them. Both GoogleDefaultChannelCredentials and ComputeEngineChannelCredentials do not require ALTS to work; they will fall back to TLS if anything goes wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks for clarifying. I have updated the PR. PTAL.

@mohanli-ml mohanli-ml changed the title alts: Make ComputeEngineChannelCredentials take a CallCredentials alts: Make GoogleDefaultChannelCredentials take a CallCredentials Oct 5, 2021
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fair. Once the two comments are resolved it'd be good to merge.

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. Since this is direct-to-stable since it is being used by a library, I'm going to hold off on merging until it is discussed in the API stabilization meeting on the 14th.

}

public static Builder newBuilder() {
return new Builder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare private Builder() {} to favor static newBuilder() over new Builder().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return newBuilder().build();
}

public static Builder newBuilder() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Add javadoc and @since 1.42.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

sslContext = GrpcSslContexts.forClient().build();
} catch (SSLException e) {
throw new RuntimeException(e);
/** Builder for {@link GoogleDefaultChannelCredentials} instances. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add @since 1.42.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public static final class Builder {
private CallCredentials callCredentials;

/** Construct GoogleDefaultChannelCredentials with a given call credential. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/Construct/Constructs/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return this;
}

/** Build a GoogleDefaultChannelCredentials instance. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/Build/Builds/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ejona86
Copy link
Member

ejona86 commented Oct 14, 2021

API review:

  • Seems fine. Fine with direct-to-stable

@ejona86 ejona86 merged commit a2398ce into grpc:master Nov 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants