DB::Exception: test: Authentication failed: [How to Solve]

Problem Description: if you want to restrict specific IP addresses from accessing the Clickhouse, use the following statement to create a user

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;

Client login:
ensure that the user name and password entered are correct

clickhouse-client --host 172.18.xxx.xxx  --port 9000  --user test --password test  -m

Error Messages:
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.

Problem solving process:

1. Telnet database is accessible
telnet 172.18.xxx.xxx 9000

2. The database can be accessed normally when the user does not specify IP
drop user test;
CREATE USER test IDENTIFIED WITH sha256_ password BY ‘test’;
GRANT SHOW, SELECT, INSERT ON test.* TO test;

The user name and password are correct, and the network is connected. Why can’t you access normally after specifying the IP
the first thought is to look at the Clickhouse log, but no valuable information can be found by querying the Clickhouse log
where else can you provide useful information?Cilckhouse’s query_ The log appears

3. View query_ Log, initial_ Address is not the IP address of the client, but the address of the gateway
select initial_ address n from system.query_ Log QL where user = “test”
why is the address of the gateway?It turns out that the client and Clickhouse are not in the same network segment. Access across network segments must pass through the gateway.

4. After changing the authorized IP address to the gateway, it can be accessed normally
in this way, the meaning of restricting IP addresses from accessing Clickhouse is lost.

Read More: