Skip to content

Conversation

@chernser
Copy link
Contributor

@chernser chernser commented Oct 29, 2024

Summary

Password can be passed as value of the X-ClickHouse-Key header docs. But header values have some limitations about what characters can be used (learned from practical tests and https://www.rfc-editor.org/rfc/rfc7230#section-3.2.6) what would require escaping special chars. Basic authentication helps to avoid all this and is standard authentication mechanism.
This PR changes both clients (v1, v2).

New configuration parameter is added:

  • com.clickhouse.client.http.config.ClickHouseHttpOption#USE_BASIC_AUTHENTICATION - allows to switch using ClickHouse X- headers to authenticate. Default is using basic auth.

Closes: #1305

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

} else if (!ClickHouseChecker.isNullOrEmpty(credentials.getPassword())) {
map.put("x-clickhouse-key", credentials.getPassword());
} else {
String password = credentials.getPassword() == null ? "" : credentials.getPassword();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to understand you have changed the logic to use Basic authorization to avoid the illegal characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I've changed this logic to avoid problem with different characters.
So even sequence =? is getting problem.
Additionally it does things more standard.
Javascript Client uses this approach as default - https://github.com/ClickHouse/clickhouse-js/blob/main/packages/client-node/src/connection/node_base_connection.ts#L87

@mzitnik
Copy link
Contributor

mzitnik commented Oct 30, 2024

@chernser please validate discussed

@sonarqubecloud
Copy link

@chernser chernser merged commit 85f7bae into main Oct 31, 2024
59 of 60 checks passed
@chernser chernser deleted the fix_password_authentication branch October 31, 2024 16:57
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.

clickhouse-jdbc password contains =? Connection failed.

2 participants