Skip to main content
To give a user full access to one database and nothing else, create a role and run GRANT CURRENT GRANTS ON <database>.* TO <role>. The role receives every privilege that you hold yourself with the grant option and that can be limited to a database. You do not have to list the privileges, and GRANT ALL, which is not supported in ClickHouse Cloud, is not needed.

Create the role and the user

Run the statements as the default user or as another user with default_role, and replace <password> with a strong password:
All roles granted to a new user are its default roles, so app_db_admin is active as soon as app_user connects:
To see the privileges that the role received, run:
The result is a single GRANT ... ON app_db.* TO app_db_admin statement. Its list of privileges depends on the privileges of the user that ran GRANT CURRENT GRANTS. It includes SHOW, SELECT, INSERT, ALTER, CREATE TABLE, DROP TABLE, TRUNCATE and OPTIMIZE if that user holds them with the grant option.

Check the access

Connect as app_user. Creating, changing, reading and dropping tables in app_db works:
Anything outside the database is refused:
The statement fails with the ACCESS_DENIED error: Not enough privileges. To execute this query, it's necessary to have the grant CREATE DATABASE ON other_db.*.

If the user cannot create tables

On a server that requires grants for table engines, CREATE TABLE fails for the new user with Not enough privileges. To execute this query, it's necessary to have the grant TABLE ENGINE ON MergeTree. The TABLE ENGINE privilege is granted per engine name, not per database, so GRANT CURRENT GRANTS ON app_db.* does not include it. Grant it to the role separately, for all engines or for the engines the user needs:

What the role can and cannot do

  • The role has no privileges that cannot be limited to a database, even if you hold them: for example creating users and roles, KILL QUERY, CREATE FUNCTION, or reading from external sources such as S3 and URL. Grant them separately if the user needs them.
  • The role can drop app_db itself and create it again. To prevent this, run REVOKE DROP DATABASE ON app_db.* FROM app_db_admin.
  • The privileges are copied when you run the statement. If you get more privileges later, run GRANT CURRENT GRANTS ON app_db.* TO app_db_admin again to add them to the role. Running it again only adds privileges. A privilege that you have lost stays on the role until a user that holds it with the grant option revokes it, for example with REVOKE DROP TABLE ON app_db.* FROM app_db_admin.
  • Grants refer to the database by name. They stay in place if the database is dropped and created again.
  • To let the user grant these privileges to other users and roles, add WITH GRANT OPTION to the GRANT CURRENT GRANTS statement.