问题描述:想限制特定的IP可以访问clickhouse,使用如下语句创建用户
drop user test;
CREATE USER test HOST IP '172.18.xxx.xxx' IDENTIFIED WITH sha256_password BY 'test';
GRANT SHOW, SELECT, INSERT ON test.* TO test;
客户端登陆:
确保输入的用户名和密码是正确的
clickhouse-client --host 172.18.xxx.xxx --port 9000 --user test --password test -m
错误信息:
Received from 172.18.xxx.xxx:9000. DB::Exception: test: Authentication failed:
password is incorrect or there is no user with such name.
ClickHouse client version 21.4.6.55 (official build).
Connecting to 172.18.52.122:9000 as user test.
Code: 516. DB::Exception:
Received from 172.18.xxx.xxx:9000. DB::Exception: test: Authentication failed:
password is incorrect or there is no user with such name.
问题解决过程:
1.telnet 数据库是通的
telnet 172.18.xxx.xxx 9000
2.创建用户不指定IP时可以正常访问数据库。
drop user test;
CREATE USER test IDENTIFIED WITH sha256_password BY ‘test’;
GRANT SHOW, SELECT, INSERT ON test.* TO test;
用户名,密码是正确的,网络也是通的,为什么指定IP后就不能正常访问呢?
首先想到的是去看clickhouse的日志,但查询clickhouse的日志也没发现有价值的信息。
还有什么地方能提供有用的信息呢,cilckhouse的query_log 出现了
3.查看query_log 后发现,initial_address并不是客户端的IP,而是网关的地址。
select initial_address n from system
.query_log ql where user=‘test’
为什么是网关的地址呢,原来客户端与clickhouse不在同一个网段,跨网段访问,要经过网关。
4.把授权IP地址改为网关后,可以正常访问。
但这样就失去了限制 IP 地址可以访问clickhouse的意义。