Skip to content

Commit d18ff45

Browse files
committed
SHOW ROLES/PRIVILEGES ON
1 parent 1cc3192 commit d18ff45

File tree

5 files changed

+248
-5
lines changed

5 files changed

+248
-5
lines changed

pages/database-management/authentication-and-authorization.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,54 @@ In addition to the `AUTH` privilege, users must also have access to the default
2525

2626
Replication queries (such as `REGISTER REPLICA`, `SHOW REPLICAS`, `DROP REPLICA`, etc.) and multi-database queries (such as `SHOW DATABASES`, `CREATE DATABASE`, `DROP DATABASE`, etc.) also now target the "memgraph" database and require access to it.
2727

28+
To execute these queries, users must have:
29+
- The appropriate privileges (`REPLICATION`, `MULTI_DATABASE_EDIT`)
30+
- Access to the default "memgraph" database
31+
32+
## Multi-tenant query syntax changes
33+
34+
Recent changes to Memgraph have also modified the syntax for certain queries in multi-tenant environments. The `SHOW ROLE` and `SHOW PRIVILEGES` commands now require specifying the database context.
35+
36+
### SHOW ROLE syntax in multi-tenant environments
37+
38+
In multi-tenant environments, you must specify which database context to use when showing roles:
39+
40+
1. **Show roles for the user's main database:**
41+
```cypher
42+
SHOW ROLE FOR user_name ON MAIN;
43+
```
44+
45+
2. **Show roles for the current database:**
46+
```cypher
47+
SHOW ROLE FOR user_name ON CURRENT;
48+
```
49+
50+
3. **Show roles for a specific database:**
51+
```cypher
52+
SHOW ROLE FOR user_name ON DATABASE database_name;
53+
```
54+
55+
### SHOW PRIVILEGES syntax in multi-tenant environments
56+
57+
Similarly, the `SHOW PRIVILEGES` command requires database context specification:
58+
59+
1. **Show privileges for the user's main database:**
60+
```cypher
61+
SHOW PRIVILEGES FOR user_or_role ON MAIN;
62+
```
63+
64+
2. **Show privileges for the current database:**
65+
```cypher
66+
SHOW PRIVILEGES FOR user_or_role ON CURRENT;
67+
```
68+
69+
3. **Show privileges for a specific database:**
70+
```cypher
71+
SHOW PRIVILEGES FOR user_or_role ON DATABASE database_name;
72+
```
73+
74+
These commands return the aggregated roles and privileges for the user in the specified database context. The `ON MAIN` option shows information for the user's main database, `ON CURRENT` shows information for whatever database is currently active, and `ON DATABASE` shows information for the explicitly specified database.
75+
2876
### Multi-tenant recommendations
2977

3078
For multi-tenant environments, we recommend:

pages/database-management/authentication-and-authorization/multiple-roles.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,25 @@ To see which roles a user has for a specific database:
262262
SHOW ROLES FOR user_name ON database_name;
263263
```
264264

265+
In multi-tenant environments, you can also use these additional options:
266+
267+
1. **Show roles for the user's main database:**
268+
```cypher
269+
SHOW ROLES FOR user_name ON MAIN;
270+
```
271+
272+
2. **Show roles for the current database:**
273+
```cypher
274+
SHOW ROLES FOR user_name ON CURRENT;
275+
```
276+
277+
3. **Show roles for a specific database:**
278+
```cypher
279+
SHOW ROLES FOR user_name ON DATABASE database_name;
280+
```
281+
282+
These commands return the aggregated roles for the user in the specified database context.
283+
265284
### Viewing permissions for a specific database
266285

267286
To see what permissions a user has in a specific database:
@@ -270,6 +289,24 @@ To see what permissions a user has in a specific database:
270289
SHOW PRIVILEGES FOR user_name ON database_name;
271290
```
272291

292+
In multi-tenant environments, you can also use these additional options:
293+
294+
1. **Show privileges for the user's main database:**
295+
```cypher
296+
SHOW PRIVILEGES FOR user_name ON MAIN;
297+
```
298+
299+
2. **Show privileges for the current database:**
300+
```cypher
301+
SHOW PRIVILEGES FOR user_name ON CURRENT;
302+
```
303+
304+
3. **Show privileges for a specific database:**
305+
```cypher
306+
SHOW PRIVILEGES FOR user_name ON DATABASE database_name;
307+
```
308+
309+
These commands return the aggregated privileges for the user in the specified database context.
273310

274311
### SSO integration with multi-tenant roles
275312

@@ -351,3 +388,6 @@ SET ROLE multi_db_role FOR user1 ON db2;
351388
10. **Ensure multi-database privilege access**: Users who need to perform multi-database operations must have the appropriate privileges (`MULTI_DATABASE_USE`, `MULTI_DATABASE_EDIT`) and access to the "memgraph" database
352389
11. **Separate application data**: Store all application data in tenant-specific databases, not in the default "memgraph" database
353390
12. **Plan for administrative operations**: Design your role structure to ensure that users who need to manage users, roles, replication, or multi-database operations have appropriate access to the "memgraph" database
391+
13. **Use explicit database context**: Always specify the database context when using `SHOW ROLE` and `SHOW PRIVILEGES` commands in multi-tenant environments
392+
14. **Choose appropriate context**: Use `ON MAIN` for the user's main database, `ON CURRENT` for the currently active database, or `ON DATABASE` for a specific database
393+
15. **Verify permissions in context**: Always check roles and privileges in the specific database context where they will be used

pages/database-management/authentication-and-authorization/role-based-access-control.mdx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ To show what roles a user has, run the following query:
7979
SHOW ROLE FOR user_name;
8080
```
8181

82+
In multi-tenant environments, you must specify which database context to use when showing roles. There are three options:
83+
84+
1. **Show roles for the user's main database:**
85+
```cypher
86+
SHOW ROLE FOR user_name ON MAIN;
87+
```
88+
89+
2. **Show roles for the current database:**
90+
```cypher
91+
SHOW ROLE FOR user_name ON CURRENT;
92+
```
93+
94+
3. **Show roles for a specific database:**
95+
```cypher
96+
SHOW ROLE FOR user_name ON DATABASE database_name;
97+
```
98+
99+
These commands return the aggregated roles for the user in the specified database context. The `ON MAIN` option shows roles for the user's main database, `ON CURRENT` shows roles for whatever database is currently active, and `ON DATABASE` shows roles for the explicitly specified database.
100+
82101
TODO: multi-tenant environment show role for user_name
83102

84103
To list all defined user roles run:
@@ -295,6 +314,25 @@ To check privilege for a certain user or role, run the following query:
295314
SHOW PRIVILEGES FOR user_or_role;
296315
```
297316

317+
In multi-tenant environments, you must specify which database context to use when showing privileges. There are three options:
318+
319+
1. **Show privileges for the user's main database:**
320+
```cypher
321+
SHOW PRIVILEGES FOR user_or_role ON MAIN;
322+
```
323+
324+
2. **Show privileges for the current database:**
325+
```cypher
326+
SHOW PRIVILEGES FOR user_or_role ON CURRENT;
327+
```
328+
329+
3. **Show privileges for a specific database:**
330+
```cypher
331+
SHOW PRIVILEGES FOR user_or_role ON DATABASE database_name;
332+
```
333+
334+
These commands return the aggregated privileges (including label-based permissions) for the user or role in the specified database context.
335+
298336
## Fine-grained access control
299337

300338
Sometimes, authorizing the database by granting and denying clause privileges is
@@ -398,6 +436,25 @@ SHOW PRIVILEGES FOR user_or_role;
398436

399437
and all the values of clause privileges, as well as label-based permissions will be displayed.
400438

439+
In multi-tenant environments, you must specify which database context to use when showing privileges. There are three options:
440+
441+
1. **Show privileges for the user's main database:**
442+
```cypher
443+
SHOW PRIVILEGES FOR user_or_role ON MAIN;
444+
```
445+
446+
2. **Show privileges for the current database:**
447+
```cypher
448+
SHOW PRIVILEGES FOR user_or_role ON CURRENT;
449+
```
450+
451+
3. **Show privileges for a specific database:**
452+
```cypher
453+
SHOW PRIVILEGES FOR user_or_role ON DATABASE database_name;
454+
```
455+
456+
These commands return the aggregated privileges (including label-based permissions) for the user or role in the specified database context.
457+
401458
### Templates for granting privileges
402459

403460
To grant all privileges to a superuser (admin):

pages/database-management/multi-tenancy.md

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,55 @@ Access to all databases can be granted or revoked using wildcards:
142142

143143
### Multi-database queries and the memgraph database
144144

145-
Recent changes to Memgraph have modified how multi-database queries are executed. Multi-database queries (such as `SHOW DATABASES`, `CREATE DATABASE`, `DROP DATABASE`, etc.) now target the default "memgraph" database and require access to it.
145+
Recent changes to Memgraph have modified how multi-database queries are executed. Multi-database queries (such as `SHOW DATABASES`, `CREATE DATABASE`, `DROP DATABASE`, etc.) now target the "memgraph" database and require access to it.
146146

147-
#### Requirements for multi-database queries
147+
To execute these queries, users must have:
148+
- The appropriate privileges (`MULTI_DATABASE_USE`, `MULTI_DATABASE_EDIT`)
149+
- Access to the default "memgraph" database
148150

149-
To execute multi-database queries, users must have:
150-
1. The appropriate multi-database privileges (`MULTI_DATABASE_USE`, `MULTI_DATABASE_EDIT`)
151-
2. Access to the default "memgraph" database
151+
### Multi-tenant query syntax changes
152+
153+
Recent changes to Memgraph have also modified the syntax for certain queries in multi-tenant environments. The `SHOW ROLE` and `SHOW PRIVILEGES` commands now require specifying the database context.
154+
155+
#### SHOW ROLE syntax in multi-tenant environments
156+
157+
In multi-tenant environments, you must specify which database context to use when showing roles:
158+
159+
1. **Show roles for the user's main database:**
160+
```cypher
161+
SHOW ROLE FOR user_name ON MAIN;
162+
```
163+
164+
2. **Show roles for the current database:**
165+
```cypher
166+
SHOW ROLE FOR user_name ON CURRENT;
167+
```
168+
169+
3. **Show roles for a specific database:**
170+
```cypher
171+
SHOW ROLE FOR user_name ON DATABASE database_name;
172+
```
173+
174+
#### SHOW PRIVILEGES syntax in multi-tenant environments
175+
176+
Similarly, the `SHOW PRIVILEGES` command requires database context specification:
177+
178+
1. **Show privileges for the user's main database:**
179+
```cypher
180+
SHOW PRIVILEGES FOR user_or_role ON MAIN;
181+
```
182+
183+
2. **Show privileges for the current database:**
184+
```cypher
185+
SHOW PRIVILEGES FOR user_or_role ON CURRENT;
186+
```
187+
188+
3. **Show privileges for a specific database:**
189+
```cypher
190+
SHOW PRIVILEGES FOR user_or_role ON DATABASE database_name;
191+
```
192+
193+
These commands return the aggregated roles and privileges for the user in the specified database context. The `ON MAIN` option shows information for the user's main database, `ON CURRENT` shows information for whatever database is currently active, and `ON DATABASE` shows information for the explicitly specified database.
152194

153195
#### Impact on multi-tenant environments
154196

pages/help-center/errors/auth.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,62 @@ GRANT DATABASE memgraph TO role_name;
7373

7474
In multi-tenant environments, we recommend treating the "memgraph" database as an administrative/system database and restricting access to privileged users only. See the [multi-tenancy documentation](/database-management/multi-tenancy#default-database-best-practices) for recommended setup patterns.
7575

76+
## Database context must be specified for SHOW ROLE in multi-tenant environment
77+
78+
This error occurs when attempting to use `SHOW ROLE` or `SHOW ROLES` in a multi-tenant environment without specifying the database context.
79+
80+
### Solution
81+
82+
In multi-tenant environments, you must specify which database context to use:
83+
84+
```cypher
85+
-- Show roles for the user's main database
86+
SHOW ROLE FOR user_name ON MAIN;
87+
88+
-- Show roles for the current database
89+
SHOW ROLE FOR user_name ON CURRENT;
90+
91+
-- Show roles for a specific database
92+
SHOW ROLE FOR user_name ON DATABASE database_name;
93+
```
94+
95+
### When this occurs
96+
97+
This error typically occurs when:
98+
- Running `SHOW ROLE` or `SHOW ROLES` in a multi-tenant environment
99+
- The system detects multiple databases and requires explicit context specification
100+
- The user is connected to a multi-tenant Memgraph instance
101+
102+
## Database context must be specified for SHOW PRIVILEGES in multi-tenant environment [#error-9]
103+
104+
This error occurs when attempting to use `SHOW PRIVILEGES` in a multi-tenant environment without specifying the database context.
105+
106+
### Solution
107+
108+
In multi-tenant environments, you must specify which database context to use:
109+
110+
```cypher
111+
-- Show privileges for the user's main database
112+
SHOW PRIVILEGES FOR user_or_role ON MAIN;
113+
114+
-- Show privileges for the current database
115+
SHOW PRIVILEGES FOR user_or_role ON CURRENT;
116+
117+
-- Show privileges for a specific database
118+
SHOW PRIVILEGES FOR user_or_role ON DATABASE database_name;
119+
```
120+
121+
### When this occurs
122+
123+
This error typically occurs when:
124+
- Running `SHOW PRIVILEGES` in a multi-tenant environment
125+
- The system detects multiple databases and requires explicit context specification
126+
- The user is connected to a multi-tenant Memgraph instance
127+
128+
### Best practice
129+
130+
Always specify the database context when working in multi-tenant environments to ensure you're viewing the correct roles and privileges for the intended database.
131+
76132
## User doesn't have REPLICATION privilege
77133

78134
This error occurs when a user attempts to execute replication queries (such as `REGISTER REPLICA`, `SHOW REPLICAS`, `DROP REPLICA`, etc.) without the required `REPLICATION` privilege.

0 commit comments

Comments
 (0)