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

feat: Support transport and binding-enforcement MDS parameters. #1558

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

rmehta19
Copy link
Contributor

No description provided.

@rmehta19 rmehta19 requested review from a team as code owners October 26, 2024 02:06
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Oct 26, 2024
@rmehta19 rmehta19 force-pushed the mds-cred-token-req-param branch from 04db8a3 to 91dba11 Compare October 26, 2024 02:07
@rmehta19
Copy link
Contributor Author

cc: @rockspore

@@ -696,6 +725,14 @@ public Collection<String> getDefaultScopes() {
return defaultScopes;
}

public String getTransport() {

Choose a reason for hiding this comment

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

Please provide javadoc on these, pointing to publicly documented Metadata Service parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline: We will update public MDS docs when the feature is non-experimental. Since the usage of the S2A + MTLS + bound tokens flow is guarded by an environment variable (EXPERIMENTAL_GOOGLE_API_USE_S2A). Until the public docs are updated, we can link to AIP here and #1400 (AIP already linked in this merged PR).

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Oct 28, 2024
@rmehta19
Copy link
Contributor Author

rmehta19 commented Nov 7, 2024

@lqiu96 , @zhumin8 : Would be able to take a look at this change and leave any feedback? Thanks!

Comment on lines 211 to 216
if (!transport.isEmpty()) {
tokenUrl.set("transport", transport);
}
if (!bindingEnforcement.isEmpty()) {
tokenUrl.set("binding-enforcement", bindingEnforcement);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be null and empty check. Setter can set a null value unless we want to add a check there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out, done in 9d46bbd

Comment on lines 660 to 661
private String transport = "";
private String bindingEnforcement = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
private String transport = "";
private String bindingEnforcement = "";
private String transport;
private String bindingEnforcement;

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 in 3cb6e98

@lqiu96
Copy link
Contributor

lqiu96 commented Dec 3, 2024

Update to use conventional commits:
feat: Support transport and binding-enforcement MDS parameters

@rmehta19 rmehta19 changed the title Support transport and binding-enforcement MDS parameters. feat: Support transport and binding-enforcement MDS parameters. Dec 3, 2024
@rmehta19
Copy link
Contributor Author

rmehta19 commented Dec 3, 2024

Thanks for the review @lqiu96 !

@@ -200,6 +218,16 @@ String createTokenUrlWithScopes() {
if (!scopes.isEmpty()) {
tokenUrl.set("scopes", Joiner.on(',').join(scopes));
}
if (transport == Transport.MTLS) {
tokenUrl.set("transport", "mtls");
Copy link
Contributor

@blakeli0 blakeli0 Dec 13, 2024

Choose a reason for hiding this comment

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

Fields can be added to the Enum class, so that each Enum can have its own label, then you can just do tokenUrl.set("transport", transport.getLabel()). See this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out! Done in latest commit.

@@ -109,6 +109,16 @@ public class ComputeEngineCredentials extends GoogleCredentials
static final int MAX_COMPUTE_PING_TRIES = 3;
static final int COMPUTE_PING_CONNECTION_TIMEOUT_MS = 500;

public enum Transport {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know the it is called transport in the token url, but since Transport in GAPIC has different meaning (the value of it is either gRPC or httpJson), can we name this differently? Maybe AuthTransport? Javadocs for what ALTS and MTLS mean would also be appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to AuthTransport in latest commit and added some javadocs. Thanks!

// Binding enforcement will always happen, irrespective of the IAM policy.
ON("on"),
// Binding enforcement will depend on IAM policy.
IAMPOLICY("iam-policy");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
IAMPOLICY("iam-policy");
IAM_POLICY("iam-policy");

I believe the convention is underscore to separate the words for constants

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 in f36a19c

Comment on lines 738 to 748
@CanIgnoreReturnValue
public Builder setTransport(AuthTransport transport) {
this.transport = transport;
return this;
}

@CanIgnoreReturnValue
public Builder setBindingEnforcement(BindingEnforcement bindingEnforcement) {
this.bindingEnforcement = bindingEnforcement;
return this;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you some small/ simple javadocs for these public setters?

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 in 8a2d967

Comment on lines 762 to 769
public AuthTransport getTransport() {
return transport;
}

public BindingEnforcement getBindingEnforcement() {
return bindingEnforcement;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

same here. also if it's returning AuthTransport, can it be getAuthTransport()?

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 in 8a2d967

Comment on lines +193 to +194
@Test
public void buildTokenUrl_nullTransport() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: one additional test where both transport and bindingenforcements are null

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 in ce74e45

@@ -109,6 +109,40 @@ public class ComputeEngineCredentials extends GoogleCredentials
static final int MAX_COMPUTE_PING_TRIES = 3;
static final int COMPUTE_PING_CONNECTION_TIMEOUT_MS = 500;

public enum AuthTransport {
Copy link
Contributor

@lqiu96 lqiu96 Dec 19, 2024

Choose a reason for hiding this comment

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

I think AuthTransport is ok for this. I would prefer if this could be more specific if possible.

Is there a term for alts and mtls type of transport that we can use? Does TlsTransport make sense? I don't know if TLS has a transport concept or if that would be confusing.

GoogleMtlsTransport? Though I'm not sure mtls/atls are google specific terms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TLDR: WDYT of GoogleAuthTransport?

I think AuthTransport is ok for this. I would prefer if this could be more specific if possible.

We generally call this "transport type": describes how the client is authenticating to Google APIS either via GFE (using mtls) or via DirectPath (using alts). However Blake mentioned above that transport has a different meaning in Client libraries (grpc vs http), so it would be good to clarify to something more specific, which is how we landed on AuthTransport initially.

Is there a term for alts and mtls type of transport that we can use? Does TlsTransport make sense? I don't know if TLS has a transport concept or if that would be confusing.

TLS is the security protocol being used, it's used in both mtls and alts. mtls is mutually authenticated TLS, alts is (in short) "Google-optimized" mtls (see public docs).

In the enum name, I think we want to focus on how clients are authenticating to Google APIS, not details of the protocol being used (mtls vs alts). How about GoogleAuthTransport? I think this captures that the enum is listing different ways to ways clients can authenticate to Google APIs.

GoogleMtlsTransport? Though I'm not sure mtls/atls are google specific terms.
I think this name would be ok. One thing is that mtls via GFE strictly adheres to the TLS standard (i.e. not Google specific). Whereas alts is a Google specific protocol.

I've done this in 8ce3a4d, let me know if the name sounds ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants