Skip to content

Commit 40f6d6f

Browse files
TizianoTandinux
andauthored
Stage (#140)
* chore(docs): restructure security docs and enhance API Keys documentation Separated Users and Roles & Privileges into dedicated pages for better organization. Completely rewrote API Keys documentation with detailed instructions for creating, managing, and using API keys. Cleaned up navigation structure and removed duplicate content. * docs: update OffSync page for v1.5.0 UI redesign - Remove outdated video imports (old UI recordings) - Add Enabling/Disabling OffSync section with dialog flow - Rewrite Configuration tab: Database ID + SQL snippet + Push Notifications - Add Metrics tab section (active devices, upload/download bytes) - Update intro to reflect 4-tab layout * docs: add enable/disable OffSync video to offsync page * docs: remove obsolete section "Advanced: RLS and SQLite Sync" * docs: enhance OffSync documentation for Database ID and Push Notifications configuration * docs: comment out video player for OffSync enable/disable functionality --------- Co-authored-by: Andrea Donetti <andinux@gmail.com>
1 parent 3e42802 commit 40f6d6f

File tree

8 files changed

+366
-58
lines changed

8 files changed

+366
-58
lines changed

sqlite-cloud/_nav.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ const sidebarNav: SidebarNavStruct = [
287287
{ title: "Webhooks", filePath: "webhooks", type: "inner", level: 0 },
288288
{ title: "Pub/Sub", filePath: "pub-sub", type: "inner", level: 0 },
289289
//{ title: "Vector", filePath: "vector", type: "inner", level: 0 },
290-
{ title: "Users and Roles", filePath: "security", type: "inner", level: 0 },
290+
{ title: "Users", filePath: "users", type: "inner", level: 0 },
291+
{ title: "Roles & Privileges", filePath: "roles", type: "inner", level: 0 },
291292
{ title: "API Keys", filePath: "apikey", type: "inner", level: 0 },
292293
{ title: "Row-Level Security", filePath: "rls", type: "inner", level: 0 },
293294
{ title: "OffSync", filePath: "offsync", type: "inner", level: 0 },

sqlite-cloud/platform/apikey.mdx

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,75 @@
11
---
22
title: Security and Access Control
3-
description: SQLite Cloud provides secure access to resources through role-based authorization, which ensures user isolation and enhances security and manageability.
3+
description: Manage API Keys for secure application access, server-to-server communication, and SDK integration.
44
category: platform
55
status: publish
66
slug: apikey
77
---
88

9-
## API KEYs
109

1110
API KEYs can be used as an alternative authentication mechanism.
1211
Authentication through API keys ensures the same privileges as the user to which they are associated.
1312
API KEYs are recommended for all server-to-server authentication cases and are necessary for using the REST APIs and the SDKs that uses the WebSocket APIs.
1413

15-
To create an API key for a user, click on the **Create API KEY** button.
14+
You can manage all keys in your cluster via the SQLite Cloud Dashboard under the **API Keys** section.
1615

17-
![Dashboard Create APIKEY](@docs-website-assets/introduction/dashboard_create_apikey.png)
16+
---
17+
18+
## Creating an API Key
19+
20+
You can create an API Key and immediately assign it to any existing user in your cluster.
21+
22+
1. Navigate to the **API Keys** section in the left sidebar.
23+
2. Click the **Create API Key** button.
24+
3. **API Key Name:** Enter a descriptive name to identify the key (e.g., `MobileApp_Prod`, `Backend_Worker`).
25+
4. **User:** Select the user this key will impersonate from the dropdown list.
26+
5. **Expiration:**
27+
* Select **Never expires** for long-running services.
28+
* Select **Set expiration date** to enforce a rotation policy or for temporary access tokens.
29+
6. Click **Create**.
30+
31+
[VIDEO: create_apikey_global.mp4]
32+
{/* <!-- Video showing the global creation flow: entering a name, selecting a user from the dropdown, picking a date, and creating --> */}
33+
34+
---
35+
36+
## Managing API Keys
37+
38+
The API Keys list provides a centralized view of all active keys, their associated users, and expiration status.
39+
40+
### Regenerating a Key
41+
If a key is lost, forgotten, or you suspect it has been compromised (leaked), you should regenerate it immediately.
42+
43+
1. Find the key in the list.
44+
2. Click the context menu (three dots) on the right.
45+
3. Select **Regenerate**.
46+
4. Confirm the action in the modal window.
47+
48+
**Warning:** Regenerating a key invalidates the old key string immediately. You must update any applications or scripts using the old key with the new value to restore connectivity.
49+
50+
[VIDEO: regenerate_apikey.mp4]
51+
{/* <!-- Video showing the regenerate flow and the confirmation modal --> */}
52+
53+
### Editing and Deleting
54+
* **Edit:** Allows you to rename the key or change its expiration settings without changing the key string itself.
55+
* **Delete:** Permanently revokes the key. Applications using this key will no longer be able to connect.
56+
57+
[VIDEO: delete_apikey.mp4]
58+
{/* <!-- Video showing the delete action --> */}
59+
60+
---
61+
62+
## Using API Keys
63+
64+
Once generated, the API Key is typically used in the connection string of your SQLite Cloud client or SDK.
65+
66+
The standard format for a connection string using an API Key is:
67+
```
68+
sqlitecloud://<host>:<port>?apikey=<your-api-key>
69+
```
70+
71+
When using the REST API directly, the key should be passed in the Authorization header:
1872

19-
The resulting table will display all the API keys associated with each user, along with their name.
20-
![Dashboard List APIKEY](@docs-website-assets/introduction/dashboard_list_apikey.png)
73+
```http
74+
Authorization: Bearer <your-api-key>
75+
```

sqlite-cloud/platform/offsync.mdx

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ slug: offsync
77
---
88

99
import VideoPlayer from '@commons-components/Video/VideoPlayer.astro';
10-
import enableSync from '@docs-website-assets/introduction/video/dashboard_sqlite_sync_enabling.mp4';
11-
import connectionUrlSync from '@docs-website-assets/introduction/video/dashboard_sync_connection_url.mp4';
12-
import devicesSync from '@docs-website-assets/introduction/video/dashboard_sync_devices.mp4';
1310

1411
import Callout from "@commons-components/Information/Callout.astro";
1512

@@ -31,35 +28,65 @@ OffSync extends standard SQLite tables with built-in support for offline work an
3128
When combined with [Row-Level Security (RLS)](/docs/rls), OffSync allows you to build secure, multi-tenant applications where each user's data is safely isolated, both on the edge and in the cloud.
3229

3330

34-
---
31+
---
3532

3633
## Configuring OffSync
3734

38-
You can enable and manage OffSync for your databases directly from the SQLite Cloud dashboard.
39-
Below are the main steps:
35+
You can enable and manage OffSync for your databases directly from the SQLite Cloud dashboard.
36+
The OffSync panel has four tabs: **Sync Tables**, **Configuration**, **Devices**, and **Metrics**.
37+
38+
### Enabling and Disabling OffSync
39+
40+
When OffSync is not yet active for a database, the panel shows a brief explanation and an **Enable OffSync** button. Clicking it opens a confirmation dialog; after confirming, the database is registered with the sync service and the tabbed view appears.
41+
42+
To disable OffSync, click the **Disable OffSync** button in the top-right corner of the panel and confirm the action in the dialog that appears.
43+
44+
{/* <VideoPlayer src={enableDisableSync} /> */}
4045

4146
### Enable Tables for Synchronization
42-
From the **Sync Tables** tab, select which tables in your database you want to keep synchronized.
47+
48+
From the **Sync Tables** tab, select which tables in your database you want to keep synchronized.
4349
Once enabled, all changes to those tables will automatically sync with connected devices.
4450

45-
<VideoPlayer src={enableSync} />
51+
{/* VIDEO: dashboard_offsync_sync_tables.mp4
52+
Show: Sync Tables tab open → toggle one or more tables on → confirmation that sync is active for those tables. */}
53+
54+
### Configuration Tab
4655

56+
The **Configuration** tab contains two sub-sections:
4757

48-
### Get the Connection String
49-
In the **Configuration** tab, copy the connection string.
50-
Use this in your application to initialize OffSync and connect your local SQLite database with SQLite Cloud.
58+
**Database ID** — A read-only field showing the unique identifier for your OffSync-enabled database, with a copy button for convenience. Use this ID in your application to initialize the sync connection (see the <a href="https://github.com/sqliteai/sqlite-sync" target="_blank">sqlite-sync README</a> for more details):
5159

52-
<VideoPlayer src={connectionUrlSync} />
60+
```sql
61+
SELECT cloudsync_network_init('<database-id>');
62+
```
5363

64+
**Push Notifications** — Push notifications work out of the box. If you have enabled Expo enhanced security, provide your access token here. This is only required when using the `sqlite-sync-react-native` library with push mode enabled — the token adds an extra layer of security to prevent unauthorized push notifications.
65+
66+
{/* VIDEO: dashboard_offsync_configuration.mp4
67+
Show: Configuration tab open → Database ID field with copy button clicked → scroll down to Push Notifications section → paste an Expo token → save → status changes to "Working". */}
5468

5569
### Manage Connected Devices
56-
In the **Devices** tab, you can view all devices currently connected to your database.
70+
71+
In the **Devices** tab, you can view all devices currently connected to your database.
5772
Here you can check their sync status and remove devices if needed.
5873

59-
<VideoPlayer src={devicesSync} />
74+
{/* VIDEO: dashboard_offsync_devices.mp4
75+
Show: Devices tab open with a list of connected devices → inspect sync status of one device → remove a device from the list. */}
6076

6177
<Callout type="note" title="Matching Schemas and Tables">
6278
For OffSync to work correctly, the list of tables configured for synchronization—and their corresponding schemas—must be identical in both your local SQLite database and your SQLite Cloud database.
6379
</Callout>
6480

81+
### Metrics Tab
82+
83+
The **Metrics** tab provides visibility into daily and cumulative usage for your OffSync-enabled database:
84+
85+
- **Active devices** — number of devices that have synced within the period
86+
- **Upload bytes** — data sent from devices to SQLite Cloud
87+
- **Download bytes** — data sent from SQLite Cloud to devices
88+
89+
{/* VIDEO: dashboard_offsync_metrics.mp4
90+
Show: Metrics tab open → scroll through active devices chart → upload bytes chart → download bytes chart, ideally with some non-zero data visible. */}
91+
6592
Once enabled, any changes made to the selected tables via the SQLite Sync extension will be automatically synchronized with your SQLite Cloud database.

sqlite-cloud/platform/pub-sub.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ status: publish
66
slug: pub-sub
77
---
88

9-
# SQLiteCloud Pub/Sub System
109

1110
**Publish/Subscribe (Pub/Sub)** is a messaging pattern that enables asynchronous communication between multiple applications. In the context of **SQLiteCloud**, Pub/Sub provides a robust way to deliver real-time updates or custom messages to subscribed clients when data changes or explicit notifications are issued.
1211

sqlite-cloud/platform/rls.mdx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,3 @@ OLD.status <> 'paid'
254254

255255
**Explanation:**
256256
This policy uses the `OLD` reference to check the value of the `status` column *before* the update is applied. If the status is already `'paid'`, the condition `OLD.status <> 'paid'` will be false, and the `UPDATE` operation will be denied. This effectively makes paid invoices read-only.
257-
258-
259-
---
260-
261-
## Advanced: RLS and SQLite Sync
262-
263-
When using RLS in conjunction with <a href="https://github.com/sqliteai/sqlite-sync" target="_blank">SQLite Sync</a>, it's important to understand how they interact. The Sync protocol applies changes on a column-by-column basis, which can affect how `INSERT` and `UPDATE` policies are evaluated.
264-
265-
To accommodate this, SQLite Cloud offers two modes for handling RLS during sync operations, configurable via the `rls_mode` server setting using the SQLite Cloud builtin command `SET KEY rls_mode TO <value>`.
266-
267-
#### Default Mode (`rls_mode = 1`)
268-
269-
To simplify policy creation for the most common use cases, the default mode does **not** enforce `INSERT` and `UPDATE` policies while applying changes from SQLite Sync.
270-
271-
Instead, after the sync operation is complete, the `SELECT` policy is used to validate the final state of the row. If the user does not have permission to view the resulting row, the entire transaction is rolled back. This ensures that users cannot introduce changes that they are not allowed to see.
272-
273-
#### Manual Policy Mode (`rls_mode = 0`)
274-
275-
For more complex scenarios, such as implementing separate read/write permissions or restricting write access to specific columns, you can set `rls_mode` to `0`.
276-
277-
In this mode, your `INSERT` and `UPDATE` policies are enforced for every incremental change applied by SQLite Sync. Because of Sync's column-by-column operation, your policies must be written to permit intermediate states. This means the policies must allow `NEW` values for non-primary key columns to be temporarily set to their default values during the sync process.

0 commit comments

Comments
 (0)