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

Connection-scoped proxy support for Java/JDBC client #1338

Closed
ngucandy opened this issue Apr 27, 2023 · 2 comments · Fixed by #1356
Closed

Connection-scoped proxy support for Java/JDBC client #1338

ngucandy opened this issue Apr 27, 2023 · 2 comments · Fixed by #1356
Assignees

Comments

@ngucandy
Copy link

I'm using the ClickHouse JDBC client in a multi-tenant server application that allows users to connect to several different databases. Many JDBC drivers allow configuration of HTTP(S) or SOCKS proxies that are scoped only to a single connection. I don't see any way to do this with ClickHouse JDBC. If this is possible, can someone point me in right direction? If this isn't possible, how do I submit an enhancement request to add this ability?

@zhicwu
Copy link
Contributor

zhicwu commented Apr 27, 2023

Hi @ngucandy! Currently, the ClickHouse JDBC driver does not have a specific option for configuring a proxy per connection. However, the library uses HttpURLConnection by default to access the ClickHouse server. You can set up a JVM-wide proxy using system properties as mentioned in the Java documentation. Keep in mind that this will apply the proxy settings to all connections in your application.

If you need a quick workaround to specify a proxy for a single connection, consider using chproxy, a ClickHouse proxy server, in conjunction with different DNS configurations for the backend. This approach allows you to route ClickHouse connections through different proxies based on the backend DNS configuration, providing a more granular control over your connections.

@ngucandy
Copy link
Author

@zhicwu Thanks for confirming this isn't something currently supported. Unfortunately, using chproxy would not be a "quick" workaround for us. We actually have our own proxy implementation that we must use to allow for secure connections between our application servers and our user's databases (which often sit behind a corporate firewall).

I see that HttpUrlConnectionImpl already supports creating connections by passing in Proxy.NO_PROXY on a per-connection basis:

HttpURLConnection newConn = c.isUseNoProxy()
? (HttpURLConnection) new URL(url).openConnection(Proxy.NO_PROXY)
: (HttpURLConnection) new URL(url).openConnection();

Is it feasible to modify this approach so that different types of proxies could be passed in instead? For example, change the current option use_no_proxy to a set of options:

  • use_proxy_type (none, http, socks)
  • proxy_host
  • proxy_port

This should allow the construction of a Proxy object that can be passed into new URL(url).openConnection(proxy) and provide a way for the JDBC driver users to pass in per-connection proxy parameters. Of course, I'm not very familiar with the codebase so I'm not sure what are the other implications of making this kind of change. Just trying to brainstorm how to add per-connection proxy support.

@mzitnik mzitnik self-assigned this Apr 30, 2023
@mzitnik mzitnik mentioned this issue May 9, 2023
3 tasks
@zhicwu zhicwu linked a pull request May 16, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants