Skip to content

Percent-encode ClickHouse credentials in connection DSN - #2123

Open
mraj602 wants to merge 1 commit into
Altinity:0.28.0from
mraj602:fix/dsn-escape-credentials
Open

mraj602 wants to merge 1 commit into
Altinity:0.28.0from
mraj602:fix/dsn-escape-credentials

Conversation

@mraj602

@mraj602 mraj602 commented Oct 28, 2026

Copy link
Copy Markdown

Fixes #1822

The operator and the metrics exporter connect to ClickHouse via a DSN built in
pkg/model/clickhouse/credentials_endpoint.go as scheme://user:password@host:port,
with username and password inserted as-is. mailru/go-clickhouse parses the DSN with
url.Parse, so a password containing # is cut at the # (the reported
invalid port ":cs" after host), and @, /, ?, : or % either break the
parse or are read back as a different password.

This change percent-encodes username and password with net/url (url.User(s).String())
when building the DSN. Plain credentials produce the same DSN as before. The DSN used for
logging still shows *** for the password.

Tests: credentials_endpoint_test.go builds DSNs for several reserved-character passwords
and usernames (http and https, with and without log_queries), parses them with
goch.ParseDSN, and checks the user and password read back unchanged. Without the fix, 5 of 7 cases fail.

go test ./pkg/model/clickhouse/ passes. CHANGELOG entry added under 0.28.0 / Fixed.

A username or password holding URL-reserved characters such as '#', '@',
'/', '?' or '%' was put into the http(s)://user:password@host DSN as is,
so the driver failed to parse it or read back a different password.
Escape both with net/url before building the DSN.

Signed-off-by: Mayank Raj <mraj602@gmail.com>

This branch has not been deployed

No deployments
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.

2 participants