Chaho12 opened a new pull request, #7808:
URL: https://github.com/apache/kyuubi/pull/7808

   <!--
   Thanks for sending a pull request!
   
   Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: 
https://kyuubi.readthedocs.io/en/master/contributing/code/index.html
     2. If the PR is related to an issue in 
https://github.com/apache/kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, 
e.g., '[KYUUBI #XXXX] Your PR title ...'.
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
'[WIP][KYUUBI #XXXX] Your PR title ...'.
   -->
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new feature, clarify the use cases.
     2. If you fix a bug, you can clarify why it is a bug, and what versions 
are affected.
   -->
   
   The thrift HTTP and REST frontends take the client address of a session from 
the header named by
   `kyuubi.frontend.proxy.http.client.ip.header` and fall back to the TCP peer. 
The Trino frontend
   always uses `httpRequest.getRemoteAddr`, so behind a load balancer or 
gateway every Trino session
   gets the proxy's address. `kyuubi.server.limit.connections.per.ipaddress` 
then counts all Trino
   clients against one address, `kyuubi.server.limit.connections.ip.deny.list` 
cannot single out a
   client, and the session's `clientIp` shows the proxy.
   
   This patch adds `clientIpAddress` to the Trino `ApiRequestContext` - the 
configured header if
   present, otherwise the TCP peer - and uses it in the five places of 
`StatementResource` that build
   a `TrinoContext`. The Trino frontend has no `AuthenticationFilter`, which is 
where the other HTTP
   frontends read the header, so it reads the header itself.
   
   One difference from REST: a blank header falls back to the TCP peer instead 
of becoming an empty
   address, since the limiter and the ip deny list skip a blank address. As 
with the other frontends,
   the header is trusted only as far as the proxy in front of the server.
   
   Affects master and 1.11.1.
   
   close #7807
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some 
test cases that check the changes thoroughly including negative and positive 
cases if possible.
   If it was tested in a way different from regular unit tests, please clarify 
how you tested step by step, ideally copy and paste-able, so that other 
reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why 
it was difficult to add.
   -->
   
   Added three cases to `StatementResourceSuite`, each submitting `select 1` 
and checking the IP
   address of the session it opens: with `X-Real-IP: 10.1.2.3` it is 
`10.1.2.3`; without the header,
   and with a blank one, it is the TCP peer.
   
       build/mvn test -pl kyuubi-server -am -Dtest=none \
           
-DwildcardSuites=org.apache.kyuubi.server.trino.api.v1.StatementResourceSuite
   
   All 7 pass with the change. With `StatementResource` reverted to 
`getRemoteAddr`, the header case
   fails with `"127.0.0.1" did not equal "10.1.2.3"`; without the blank-header 
fallback, the blank
   case fails with `"" was empty`.
   
   The suite launches a Spark engine, so `externals/kyuubi-spark-sql-engine` 
has to be packaged first.
   
   ### Was this patch assisted by generative AI tooling?
   <!--
   If generative AI tooling has assisted in authoring or reviewing this patch, 
please include
   an 'Assisted-by: ' trailer that identifies the agent and/or model.
   For example: 'Assisted-by: Claude Opus 4.7' or 'Assisted-by: 
Claude:claude-opus-4-7'.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   
   Assisted-by: Claude Opus 5.5
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to