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

Support mTLS connections (key and CA signed cert) #523

Closed
levonet opened this issue Nov 21, 2020 · 4 comments
Closed

Support mTLS connections (key and CA signed cert) #523

levonet opened this issue Nov 21, 2020 · 4 comments
Labels
enhancement module-client Client API and all implementations
Milestone

Comments

@levonet
Copy link

levonet commented Nov 21, 2020

I didn't find a way to add a key to sslrootcert, or pass the key in any other way.

Probably because the keystore is created only from X.509 format.
https://github.com/ClickHouse/clickhouse-jdbc/blob/4332286/src/main/java/ru/yandex/clickhouse/util/ClickHouseHttpClientBuilder.java#L194-L199

I see that the idea to use sslrootcert is inherited from the postgresql driver #95, #96

Maybe also need to support the sslcert, sslkey (for PKCS-8) settings. https://jdbc.postgresql.org/documentation/head/ssl-client.html

It would be desirable to receive a standard possibility to specify the key and CA signed certificate in connection url:

jdbc:clickhouse://localhost:8443/default?ssl=true&sslkey=client.pk8&sslcert=client.crt&sslrootcert=ca.crt

like postgresql too.

Without this, it is not possible to use clickhouse-jdbc with mTLS in products such as gatagrep or dbeaver.

@zhicwu zhicwu added this to the 0.3.0 release milestone Feb 1, 2021
@zhicwu zhicwu modified the milestones: 0.3.0 release, 0.3.1 release Mar 3, 2021
@zhicwu zhicwu modified the milestones: 0.3.1 release, 0.3.2 release Apr 15, 2021
@zhicwu zhicwu modified the milestones: 0.3.3 release, 0.3.2 Release Jul 31, 2021
@zhicwu zhicwu added the module-client Client API and all implementations label Oct 6, 2021
@zhicwu zhicwu modified the milestones: 0.3.2 Release, 0.3.3 release Dec 16, 2021
@zhicwu zhicwu modified the milestones: 0.3.3 release, 0.3.2-patch8 Apr 16, 2022
@zhicwu zhicwu mentioned this issue Apr 16, 2022
10 tasks
@zhicwu
Copy link
Contributor

zhicwu commented Apr 17, 2022

Implemented since 0.3.2-patch8. I didn't check how PostgreSQL JDBC driver implemented the feature, but I think it should be all similar.

Couple of things worthy of mention:

  1. Use RSA key in PKCS8 format
  2. search path of certificate and key files: classpath -> File system(start with ~/.clickhouse first for relative path)
  3. set sslmode to STRICT in JDBC driver - set to NONE will always trust server certificate but turn off client auth
    image
  4. user name(same as server configuration and Common Name in certificate) is still needed, with empty password
  5. users.xml
    <clickhouse>
     <users>
       <me>
         <ssl_certificates>
           <common_name>me</common_name>
         </ssl_certificates>
       </me>
     </users>
    </clickhouse>

@rajjat0602
Copy link

rajjat0602 commented Apr 18, 2022

I have TLS enabled ClickHouse with user name and password since you have mentioned in the above statement that -->user name(same as server configuration and Common Name in certificate) is still needed, with empty password. So How to connect to clickhouse with username and password?

@zhicwu
Copy link
Contributor

zhicwu commented Apr 18, 2022

Hi @rajjat0602, you can only pick one from password and certificate for authentication.

It seems the 3 files(tls.crt , tls.key and ca.crt) are only for server setup and you don't have client certificate. If that's the case, I think you just need set ssl=true and sslmode=NONE without specify any certificate or key. If you want to ensure the client is connecting to a trusted server, you can specify root certificate so it's something like ssl=true, sslmode=STRICT and sslrootcert=ca.crt.

@mohdmsl
Copy link

mohdmsl commented Jan 13, 2023

hi I am trying to connect to tcp port which is enabled with SSL using clickhouse-jdbc but I am getting below error
OPENSSL_internal:CERTIFICATE_VERIFY_FAILED

I have passed sslrootcert which is a cert file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement module-client Client API and all implementations
Projects
None yet
Development

No branches or pull requests

4 participants