Skip to content

Commit dd09537

Browse files
committed
Add DSN option and expand user/role examples
Introduce a second DSN option in the MCP client guide (Option B) that shows how to build a stable lake:// DSN from a SQL user (steps and example format). Clarify Option A (Use with AI Tools) as the recommended short-lived DSN. Expand the warehouse and create-user docs with concrete role/user examples: full-access (global) role, single-database role, and read-only role, including SQL to create roles, users, and grant role assignments. Reorganize and rename examples in create-user.md for clarity and add a tip that privileges must be granted to roles (then assigned to users).
1 parent d0a3b94 commit dd09537

3 files changed

Lines changed: 85 additions & 45 deletions

File tree

tidb-cloud-lake/guides/mcp-client-integration.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ For example: "Create a scheduled task that copies parquet files from @my_stage t
2121

2222
### 1. Get a {{{ .lake }}} Connection
2323

24-
We recommend using **{{{ .lake }}}** for the best experience.
24+
We recommend using **{{{ .lake }}}** for the best experience. You can obtain the DSN in two ways.
25+
26+
#### Option A: Use **Use with AI Tools** (recommended)
27+
28+
Generates a short-lived DSN with session sandbox safety in one click. Best for getting AI tools connected quickly.
2529

2630
1. Log in to [{{{ .lake }}}](https://app.lake.tidbcloud.com).
2731
2. Click **Use with AI Tools**.
@@ -31,6 +35,18 @@ We recommend using **{{{ .lake }}}** for the best experience.
3135

3236
![Use with AI Tools](/media/tidb-cloud-lake/ai-tools.png)
3337

38+
#### Option B: Build the DSN with your own SQL user
39+
40+
Use this when you want a stable account and permission set (for example, CI pipelines, sharing with teammates, or pairing with a least-privilege policy).
41+
42+
1. Create a SQL user in {{{ .lake }}} and grant the required privileges. See [CREATE USER](/tidb-cloud-lake/sql/create-user.md#example-1-full-access-across-all-databases).
43+
2. Get your `tenant`, `region`, `database`, and `warehouse` values from **Overview → Connect**.
44+
3. Assemble the DSN using this format:
45+
46+
```text
47+
lake://<username>:<password>@<tenant>.gw.<region>.default.tidbcloud.com:443/<database>?warehouse=<warehouse_name>
48+
```
49+
3450
### 2. Configure Your MCP Client
3551
3652
Use `DATABEND_MCP_SAFE_MODE=true` by default. In safe mode, production data remains read-only for AI agents, while write operations are scoped to session sandbox objects.

tidb-cloud-lake/guides/warehouse.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,28 @@ Where:
223223
224224
### Creating SQL Users for Warehouse Access
225225
226-
Besides the default `cloudapp` user, you can create additional SQL users for better security and access control:
226+
Besides the default `cloudapp` user, you can create additional SQL users for better security and access control.
227+
228+
#### Example 1: Full access across all databases
229+
230+
Grant a user read/write access to all databases — useful for admin accounts or automation pipelines that need cross-database operations:
227231
228232
```sql
229-
-- Create a role with database access
233+
-- Create a role with global access
234+
CREATE ROLE full_access_role;
235+
GRANT ALL ON *.* TO ROLE full_access_role;
236+
237+
-- Create the user and assign the role
238+
CREATE USER admin_user IDENTIFIED BY 'SecurePass456!' WITH DEFAULT_ROLE = 'full_access_role';
239+
GRANT ROLE full_access_role TO admin_user;
240+
```
241+
242+
#### Example 2: Single-database access
243+
244+
Grant a user access to one specific database only:
245+
246+
```sql
247+
-- Create a role scoped to one database
230248
CREATE ROLE warehouse_user1_role;
231249
GRANT ALL ON my_database.* TO ROLE warehouse_user1_role;
232250

@@ -235,6 +253,24 @@ CREATE USER warehouse_user1 IDENTIFIED BY 'StrongPassword123' WITH DEFAULT_ROLE
235253
GRANT ROLE warehouse_user1_role TO warehouse_user1;
236254
```
237255

256+
#### Example 3: Read-only access across all databases
257+
258+
For scenarios where the user should only query data (dashboards, BI tools, AI agents in safe mode):
259+
260+
```sql
261+
-- Create a read-only role
262+
CREATE ROLE readonly_role;
263+
GRANT SELECT ON *.* TO ROLE readonly_role;
264+
265+
-- Create the user
266+
CREATE USER readonly_user IDENTIFIED BY 'ReadOnly789!' WITH DEFAULT_ROLE = 'readonly_role';
267+
GRANT ROLE readonly_role TO readonly_user;
268+
```
269+
270+
> **Tip:**
271+
>
272+
> In {{{ .lake }}}, privileges like `CREATE DATABASE` can only be granted to roles, not directly to users. Always create a role first, grant privileges to the role, then assign the role to the user.
273+
238274
For more details, see [CREATE USER](/tidb-cloud-lake/sql/create-user.md) and [GRANT](/tidb-cloud-lake/sql/grant.md) documentation.
239275

240276
### Connection Security

tidb-cloud-lake/sql/create-user.md

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,35 @@ CREATE [ OR REPLACE ] USER <name> IDENTIFIED [ WITH <auth_type> ] BY '<password>
3838

3939
## Examples
4040

41-
### Example 1: Create User and Grant Database Privileges
41+
### Example 1: Full Access Across All Databases
42+
43+
Create a user with full read/write access across all databases:
44+
45+
```sql
46+
-- Create a role with global access
47+
CREATE ROLE full_access_role;
48+
GRANT ALL ON *.* TO ROLE full_access_role;
49+
50+
-- Create the user and assign the role
51+
CREATE USER admin_user IDENTIFIED BY 'SecurePass456!' WITH DEFAULT_ROLE = 'full_access_role';
52+
GRANT ROLE full_access_role TO admin_user;
53+
```
54+
55+
### Example 2: Read-Only Access Across All Databases
56+
57+
Create a user that can only query data, suitable for dashboards or BI tools:
58+
59+
```sql
60+
-- Create a read-only role
61+
CREATE ROLE readonly_role;
62+
GRANT SELECT ON *.* TO ROLE readonly_role;
63+
64+
-- Create the user
65+
CREATE USER readonly_user IDENTIFIED BY 'ReadOnly789!' WITH DEFAULT_ROLE = 'readonly_role';
66+
GRANT ROLE readonly_role TO readonly_user;
67+
```
68+
69+
### Example 3: Single-Database Access
4270

4371
Create a role, grant database privileges, and assign the role to a user:
4472

@@ -63,33 +91,7 @@ SHOW GRANTS FOR ROLE data_analyst_role;
6391
+-----------------------------------------------------------------+
6492
```
6593

66-
### Example 2: Create User and Grant Role
67-
68-
Create a user and assign a role with specific privileges:
69-
70-
```sql
71-
-- Create a role with specific privileges
72-
CREATE ROLE analyst_role;
73-
GRANT SELECT ON *.* TO ROLE analyst_role;
74-
GRANT INSERT ON default.* TO ROLE analyst_role;
75-
76-
-- Create user and grant the role
77-
CREATE USER john_analyst IDENTIFIED BY 'secure_pass456';
78-
GRANT ROLE analyst_role TO john_analyst;
79-
```
80-
81-
Verify the role assignment:
82-
83-
```sql
84-
SHOW GRANTS FOR john_analyst;
85-
+------------------------------------------+
86-
| Grants |
87-
+------------------------------------------+
88-
| GRANT ROLE analyst_role TO 'john_analyst'@'%' |
89-
+------------------------------------------+
90-
```
91-
92-
### Example 3: Create Users with Different Authentication Types
94+
### Example 4: Create Users with Different Authentication Types
9395

9496
```sql
9597
-- Create user with default authentication
@@ -98,17 +100,3 @@ CREATE USER user1 IDENTIFIED BY 'abc123';
98100
-- Create user with SHA256 authentication
99101
CREATE USER user2 IDENTIFIED WITH sha256_password BY 'abc123';
100102
```
101-
102-
### Example 4: Create Users with Special Configurations
103-
104-
```sql
105-
-- Create user with password change requirement
106-
CREATE USER new_employee IDENTIFIED BY 'temp123' WITH MUST_CHANGE_PASSWORD = true;
107-
108-
-- Create user in disabled state
109-
CREATE USER temp_user IDENTIFIED BY 'abc123' WITH DISABLED = true;
110-
111-
-- Create user with default role (role must be granted separately)
112-
CREATE USER manager IDENTIFIED BY 'abc123' WITH DEFAULT_ROLE = 'admin';
113-
GRANT ROLE admin TO manager;
114-
```

0 commit comments

Comments
 (0)