feat(clickhouse-driver): support client TLS certificates#11107
Open
PaulVrugt wants to merge 2 commits into
Open
feat(clickhouse-driver): support client TLS certificates#11107PaulVrugt wants to merge 2 commits into
PaulVrugt wants to merge 2 commits into
Conversation
Add TLS support to the ClickHouse driver, including mutual TLS (client
certificate authentication) for connecting over HTTPS.
- Read CA, client certificate and key from the standard
CUBEJS_DB_SSL_CA / CUBEJS_DB_SSL_CERT / CUBEJS_DB_SSL_KEY environment
variables (parsed by BaseDriver.getSslOptions, with file-path support)
and map them to the @clickhouse/client `tls` option.
- Add an `ssl: { ca, cert, key }` option to ClickHouseDriverOptions so
certificate material can be supplied programmatically from a
driverFactory (for example, per-tenant client certificates). Mutual TLS
is enabled when ca, cert and key are all present.
- Connect over HTTPS automatically when TLS material is configured.
- Document the new options and add unit tests for the option mapping.
Signed-off-by: Paul Vrugt <paulvrugt@gmail.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds TLS support to the ClickHouse driver, including mutual TLS (client
certificate authentication) when connecting over HTTPS.
Motivation: a multi-tenant deployment where tenant isolation is enforced in
ClickHouse via distinct per-tenant users (each created with
IDENTIFIED WITH ssl_certificate) and row policies. Cube must connect as adifferent ClickHouse user per tenant, authenticated by a per-tenant client
certificate rather than a shared password. The underlying
@clickhouse/clientalready supports a
tls: { ca_cert, cert, key }option; the Cube driver simplydid not forward any certificate material.
Changes
CUBEJS_DB_SSL_CA/CUBEJS_DB_SSL_CERT/CUBEJS_DB_SSL_KEYenvironmentvariables (already parsed by
BaseDriver.getSslOptions, with file-pathsupport) and map them to the
@clickhouse/clienttlsoption.ssl: { ca, cert, key }option toClickHouseDriverOptionssocertificate material can be supplied programmatically from a
driverFactory(e.g. per-tenant client certificates loaded from a secret store). Mutual TLS
is enabled when
ca,certandkeyare all present;caalone enablesbasic TLS.
tlsmapping (env vars, programmaticssl, basic vs mutual, Buffer/string inputs, precedence).No new dependencies —
@clickhouse/clientis already a direct dependency andnatively supports these options.
Checklist
Notes for reviewers
connects lazily). A full integration test for mutual TLS would require a
TLS-enabled ClickHouse container (server cert + CA + an
ssl_certificateuser) and an extension of
ClickhouseDBRunnerintesting-shared. I'm happyto add that — I'd appreciate guidance on how you'd prefer the TLS test harness
shaped before investing in it.
yarn build/yarn lint/integration:clickhouselocally; please confirm CI is green.