-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Trino client throws 401: 'Unauthorized' error while attempting to connect to a cluster behind a LB with 307/308 redirect policy set #21026
Comments
We shouldn't make this change until we've a clear consensus on whether to include the Authorization header on redirects. Trino Java client and Python client do not send Authorization on redirects. We need to agree on what's the correct behavior and enforce the same behavior across different clients as much as possible.
This decision could also affect the future development of trino-gateway. @dain @electrum Could you please take a look? Current behavior: okhttp 4.12.0
https://go.dev/src/net/http/client.go
Python requests
Related comments: |
Hello @oneonestar
I think providing an option for user to configure the behavior (Option 3 in the list) sounds like a great approach. We can come up with a clientOptions flag e.g. This approach will also give users a choice to retain the old behavior (prior to 412 4be1401) with a minimal change around the extra client option. Shall I revise the PR: #21027 to add this extra clientOptions ? |
@dain had a good idea that we could add a client option to disable redirects entirely. Authentication is a required part of the protocol, so if the client is going to follow redirects, then it must send authentication. Thoughts? |
Yea. A flag to control whether to follow a redirect is also easy to understand. However, I can’t think of when a user would turn on this option. “Turn on this option if you want better security” most likely won’t work. How about making the no follow redirect as default and add an option to turn it on? (This also prevents someone in the future assigning a CVE to Trino saying that the default behavior is not secure, blah blah) |
This is one of those areas with a trade-off between usability and security. Within an organization, the choice to use redirection on the Trino server side is made centrally by the Trino administrators. If redirection is used, then every Trino client needs to be configured to use it. Every user will need to add an extra property or option. It makes moving from a non-redirection setup to a redirection setup much harder, as every client will need to be updated. This often happens when Trino usage is large and growing. This means administrators will be reluctant to do this, which limits their options for scaling. We can ask the question: when would following redirects, or sending authentication after a redirect, be a security issue? I think this is only a problem in situations where a hosted environment allows untrusted users to connect to a user specified Trino server. In that case, the client application would not trust the server and thus should not follow redirects. In the normal case, the user can trust the Trino server. If the user is already sending their credentials to the Trino server, why would they not trust sending credentials to the target of a redirect? |
Good point.
If the server is untrusted/malicious, the credentials would already be leaked in the first connection. Follow the redirects or not is irrelevant. I doubt how useful will be to implement a no follow redirect option in this case. |
Updated the PR and added a new client options flag called Please take a look. 🙏 |
Yes, so I don’t see a problem with enabling this behavior by default. It should only be disabled if you are connecting to arbitrary servers provided by users (such as a hosted BI tool or dashboard that connects to a user specified Trino server). |
Reopen this. |
I think there is a regression on this issue caused by #22687
|
During 412 release as part of OkHttp version upgrade, explicit client retry logic was removed in the event of a 307/308 redirect. This will cause 401: 'Unauthorized' error when trino client is talking to a Trino Cluster that is deployed behind a load balancer(For example AWS ALB) with a redirect mode(e.g. 307/308) routing policy.
Reference: 4be1401
Okhttp by default does follow redirects. However it drops Authorization headers if the redirect is across hosts. This causes a 401: 'Unauthorized' error.
Reference: https://github.com/square/okhttp/blob/okhttp_4.10.x/okhttp/src/main/kotlin/okhttp3/internal/http/RetryAndFollowUpInterceptor.kt#L323-L328
The text was updated successfully, but these errors were encountered: