Clickhouse官方文档意味着一个用户只能拥有一个配置文件,并且在user
部分配置了数据库,在配置文件部分配置了readonly
,因此readonly
将影响所有用户的配置文件数据库。
因此,如何设置一个用户x
,该用户只能读取数据库dbA
,但是可以读写数据库dbB
?
答案 0 :(得分:1)
考虑使用SQL-driven access control management:
CREATE DATABASE db_01;
CREATE DATABASE db_02;
CREATE TABLE db_01.table_01 (id Int32) Engine = Memory();
CREATE TABLE db_02.table_02 (id Int32) Engine = Memory();
INSERT INTO db_01.table_01 VALUES (1), (2);
INSERT INTO db_02.table_02 VALUES (10), (20);
CREATE USER user_01 HOST ANY PROFILE 'default';
/* Set readonly access to DB 'db_01'. */
GRANT SELECT ON db_01.* TO user_01;
/* Set read-write access to DB 'db_02'. */
GRANT SELECT ON db_02.* TO user_01;
GRANT INSERT ON db_02.* TO user_01;
SELECT currentUser(); /* Make sure that user is right. */
/*
┌─currentUser()─┐
│ user_01 │
└───────────────┘
*/
SHOW GRANTS; /* Double check the assigned privileges. */
/*
┌─GRANTS─────────────────────────────────────┐
│ GRANT SELECT ON db_01.* TO user_01 │
│ GRANT INSERT, SELECT ON db_02.* TO user_01 │
└────────────────────────────────────────────┘
*/
SELECT * FROM db_01.table_01; /* OK */
INSERT INTO db_01.table_01 VALUES (3); /* DB::Exception: user_01: Not enough privileges. */
SELECT * FROM db_02.table_02; /* OK */
INSERT INTO db_02.table_02 VALUES (30); /* OK */
上面的代码仅用于演示,您需要考虑引入角色/ quotas / ..,继承另一个用户配置文件(更具限制性,而不是“默认”)等。