ClickHouse仅向用户授予数据库中多个表的访问权限

时间:2019-09-16 08:30:51

标签: permissions access clickhouse

我在Clickhouse中有两个数据库:

  • 测试
  • test2

此数据库中通过查询创建的表:

CREATE TABLE test.Migrations3 ( date Date DEFAULT toDate(now()), id UInt8, time UInt64) ENGINE = ReplicatedMergeTree('/clickhouse/tables/shard/test/Migrations3', 'clickhouse1', date, (id, time), 8192);

,我为这些数据库创建了两个用户。 用户权限如下:

        <user>
            <password>pass</password>
            <networks incl="networks" replace="replace">
                <ip>::/0</ip>
                <ip>127.0.0.1</ip>
            </networks>
            <!-- Settings profile for user. -->
            <profile>default</profile>
            <!-- Quota for user. -->
            <quota>default</quota>

        </user>

我在这些表中得到了一些数据,它是这样插入的:

INSERT INTO test.Migrations3 (date) VALUES (689);

现在,我想创建一个新的只读用户,该用户可以访问数据库测试,但只适用于此DB中的表Migrations3,而不适用于数据库中的所有表。 我阅读了文档,但找不到如何设置此访问权限。

现在,我尝试使用以下权限:

<user1>
    <databases>
        <test>
            <Migrations3>
                <filter>id = 1</filter>
            </Migrations3>
        </test>
    </databases>

    <password>pass</password>
            <networks incl="networks" replace="replace">
                <ip>::/0</ip>
                <ip>127.0.0.1</ip>
            </networks>
            <!-- Settings profile for user. -->
            <profile>readonly</profile>
            <!-- Quota for user. -->
            <quota>default</quota>
<allow_databases>
<database>test</database>
</allow_databases>

</user1>

当我运行select * from test.Migrations3时,我看到了所有行,但是我已经在权限中设置过滤器,只显示id -eq 1

我做错了什么?

2 个答案:

答案 0 :(得分:2)

对不起,但是当前您可以设置对整个数据库的访问权限 https://clickhouse.yandex/docs/en/operations/access_rights/ 但是您可以通过行级安全性来限制对表的访问 如此处https://clickhouse.yandex/docs/en/operations/settings/settings_users/#user-name-databases

所述
LAG(sea.ROW_ID,1) over (order by sea.CREATED_DTTM) AS 'FLAGID'

答案 1 :(得分:1)

以下配置强制用户user1只能在SELECT查询的结果中看到table1的行,其中id字段的值为1000。

<user1>
<databases>
    <database_name>
        <table1>
            <filter>id = 1000</filter>
        </table1>
    </database_name>
</databases>
</user1>

过滤器可以是任何产生UInt8类型值的表达式。它通常包含比较和逻辑运算符。该用户未返回database_name.table1中过滤结果为0的行。过滤与PREWHERE操作不兼容,并且会禁用WHERE→PREWHERE优化。