Skip to content

fix(clickhouse): use the upstream clickhouse-go driver - #615

Merged
lvrach merged 2 commits into
mainfrom
fix/sec-995-upstream-clickhouse-go
Nov 24, 2026
Merged

lvrach merged 2 commits into
mainfrom
fix/sec-995-upstream-clickhouse-go

Conversation

@lvrach

@lvrach lvrach commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Description

What changed

The ClickHouse driver imports github.com/ClickHouse/clickhouse-go/v2 v2.49.0. Before, it imported our fork of clickhouse-go at v2.48.0.

  • 17 Go files swap the import path.
  • go.mod requires upstream v2.49.0 directly and drops the fork. moby/moby/api and moby/moby/client move because v2.49.0 requires them. They are test-only.
  • Validation names network_compression_method when a profile refuses it at connection open (second commit).
  • Comments and .agents/knowledge name the upstream driver and point at v2.49.0 source files.

Why

The fork equals upstream v2.48.0 except for one line: it registers the database/sql driver as clickhouse-v2. This library never opens a connection by driver name, so the fork adds no behaviour. It does add upkeep, and a program that also uses upstream links both copies.

Behaviour that changes with v2.49.0

Every upstream hunk between v2.48.0 and v2.49.0 was checked against how this driver uses clickhouse-go. Most of the release touches the native protocol, batch inserts and DSN parsing, which this driver does not use. These changes reach us:

  • New setting on every query. With LZ4 on, clickhouse-go sends network_compression_method=LZ4, the hello included. That is the server default, so a readonly=1 profile accepts it. A profile that pins another value now refuses the connection. Before the second commit, validation blamed additional_result_filter for that refusal. Now it names network_compression_method. TestSQ14_ReadonlyAndConstraints covers it.
  • Named string parameters are escaped by the driver. A caller must not escape the value first. TestCP22_GoBindsTabString asserts the new behaviour. Nothing in this library uses Named.
  • A NUL byte in a positional string argument goes out as \0. Before, it went out as a raw byte.
  • A Map whose key type contains a comma now decodes. For example Map(DateTime64(3, 'UTC'), String). The read still fails, because the mapper does not support Map, but with CH_TYPE_UNSUPPORTED in place of CH_UNKNOWN.
  • The User-Agent says clickhouse-go/2.49.0.

Unchanged: the deadline handling (queryOptions), the response drain (discardAndClose), the HTTP health check, and what Row() returns for every column type the mapper reads.

How to verify

  • go test -count=1 ./sqlconnect/internal/clickhouse/... ./sqlconnect/clickhousequery/... passes (needs Docker).
  • go mod graph | grep rudderlabs/clickhouse-go prints nothing.

Not covered

  • The ClickHouse Cloud tests (clickhouse_cloud build tag) did not run. CI does not run them either. The default value of network_compression_method on ClickHouse Cloud is not checked.
  • The pinned network_compression_method case runs on server 26.3 with a CONST constraint only.
  • A program that imports this library and the fork must swap its own imports when it takes this release. The two modules have separate context keys and error types.

Linear Ticket

https://linear.app/rudderstack/issue/SEC-995

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

🤖 Generated with Claude Code

BEGIN_COMMIT_OVERRIDE
fix(clickhouse): use the upstream clickhouse-go driver (#615)
END_COMMIT_OVERRIDE

The ClickHouse driver imported a fork of clickhouse-go that differs from
upstream v2.48.0 only in the database/sql driver name. Nothing opens a
connection by that name, so the fork adds upkeep and no behaviour.
Consumers that also use upstream link both copies.

Import github.com/ClickHouse/clickhouse-go/v2 v2.49.0 instead.

v2.49.0 changes two things the tests can see:
- A Named string parameter is escaped by the driver. A caller must not
  escape it first. TestCP22_GoBindsTabString asserts the new behaviour.
- With LZ4 on, every HTTP request also sends
  network_compression_method=LZ4, the server default.

To verify: go test ./sqlconnect/internal/clickhouse/...
./sqlconnect/clickhousequery/... and check that go mod graph shows no
rudderlabs/clickhouse-go.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
clickhouse-go v2.49.0 sends network_compression_method with every query,
the hello included. A profile that pins another value refuses the open.
The probe that names the refused setting then blamed
additional_result_filter, because every probe carries the new setting.

Probe first with an empty settings map and no deadline. A refusal there
comes from the setting clickhouse-go adds, so validation names it.

To verify: go test -run TestSQ14_ReadonlyAndConstraints
./sqlconnect/internal/clickhouse/

Co-Authored-By: Claude Fable 5.2 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.73%. Comparing base (252bfc8) to head (4866e85).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #615   +/-   ##
=======================================
  Coverage   90.73%   90.73%           
=======================================
  Files         179      179           
  Lines        8861     8863    +2     
=======================================
+ Hits         8040     8042    +2     
  Misses        819      819           
  Partials        2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rudder-auto-approve rudder-auto-approve Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: this review is part of an experiment, the #proj-auto-approve auto-approval process. No human looked at this PR. Auto-approve category: refactors with no product behavior change.

Approved. The ClickHouse driver now imports upstream github.com/ClickHouse/clickhouse-go/v2 v2.49.0 instead of the fork at v2.48.0, and validation names network_compression_method when a profile refuses it at connection open.

What I checked:

  • The fork's v2.48.0 tag (0fd682b) is 4 commits ahead of upstream v2.48.0 (69b5195) and 0 behind. Outside examples, benchmarks, tests, docs and CI, its only library change besides the module path is clickhouse_std.go: sql.Register("clickhouse-v2", ...) in place of "clickhouse". A code search finds no clickhouse-v2 in this repository, so nothing here opens a connection by that driver name.
  • go.mod drops the fork and requires upstream v2.49.0. The moby/moby moves are indirect.
  • The second commit makes refusedOpenSetting try an empty settings map first. clickhouse-go still adds network_compression_method to the hello, so a refusal there names that setting, and TestSQ14_ReadonlyAndConstraints pins it with a ZSTD constraint (server code 452, stage 1).
  • The description lists the v2.49.0 behaviour changes that reach this driver, and says the ClickHouse Cloud tests did not run.
  • test, verify and zizmor pass.

[nit] The release notes for the next sqlconnect-go version should say that a program which imports both this library and the fork must swap its own imports, because the two modules have separate context keys and error types. The description says it; the changelog is where consumers will look.

To help the FYI next time:

  • Record the agreed migration plan on the tracking ticket, so the people who decided it show up there.

@lvrach

lvrach commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

On the release-notes nit: agreed. release-please writes the changelog from the PR title, so I add the import-swap note to the GitHub release of the version that ships this change. The consumer that imports both modules swaps its imports in the same PR that takes the release.

@lvrach
lvrach merged commit 5939b32 into main Nov 24, 2026
26 checks passed
@lvrach
lvrach deleted the fix/sec-995-upstream-clickhouse-go branch November 24, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant