Distributed queries as the user configured in remote_servers. Unless you configured something else, that is default with an empty password. Before you remove the default user, create another administrator on every server and switch the cluster to a shared <secret>. Then remove default in the users configuration.
This article applies to self-managed ClickHouse. For a single server, see How do I remove the default user?.
Step 1: create a replacement administrator on every server
Connect asdefault (the users.xml file that ships with ClickHouse enables SQL access management for it) and create a role and a user on all servers of the cluster. Replace my_cluster with the name of your cluster:
default to the role. Run this statement on each server, connected as default:
GRANT CURRENT GRANTS grants everything the current user is able to grant. It cannot be combined with ON CLUSTER:
default, then log in as admin on every server before you continue:
Step 2: replace the user and password in remote_servers with a secret
On every server, add a <secret> to the definition of the cluster and remove the <user> and <password> elements of the replicas, if there are any:
- The servers authenticate each other with the secret instead of a user name and a password. Every server must define the cluster under the same name and with the same secret.
- A server that receives a
Distributedquery runs it as the user who started the query, not as the user fromremote_servers. Every user who queriesDistributedtables must therefore exist on all servers and have the privileges on the underlying local tables there. See theDistributedengine documentation.
Distributed queries fail with ALL_CONNECTION_TRIES_FAILED, and the log of the receiving server contains Interserver authentication failed with the code AUTHENTICATION_FAILED.
Check the result with a query that reaches every replica and reads its own entries in system.processes:
user column shows the account under which each replica runs its part of the query. Without the secret, the remote replicas report the user from remote_servers. This is the output on a cluster of two servers, for a query started by admin on node1:
currentUser function for this check: in a distributed query it returns the name of the user who started the query on every replica, with or without the secret.
Reload the Distributed tables
The check above covers queries that read. The background sends of a Distributed table are different: a table that existed before the change keeps the connections it was created with, so its queued inserts still go to the other servers as default, with or without the secret in the configuration. This is tracked in issue #136247. If you remove default in this state, the inserts of every such table stay in its queue and fail with AUTHENTICATION_FAILED for default. No rows are lost, but none arrive either.
After the secret is in place on all servers, make every server load its Distributed tables again. Either restart the servers one by one, or run this on each server for each Distributed table:
default before this step, the same two statements make the queued rows go out.
Step 3: remove the default user
The default user is defined in users.xml, not in SQL, so DROP USER default fails with ACCESS_STORAGE_READONLY. Remove it with an override file on every server, for example /etc/clickhouse-server/users.d/remove_default_user.xml:
remove attribute deletes the element from the merged configuration, and the server reloads the users configuration without a restart. A connection as default is then refused:
Why the order matters
If you removedefault while remote_servers has neither a secret nor another <user>, the servers still try to connect to each other as default, and every Distributed query that needs another server fails to authenticate. Configure the secret first, verify it, and remove the user last.
Before you remove the user, also look for everything else that connects as default without saying so:
- Clients, scripts and monitoring agents that do not pass a user name.
- Dictionaries with a
CLICKHOUSEsource and noUSER: such a source logs in asdefault, and the dictionary fails to load withAUTHENTICATION_FAILEDwhen that user does not exist. SetUSERandPASSWORDin the source first.
ON CLUSTER statements and replication do not depend on the default user. ON CLUSTER statements are distributed through a task queue in ClickHouse Keeper, and replicas authenticate to each other with interserver_http_credentials, if you configured them.
Instead of a secret you can keep
<user> and <password> in remote_servers and point them to a dedicated account. In that case the remote servers run all Distributed queries as that one account, whoever started the query.