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

Do not rely on the X-<protocol>-User HTTP header to detect a protocol #16015

Conversation

lpoulain
Copy link
Member

@lpoulain lpoulain commented Feb 7, 2023

Description

Change the logic to detect a non-Trino protocol to stop relying on the X--User HTTP header.

Additional context and related issues

Trino detects alternative protocols (e.g. Presto) by looking whether the X--User HTTP header exists. In some cases however no such header is provided. So change the logic to avoid relying on that particular HTTP header and instead look for any X--* HTTP header.

Release notes

(X) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Feb 7, 2023
@lpoulain lpoulain requested review from findepi and electrum February 7, 2023 15:27
@martint
Copy link
Member

martint commented Feb 7, 2023

In which cases is that header not provided?

if (headerNames.contains("X-" + alternateHeaderName.get() + "-User")) {
if (headerNames.contains("X-Trino-User")) {
String headerPrefix = "x-" + alternateHeaderName.get().toLowerCase(ENGLISH);
if (headerNames.stream()
Copy link
Member

Choose a reason for hiding this comment

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

Nit: these would look better without wrapping

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean something like:

            if (headerNames.stream().anyMatch(header -> header.toLowerCase(ENGLISH).startsWith(headerPrefix))) {
                if (headerNames.stream().anyMatch(header -> header.toLowerCase(ENGLISH).startsWith("x-trino-"))) {

Copy link
Member

Choose a reason for hiding this comment

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

Yep, exactly

@electrum
Copy link
Member

electrum commented Feb 7, 2023

Now that we do user mapping for authentication, it's legitimate for a client not to send the user header, and apparently some clients do not always send it.

@github-actions
Copy link

github-actions bot commented Mar 1, 2023

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Mar 1, 2023
@mosabua
Copy link
Member

mosabua commented Mar 2, 2023

Can you clarify what the next here should be @electrum ?

@electrum electrum merged this pull request into trinodb:master Apr 4, 2023
@github-actions github-actions bot added this to the 412 milestone Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants