如何禁止默认用户查看 clickhouse 中的数据库?

How to forbid default user from viewing a database in clickhouse?

我想限制默认用户从特定数据库读取表,但撤销命令给出了以下异常。

REVOKE SELECT ON test_db.* FROM default

Received exception from server (version 20.5.2):
Code: 495. DB::Exception: Received from localhost:9000. DB::Exception: Cannot update user `default` in [users.xml] because this storage is readonly. 

users.xml 拥有 666 权限。我想知道如何做到这一点,以便默认用户无法查看给定数据库中的表。

此答案基于使用 default-profile and inter-server credentials 的默认设置这一事实。


我不确定 default 用户是否应该被修改并且可以在集群外访问。默认情况下,它具有特殊用途,例如 interserver interaction in a cluster.

我建议限制 默认 用户使用内部集群节点:

<!-- users.xml -->
..
    <profiles>
        <default>
            <!-- default-profile is full-access profile (like super user).
            Do NOT restrict permissions of default-profile. The default profile has a special purpose: it must always be present
            and is applied when starting the server and used by internal processes (Buffer storage, Distibuted DDL worker and so on)
            -->
            ..
        </default>
        ..
    </profiles>

    <users>
        <!--
            default user that used ONLY for inter-server interaction.
            Password intentionally is EMPTY so this account MUST be restricted only inner network.
        -->
        <default>
            <password replace="replace"></password>
            <profile replace="replace">default</profile>

            <networks replace="replace">
                <!-- Restrict account to hosts belonging to the cluster. -->
                <host>clickhouse-node-1</host>
                <host>clickhouse-node-2</host>
                ..
            </networks>
        </default>
        ..
    </users>
..

并为您的目标添加一个 dedicated users 而不是使用 默认 一个。

有两种管理用户的方法。旧的 XML-way 和新的 create/grant/RBAC.

用户默认值是由旧的XML方式创建的(硬编码在 clickhouse 源代码中)

您可以完全删除此用户“默认”。

cat /etc/clickhouse-server/conf.d/z_user_def_remove.xml
<?xml version="1.0" ?>
<yandex>
    <users>
        <default remove="remove"></default>
    </users>
</yandex>

我用 z_ 命名文件以将其应用到结尾(作为最后一个)。

或者您可以“默认”限制此用户的数据库。

cat /etc/clickhouse-server/conf.d/user_def_db.xml
<?xml version="1.0" ?>
<yandex>
    <users>
        <default>
           <allow_databases>
            <database>system</database>
           </allow_databases>
        </default>
    </users>
</yandex>