Manage Aiven for ClickHouse® users and roles
Create Aiven for ClickHouse® users and roles and grant them specific privileges to control or restrict access to your service.
Manage users
Add a user
To create a user account for your service:
- Console
- SQL
-
Log in to the Aiven Console and choose your Aiven for ClickHouse service.
-
In the service sidebar, click Users.
This shows a list of all users that are currently available in your service. The default
avnadminuser has all available access grants to the service.tipTo view the roles and grants for any of the listed users, click View details & grants for that user.
-
On the Users page, click Add user.
-
In the Create a service user window, enter a name for the new user and click a role.
The role that you select defines the access grants that are assigned to the user. For more information on roles, see Manage roles and privileges.
-
Click Add user.
This creates the new user and shows you a summary of the information.
-
Copy the password on screen to a safe place. You can't access it again later, but you can reset it if needed.
To create a user by using a hash and salt, run:
CREATE USER username IDENTIFIED WITH sha256_hash BY 'hash' SALT 'salt';
To create a user using a password directly, run:
CREATE USER username IDENTIFIED BY 'password';
Users' password digests are stored securely in ZooKeeper. Only a super admin can access them. For users created in the console, their passwords are also salted with a random value. The password digests and salts are stored in backup files so they can be recovered.
Configure user settings
Configure user settings to control resource usage and query behavior. You can set limits at the user level (applying to all queries by that user) or configure per-query constraints.
Set user resource limits
Configure user settings, for example, to restrict resource use per user. This can help you:
- Prevent single users from monopolizing CPU threads and starving other users.
- Ensure fair distribution of system resources among all active users.
- Maintain system stability by preventing service overload.
-
Create a user named
limited_user.CREATE USER limited_user IDENTIFIED WITH SHA256_PASSWORD BY 'PASSWORD'; -
Set resource limit
max_threads = 1for this user.ALTER USER limited_user SETTINGS max_threads = 1; -
Grant read-only access to all databases and tables to
limited_user.GRANT SELECT ON *.* TO limited_user; -
Log in as
limited_userto test the configuration.clickhouse-client \
--host YOUR_HOST \
--port YOUR_PORT \
--user limited_user \
--password PASSWORD \
--secureReplace
YOUR_HOST,YOUR_PORT, andPASSWORDwith your service connection details. -
Verify the resource limit setting.
SHOW SETTINGS LIKE 'max_threads';This displays the
max_threadssetting with a value of1for thelimited_user.
Set per-query resource limits
Constrain resources on a per-query basis for specific users by setting query-level limits in their user profile.
-
Create a user with per-query memory and execution time limits.
CREATE USER query_limited_user IDENTIFIED WITH SHA256_PASSWORD BY 'PASSWORD'
SETTINGS max_memory_usage = 1000000000, max_execution_time = 30; -
Grant appropriate permissions.
GRANT SELECT ON *.* TO query_limited_user; -
Test the per-query limits by logging in and running a query.
clickhouse-client \
--host YOUR_HOST \
--port YOUR_PORT \
--user query_limited_user \
--password PASSWORD \
--secure -
Verify the query-level settings.
SHOW SETTINGS LIKE '%max_%';
Common per-query settings
max_memory_usage: Maximum memory per query (in bytes)max_execution_time: Maximum query execution time (in seconds)max_rows_to_read: Maximum rows a query can examinemax_result_rows: Maximum rows in query result
Manage roles and privileges
Aiven for ClickHouse has no predefined roles. All roles you create are custom roles you design for your purposes by granting specific privileges to particular roles. For example: you can create a role that allows only reading a single database, table, or column; or you can create another role that allows only inserting data, not deleting it.
ClickHouse® supports a Role Based Access Control model and allows you to configure access privileges by using SQL statements. You can either use the query editor or rely on the command-line interface.
The upstream ClickHouse documentation includes detailed documentation for access rights.
Create a role
To create a role named auditor, run the following command:
CREATE ROLE auditor;
Find more information on creating roles in the upstream ClickHouse documentation.