View privilege and role information
Users with the system-defined roleuser_admin can view all the user and role information within the cluster.
View privilege information
You can view the privileges granted to a user or a role using SHOW GRANTS.-
View the privileges of the current user.
NOTE Any user can view their own privileges without needing any privileges.
-
View the privileges of a specific user.
The following example shows the privileges of the user
jack: -
View the privileges of a specific role.
The following example shows the privileges of the role
example_role:
View roles
You can view all the roles within the cluster using SHOW ROLES.Manage roles
Users with the system-defined roleuser_admin can create, grant, revoke, or drop roles in the database.
Create a role
You can create a role using CREATE ROLE. By default, a user can have a maximum of 64 roles, including the roles inherited through the roles granted to the user. This limit is checked when a role is granted to a user. You can adjust this setting by using the FE dynamic parameterprivilege_max_total_roles_per_user. A role can have a maximum of 16 inheritance levels. You can adjust this setting by using the FE dynamic parameter privilege_max_role_depth.
The following example creates the role example_role:
Grant a role
You can grant roles to a user or another role using GRANT.-
Grant a role to a user.
The following example grants the role
example_roleto the userjack: -
Grant a role to another role.
The following example grants the role
example_roleto the roletest_role: -
Grant a role to a user group. You can identify user groups from external authentication systems via Group Provider.
The following example grants the role
example_roleto the user groupanalysts:
Alter the default role of a user
The default role of a user is automatically activated when the user connects to the database. For instructions on how to enable all (default and granted) roles for a user after connection, see Enable all roles. You can set the default role of a user using SET DEFAULT ROLE or ALTER USER. Both of the following examples set the default role ofjack to db1_admin. Note that db1_admin must have been assigned to jack.
-
Set the default role using SET DEFAULT ROLE:
-
Set the default role using ALTER USER:
Revoke a role
You can revoke roles from a user or another role using REVOKE.
NOTE
You cannot revoke the system-defined default role PUBLIC from a user.
-
Revoke a role from a user.
The following example revokes the role
example_rolefrom the userjack: -
Revoke a role from another role.
The following example revokes the role
example_rolefrom the roletest_role:
Drop a role
You can drop a role using DROP ROLE. The following example drops the roleexample_role:
CAUTION System-defined roles cannot be dropped.
Enable all roles
The default roles of a user are roles that are automatically activated each time the user connects to the cluster. If you want to enable all the roles (default and granted roles) for all users when they connect to the cluster, you can perform the following operation. This operation requires the system privilege OPERATE.jack@'172.10.1.10' has roles db_admin and user_admin but they are not default roles of the user and are not automatically activated when the user connects to the database. If jack@'172.10.1.10' needs to activate db_admin and user_admin, he can run SET ROLE db_admin, user_admin;. Note that SET ROLE overwrites original roles. If you want to enable all your roles, run SET ROLE ALL.
Manage privileges
Users with the system-defined roleuser_admin can grant or revoke privileges in the database.
Grant privileges
You can grant privileges to a user or a role using GRANT.-
Grant a privilege to a user.
The following example grants the SELECT privilege on the table
sr_memberto the userjack, and allowsjackto grant this privilege to other users or roles (by specifying WITH GRANT OPTION in the SQL): -
Grant a privilege to a role.
The following example grants the SELECT privilege on the table
sr_memberto the roleexample_role:
Revoke privileges
You can revoke privileges from a user or a role using REVOKE.-
Revoke a privilege from a user.
The following example revokes the SELECT privilege on the table
sr_memberfrom the userjack, and disallowsjackto grant this privilege to other users or roles: -
Revoke a privilege from a role.
The following example revokes the SELECT privilege on the table
sr_memberfrom the roleexample_role:
Best practices
Multi-service access control
Usually, a company-owned cluster is managed by a sole service provider and maintains multiple lines of business (LOBs), each of which uses one or more databases. As shown below, a cluster’s users include members from the service provider and two LOBs (A and B). Each LOB is operated by two roles - analysts and executives. Analysts generate and analyze business statements, and executives query the statements.
DB_A, and LOB B the database DB_B. LOB A and LOB B use different tables in DB_C. DB_PUBLIC can be accessed by all members of both LOBs.


-
Assign the system-defined roles
db_admin,user_admin, andcluster_adminto cluster maintainers, setdb_adminanduser_adminas their default roles for daily maintenance, and manually activate the rolecluster_adminwhen they need to operate the nodes of the cluster. Example: - Create users for each member within the LOBs, and set complex passwords for each user.
-
Create roles for each position within the LOBs, and apply the corresponding privileges to each role.
For the director of each LOB, grant their role the maximum collection of the privileges their LOBs need, and the corresponding GRANT privileges (by specifying WITH GRANT OPTION in the statement). Therefore, they can assign these privileges to the members of their LOB. Set the role as their default role if their daily work requires it.
Example:
For analysts and executives, assign them the role with the corresponding privileges. Example:
-
For the database
DB_PUBLIC, which can be accessed by all cluster users, grant the SELECT privilege onDB_PUBLICto the system-defined rolepublic. Example:
DB_PUBLIC, and executives can only query these tables, you can create roles public_analysis and public_sales, apply relevant privileges to the roles, and assign them to the original roles of analysts and executives respectively.
Example:
Customize roles based on scenarios
We recommend you customize roles to manage privileges and users. The following examples classify a few combinations of privileges for some common scenarios.
Grant global read-only privileges on tables
Grant global write privileges on tables
Grant read-only privileges on a specific external catalog
Grant write-only privileges on a specific external catalog
You can only write data into Iceberg tables (since v3.1) and Hive tables (since v3.2).Grant admin privileges on a specific database
Grant privileges to perform backup and restore operations on global, database, table, and partition levels
-
Grant privileges to perform global backup and restore operations:
The privileges to perform global backup and restore operations allow the role to back up and restore any database, table, or partition. It requires the REPOSITORY privilege on the SYSTEM level, the privileges to create databases in the default catalog, to create tables in any database, and to load and export data on any table.
-
Grant the privileges to perform database-level backup and restore operations:
The privileges to perform database-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, the privilege to create databases in the default catalog, the privilege to create tables in any database, the privilege to load data into any table, and the privilege export data from any table in the database to be backed up.
-
Grant the privileges to perform table-level backup and restore operations:
The privileges to perform table-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, the privilege to create tables in corresponding databases, the privilege to load data into any table in the database, and the privilege to export data from the table to be backed up.
-
Grant the privileges to perform partition-level backup and restore operations:
The privileges to perform partition-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, and the privilege to load and export data on the corresponding table.