clickhouse-elixir / clickhouse_ecto

Ecto adapter for ClickHouse database
Apache License 2.0
64 stars 37 forks source link

Authorization doesn't work with later versions of Clickhouse #24

Closed drapadubok closed 3 years ago

drapadubok commented 3 years ago

When trying to connect to 21.7.4.18 version of CH, I get the following:

    :erlang.apply("Code: 516, e.displayText() = DB::Exception: Invalid authentication: 'Basic:' HTTP Authorization scheme is not supported (version 21.7.4.18 (official build))\n", :reason, [])
    (clickhousex 0.5.0) lib/clickhousex/http_client.ex:103: Clickhousex.HTTPClient.decode_response/3
    (clickhousex 0.5.0) lib/clickhousex/protocol.ex:37: Clickhousex.Protocol.connect/1
    (db_connection 2.4.0) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.15.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Judging from the implementation, it seems that the expected header is different from the one supplied: https://clickhouse.tech/codebrowser/html_report/ClickHouse/src/Server/HTTPHandler.cpp.html

E.g. changing from auth_header = {"Authorization", "Basic: #{auth_hash}"} -> auth_header = {"Authorization", "Basic #{auth_hash}"} should fix this. I can submit a PR, if this change makes sense, but I suspect this would affect backwards compatibility.

drapadubok commented 3 years ago

I'm sorry, I was supposed to post this to Clickhousex repo, closing.