-
Notifications
You must be signed in to change notification settings - Fork 181
💥 [BREAKING] enable TLS if api key provided #2740
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
base: master
Are you sure you want to change the base?
Conversation
0153bc0 to
b7762ee
Compare
| boolean enableHttps; | ||
| if (this.enableHttpsExplicitlySet) { | ||
| enableHttps = this.enableHttps; | ||
| } else { | ||
| enableHttps = this.apiKeyProvided; | ||
| } |
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.
| boolean enableHttps; | |
| if (this.enableHttpsExplicitlySet) { | |
| enableHttps = this.enableHttps; | |
| } else { | |
| enableHttps = this.apiKeyProvided; | |
| } | |
| boolean enableHttps = this.enableHttps; | |
| if (!this.enableHttpsExplicitlySet && this.apiKeyProvided && this.sslContext != null && this.channel != null) { | |
| enableHttps = true; | |
| } |
I think this is better. IIUC, you should only default enableHttps if no SSL/channel-related things are set. I think this way of defining the logic is also clearer that you are setting to true in this one rare situation.
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.
That makes sense to me. I've basically done this but removed the "explicit" flag in favor of changing enableHttps to Boolean
| Collection<ClientInterceptor> grpcClientInterceptors = | ||
| MoreObjects.firstNonNull(this.grpcClientInterceptors, Collections.emptyList()); | ||
|
|
||
| // Auto-enable TLS when API key is provided and TLS is not explicitly set |
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 PR should be marked as 💥 COMPAT BREAK. Perhaps even more in Java than other languages, there may be users setting API keys and expecting non-TLS by default (e.g. to their proxies). So we need to make very clear in release notes this is a breaking change.
| this.target = options.target; | ||
| this.channelInitializer = options.channelInitializer; | ||
| this.enableHttps = options.enableHttps; | ||
| this.enableHttpsExplicitlySet = true; |
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.
Why are you assuming this is always true if a builder is created from an options?
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.
Yeah, I figured this would be a safe-ish way to assume enableHttpsExplicitlySet but it doesn't make sense.
It's not a good way to represent the tri-state of: not set, explicitly false, set.
I've instead opted to make enableHttps a Boolean instead of a boolean.
cretz
left a comment
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.
LGTM, nothing blocking (but added a couple of notes). Will leave approval up to Java SDK owners though.
| private ManagedChannel channel; | ||
| private SslContext sslContext; | ||
| private boolean enableHttps; | ||
| private Boolean enableHttps; |
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 assume we don't want to support a user calling setEnableHttps(null) to restore to "default"? I don't mind, just want to confirm
| private ManagedChannel channel; | ||
| private SslContext sslContext; | ||
| private boolean enableHttps; | ||
| private Boolean enableHttps; |
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.
Here's a contrived situation:
- I create service stubs options with no API key and having set nothing about TLS whatsoever, thereby making
enableHttpsdefault tofalseon the service stub options - I want to create new service stub options build from the existing options, so now
enableHttpsisfalseeven though I never set it - I do a
addApiKeyon this new service stub options I have never set any TLS setting on, but it still won't default to TLS because with the current code, it's impossible to create a builder from existing options and retain default TLS behavior
I don't mind if we break and/or don't-support this scenario, just wanted to mention it
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 think we should at least document that scenario since it is confusing. Arguably if enableHttps wasn't explicitly set when the service stub options was created we should preserve that information when we go back to a builder
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.
Hmm, maybe should revert the change:
this.enableHttps != null ? this.enableHttps : false,
and make enableHttps a Boolean in ServiceStubOptions as well
The semantics might be clearer this way tbh
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 we don't consider changing the return type of ServiceStubOptions.getEnableHttps() to Boolean instead of boolean to be too big of a compat break, I agree that is the better/clearer approach
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.
Hm I think changing the return type to a Boolean is a bit dangerous since if we return a null and users expect it to be a bool then they could get a null pointer exception. Can we just internally keep track of it as a Boolean, but keep the return type the same?
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 didn't figure it'd be that common, but meh. This works for me, but what should be the return value of getEnableHttps be if enableHttps is null? Would the logic be return (this.enableHttps != null && this.enableHttps) || (enableHttps == null && this.apiKeyProvided && this.sslContext == null && this.channel == null)? I also assume users may never want to differentiate whether it's explicitly set or not? Maybe a different field name/getter and getEnableHttps is that more advanced logic but the getter still exists for the wrapper?
##What was changed
DWISOTT
How was this tested:
Unit tests
Any docs updates needed?
Maybe