Manage user privileges
This topic describes how to manage users, roles, and privileges in StarRocks.
StarRocks employs both role-based access control (RBAC) and identity-based access control (IBAC) to manage privileges within a StarRocks cluster, allowing cluster administrators to easily restrict privileges within the cluster on different granular levels.
Within a StarRocks cluster, privileges can be granted to users or roles. A role is a collection of privileges that can be assigned to users or other roles in the cluster as needed. A user can be granted one or more roles, which determine their permissions on different objects.
View privilege and role informationβ
Users with the system-defined role user_admin can view all the user and role information within the StarRocks 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.
SHOW GRANTS;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:SHOW GRANTS FOR jack@'172.10.1.10'; -
View the privileges of a specific role.
The following example shows the privileges of the role
example_role:SHOW GRANTS FOR ROLE example_role;
View rolesβ
You can view all the roles within the StarRocks cluster using SHOW ROLES.
SHOW ROLES;
Manage rolesβ
Users with the system-defined role user_admin can create, grant, revoke, or drop roles in StarRocks.
Create a roleβ
You can create a role using CREATE ROLE. By default, a user can have a maximum of 64 roles. You can adjust this setting by using the FE dynamic parameter privilege_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:
CREATE 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 example_role TO USER jack@'172.10.1.10'; -
Grant a role to another role.
The following example grants the role
example_roleto the roletest_role:GRANT example_role TO ROLE test_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:GRANT example_role TO EXTERNAL GROUP analysts;
Alter the default role of a userβ
The default role of a user is automatically activated when the user connects to StarRocks. 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 of jack to db1_admin. Note that db1_admin must have been assigned to jack.
-
Set the default role using SET DEFAULT ROLE:
SET DEFAULT ROLE 'db1_admin' TO jack@'172.10.1.10'; -
Set the default role using ALTER USER:
ALTER USER jack@'172.10.1.10' DEFAULT ROLE 'db1_admin';
Revoke a roleβ
You can revoke roles from a user or another role using REVOKE.
NOTE
You cannot revoke the system-defined default role
PUBLICfrom a user.
-
Revoke a role from a user.
The following example revokes the role
example_rolefrom the userjack:REVOKE example_role FROM USER jack@'172.10.1.10'; -
Revoke a role from another role.
The following example revokes the role
example_rolefrom the roletest_role:REVOKE example_role FROM ROLE test_role;
Drop a roleβ
You can drop a role using DROP ROLE.
The following example drops the role example_role:
DROP ROLE example_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 StarRocks cluster.
If you want to enable all the roles (default and granted roles) for all StarRocks users when they connect to the StarRocks cluster, you can perform the following operation.
This operation requires the system privilege OPERATE.
SET GLOBAL activate_all_roles_on_login = TRUE;
You can also use SET ROLE to activate the roles assigned to you. For example, user 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 StarRocks. 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 role user_admin can grant or revoke privileges in StarRocks.
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 SELECT ON TABLE sr_member TO USER jack@'172.10.1.10' WITH GRANT OPTION; -
Grant a privilege to a role.
The following example grants the SELECT privilege on the table
sr_memberto the roleexample_role:GRANT SELECT ON TABLE sr_member TO ROLE example_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 SELECT ON TABLE sr_member FROM USER jack@'172.10.1.10'; -
Revoke a privilege from a role.
The following example revokes the SELECT privilege on the table
sr_memberfrom the roleexample_role:REVOKE SELECT ON TABLE sr_member FROM ROLE example_role;
Best practicesβ
Multi-service access controlβ
Usually, a company-owned StarRocks 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 StarRocks 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.

LOB A independently manages the database 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.

Because different members perform different operations on different databases and tables, we recommend you create roles in accordance with their services and pos