|
| 1 | +--- |
| 2 | +title: Roles & Privileges |
| 3 | +description: Understand the role-based access control system, built-in roles, and how to define custom access policies. |
| 4 | +category: platform |
| 5 | +status: publish |
| 6 | +slug: roles |
| 7 | +--- |
| 8 | +import VideoPlayer from '@commons-components/Video/VideoPlayer.astro'; |
| 9 | +import createRole from '@docs-website-assets/introduction/video/roles-privileges/roles_create_custom_role.mp4'; |
| 10 | +import manageRole from '@docs-website-assets/introduction/video/roles-privileges/roles_manage_roles.mp4'; |
| 11 | + |
| 12 | +import Callout from "@commons-components/Information/Callout.astro"; |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +In SQLite Cloud, a **Role** is a named collection of permissions (privileges) that allows specific actions on resources like databases, tables. Users can have multiple roles, which determine their access to the system. |
| 17 | + |
| 18 | +Roles are the bridge between Users and Resources: |
| 19 | +* **Users** authenticate into the system. |
| 20 | +* **Roles** define what those users are allowed to do. |
| 21 | +* **Resources** (Databases, Tables) are the objects being accessed. |
| 22 | + |
| 23 | +You can manage role definitions via the SQLite Cloud Dashboard under the **Roles** section. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Built-in Roles |
| 28 | + |
| 29 | +SQLite Cloud comes with a set of pre-defined roles designed to cover the most common use cases. These roles are available immediately and cannot be modified, but they can be scoped to specific databases or tables when assigned to a user. |
| 30 | + |
| 31 | +### General Access Roles |
| 32 | +* **ADMIN:** This role possesses the highest level of privileges, with unrestricted access to all assigned permissions. |
| 33 | +* **READ:** Grants read-only access to a specified database or table. |
| 34 | +* **READWRITE:** Offers both read and write functionality for a specified database or table. |
| 35 | +* **DBADMIN:** Allows for administrative tasks like indexing and statistics gathering but doesn't manage users or roles. |
| 36 | + |
| 37 | +### Any Database Roles |
| 38 | +These roles implicitly apply to the entire cluster (`*`) and do not require specific scoping during assignment. |
| 39 | +* **READANYDATABASE:** Provides read-only access to any database and table. |
| 40 | +* **READWRITEANYDATABASE:** Grants read and write capabilities across any database and table. |
| 41 | +* **DBADMINANYDATABASE:** Provides administrative functions for any database. |
| 42 | + |
| 43 | +### Pub/Sub Roles |
| 44 | +* **SUB:** Grants the subscribe privilege to a specified database, table, or channel. |
| 45 | +* **PUB:** Offers the publish privilege to a specified database, table, or channel. |
| 46 | +* **PUBSUB:** Combines subscribe and publish privileges for a specified database, table, or channel. |
| 47 | +* **PUBSUBADMIN:** Allows the creation and removal of channel privileges for a specified database or channel. |
| 48 | +* **SUBANYCHANNEL**: Provides the subscribe privilege for any channel or table. |
| 49 | +* **PUBANYCHANNEL**: Grants the publish privilege for any channel or table. |
| 50 | +* **PUBSUBANYCHANNEL**: Combines subscribe and publish privileges for any channel or table. |
| 51 | +* **PUBSUBADMINANYCHANNEL**: Permits the creation and removal of channel privileges for any channel. |
| 52 | + |
| 53 | +### Cluster Management Roles |
| 54 | +* **USERADMIN:** Enables the creation and modification of roles and users. |
| 55 | +* **CLUSTERADMIN:** Empowers users to manage and monitor the cluster. |
| 56 | +* **CLUSTERMONITOR:** Offers read-only access to cluster monitoring commands. |
| 57 | +* **HOSTADMIN:** Allows monitoring and management of individual nodes. |
| 58 | + |
| 59 | +<Callout type="note" title="Restrictions"> |
| 60 | +To further refine the scope of a role or privilege, you can specify a database and table name during the [CREATE ROLE](/docs/role-commands), [GRANT ROLE](/docs/role-commands), <a href="https://docs.sqlitecloud.io/docs/privilege-commands" target="_blank">GRANT PRIVILEGE</a> and <a href="https://docs.sqlitecloud.io/docs/privilege-commands" target="_blank">SET PRIVILEGE</a> commands, as well as during the <a href="https://docs.sqlitecloud.io/docs/user-commands" target="_blank">CREATE USER</a> command. If `NULL` is used, it means that the role or privilege is not assigned and cannot function without specifying a database and table name combination. To extend the validity to any database and table, you can utilize the special `*` character. |
| 61 | +</Callout> |
| 62 | + |
| 63 | +Below is the technical definition of all built-in roles and their mapped privileges: |
| 64 | + |
| 65 | +```bash |
| 66 | +>> LIST ROLES |
| 67 | +-----------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------|--------------|-----------| |
| 68 | + rolename | builtin | privileges | databasename | tablename | |
| 69 | +-----------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------|--------------|-----------| |
| 70 | + ADMIN | 1 | READ,INSERT,UPDATE,DELETE,READWRITE,PRAGMA,CREATE_TABLE,CREATE_INDEX,CREATE_VIEW, | | | |
| 71 | + | | CREATE_TRIGGER,DROP_TABLE,DROP_INDEX,DROP_VIEW,DROP_TRIGGER,ALTER_TABLE,ANALYZE, | | | |
| 72 | + | | ATTACH,DETACH,DBADMIN,SUB,PUB,PUBSUB,BACKUP,RESTORE,DOWNLOAD,PLUGIN,SETTINGS,USERADMIN, | | | |
| 73 | + | | CLUSTERADMIN,CLUSTERMONITOR,CREATE_DATABASE,DROP_DATABASE,HOSTADMIN,SWITCH_USER,PUBSUBCREATE,PUBSUBADMIN,WEBLITE,ADMIN | NULL | NULL | |
| 74 | + READ | 1 | READ | NULL | NULL | |
| 75 | + READANYDATABASE | 1 | READ | * | * | |
| 76 | + READWRITE | 1 | READ,INSERT,UPDATE,DELETE,READWRITE | NULL | NULL | |
| 77 | + READWRITEANYDATABASE | 1 | READ,INSERT,UPDATE,DELETE,READWRITE | * | * | |
| 78 | + DBADMIN | 1 | READ,INSERT,UPDATE,DELETE,READWRITE,PRAGMA,CREATE_TABLE,CREATE_INDEX,CREATE_VIEW, | | | |
| 79 | + | | CREATE_TRIGGER,DROP_TABLE,DROP_INDEX,DROP_VIEW,DROP_TRIGGER,ALTER_TABLE,ANALYZE,ATTACH,DETACH,DBADMIN | NULL | NULL | |
| 80 | + DBADMINANYDATABASE | 1 | READ,INSERT,UPDATE,DELETE,READWRITE,PRAGMA,CREATE_TABLE,CREATE_INDEX,CREATE_VIEW, | | | |
| 81 | + | | CREATE_TRIGGER,DROP_TABLE,DROP_INDEX,DROP_VIEW,DROP_TRIGGER,ALTER_TABLE,ANALYZE,ATTACH,DETACH,DBADMIN | * | * | |
| 82 | + USERADMIN | 1 | USERADMIN | * | * | |
| 83 | + CLUSTERADMIN | 1 | CLUSTERADMIN | * | * | |
| 84 | + CLUSTERMONITOR | 1 | CLUSTERMONITOR | * | * | |
| 85 | + HOSTADMIN | 1 | BACKUP,RESTORE,DOWNLOAD,CREATE_DATABASE,DROP_DATABASE,HOSTADMIN | * | * | |
| 86 | + SUB | 1 | SUB | NULL | NULL | |
| 87 | + SUBANYCHANNEL | 1 | SUB | * | * | |
| 88 | + PUB | 1 | PUB | NULL | NULL | |
| 89 | + PUBANYCHANNEL | 1 | PUB | * | * | |
| 90 | + PUBSUB | 1 | SUB,PUB,PUBSUB | NULL | NULL | |
| 91 | + PUBSUBANYCHANNEL | 1 | SUB,PUB,PUBSUB | * | * | |
| 92 | + PUBSUBADMIN | 1 | SUB,PUB,PUBSUB,PUBSUBCREATE,PUBSUBADMIN | NULL | NULL | |
| 93 | + PUBSUBADMINANYCHANNEL | 1 | SUB,PUB,PUBSUB,PUBSUBCREATE,PUBSUBADMIN | * | * | |
| 94 | +-----------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------|--------------|-----------| |
| 95 | +``` |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Custom Roles |
| 100 | + |
| 101 | +If the built-in roles do not fit your specific security model, you can create **User-Defined Roles**. This allows you to mix and match specific privileges. |
| 102 | + |
| 103 | +### Creating a Custom Role |
| 104 | + |
| 105 | +1. Navigate to the **Roles** section in the left sidebar. |
| 106 | +2. Click the **Create Role** button. |
| 107 | +3. **Name:** Enter a unique name for the role (e.g., `AuditLogger`, `HRManager`). |
| 108 | +4. **Privileges:** Select the specific atomic privileges this role should possess (see list below). |
| 109 | +5. Click **Create**. |
| 110 | + |
| 111 | +<VideoPlayer src={createRole} /> |
| 112 | + |
| 113 | +### Managing Roles |
| 114 | + |
| 115 | +From the Roles list, you can: |
| 116 | +* **Inspect:** Click on a role to see exactly which privileges it contains. |
| 117 | +* **Edit:** Add or remove privileges from a custom role (Built-in roles cannot be edited). |
| 118 | +* **Delete:** Remove a custom role. |
| 119 | + |
| 120 | +<VideoPlayer src={manageRole} /> |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## Privileges Reference |
| 125 | + |
| 126 | +In a role-based access control system, a **Privilege** represents a specific action or permission that a user or role is allowed to perform within the system. |
| 127 | +It defines what a user can or cannot do, such as reading, writing, or managing certain resources like tables, databases, or settings. |
| 128 | +Essentially, a privilege is a **right** or **ability** granted to a user or role, specifying their level of access and control over the system's resources. |
| 129 | + |
| 130 | +A privilege can be <a href="https://docs.sqlitecloud.io/docs/privilege-commands" target="_blank">granted</a>, <a href="https://docs.sqlitecloud.io/docs/privilege-commands" target="_blank">revoked</a> and <a href="https://docs.sqlitecloud.io/docs/privilege-commands" target="_blank">assigned</a> to a given role. |
| 131 | +A role can contains any combination of privileges. |
| 132 | + |
| 133 | +Below is the complete list of available privileges: |
| 134 | + |
| 135 | +| | | | |
| 136 | +| :--- | :--- | :--- | |
| 137 | +| NONE | READ | INSERT | |
| 138 | +| UPDATE | DELETE | READWRITE | |
| 139 | +| PRAGMA | CREATE_TABLE | CREATE_INDEX | |
| 140 | +| CREATE_VIEW | CREATE_TRIGGER | DROP_TABLE | |
| 141 | +| DROP_INDEX | DROP_VIEW | DROP_TRIGGER | |
| 142 | +| ALTER_TABLE | ANALYZE | ATTACH | |
| 143 | +| DETACH | DBADMIN | SUB | |
| 144 | +| PUB | PUBSUB | BACKUP | |
| 145 | +| RESTORE | DOWNLOAD | PLUGIN | |
| 146 | +| SETTINGS | USERADMIN | CLUSTERADMIN | |
| 147 | +| CLUSTERMONITOR | CREATE_DATABASE | DROP_DATABASE | |
| 148 | +| HOSTADMIN | SWITCH_USER | PUBSUBCREATE | |
| 149 | +| PUBSUBADMIN | WEBLITE | ADMIN | |
0 commit comments