Skip to content

Commit b2b3e20

Browse files
authored
docs: configuring enable_expand_roles setting (#1681)
1 parent 50fae2c commit b2b3e20

File tree

1 file changed

+70
-1
lines changed
  • docs/en/sql-reference/20-sql-functions/17-table-functions

1 file changed

+70
-1
lines changed

docs/en/sql-reference/20-sql-functions/17-table-functions/show-grants.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: SHOW_GRANTS
33
---
44
import FunctionDescription from '@site/src/components/FunctionDescription';
55

6-
<FunctionDescription description="Introduced or updated: v1.2.487"/>
6+
<FunctionDescription description="Introduced or updated: v1.2.704"/>
77

88
Lists privileges explicitly granted to a user, to a role, or on a specific object.
99

@@ -20,6 +20,75 @@ SHOW_GRANTS('table', '<table_name>', '<catalog_name>', '<db_name>')
2020
SHOW_GRANTS('database', '<db_name>', '<catalog_name>')
2121
```
2222

23+
## Configuring `enable_expand_roles` Setting
24+
25+
The `enable_expand_roles` setting controls whether the SHOW_GRANTS function expands role inheritance when displaying privileges.
26+
27+
- `enable_expand_roles=1` (default):
28+
29+
- SHOW_GRANTS recursively expands inherited privileges, meaning that if a role has been granted another role, it will display all the inherited privileges.
30+
- Users will also see all privileges granted through their assigned roles.
31+
32+
- `enable_expand_roles=0`:
33+
34+
- SHOW_GRANTS only displays privileges that are directly assigned to the specified role or user.
35+
- However, the result will still include GRANT ROLE statements to indicate role inheritance.
36+
37+
For example, role `a` has the `SELECT` privilege on `t1`, and role `b` has the `SELECT` privilege on `t2`:
38+
39+
```sql
40+
SELECT grants FROM show_grants('role', 'a') ORDER BY object_id;
41+
42+
┌──────────────────────────────────────────────────────┐
43+
│ grants │
44+
├──────────────────────────────────────────────────────┤
45+
GRANT SELECT ON 'default'.'default'.'t1' TO ROLE `a`
46+
└──────────────────────────────────────────────────────┘
47+
48+
SELECT grants FROM show_grants('role', 'b') ORDER BY object_id;
49+
50+
┌──────────────────────────────────────────────────────┐
51+
│ grants │
52+
├──────────────────────────────────────────────────────┤
53+
GRANT SELECT ON 'default'.'default'.'t2' TO ROLE `b`
54+
└──────────────────────────────────────────────────────┘
55+
```
56+
57+
If you grant role `b` to role `a` and check the grants on role `a` again, you can see than the `SELECT` privilege on `t2` is now included in role `a`:
58+
59+
```sql
60+
GRANT ROLE b TO ROLE a;
61+
```
62+
63+
```sql
64+
SELECT grants FROM show_grants('role', 'a') ORDER BY object_id;
65+
66+
┌──────────────────────────────────────────────────────┐
67+
│ grants │
68+
├──────────────────────────────────────────────────────┤
69+
GRANT SELECT ON 'default'.'default'.'t1' TO ROLE `a`
70+
GRANT SELECT ON 'default'.'default'.'t2' TO ROLE `a`
71+
└──────────────────────────────────────────────────────┘
72+
```
73+
74+
If you set `enable_expand_roles` to `0` and check the grants on role `a` again, the result will show the `GRANT ROLE` statement instead of listing the specific privileges inherited from role `b`:
75+
76+
```sql
77+
SET enable_expand_roles=0;
78+
```
79+
80+
```sql
81+
SELECT grants FROM show_grants('role', 'a') ORDER BY object_id;
82+
83+
┌──────────────────────────────────────────────────────┐
84+
│ grants │
85+
├──────────────────────────────────────────────────────┤
86+
GRANT SELECT ON 'default'.'default'.'t1' TO ROLE `a`
87+
GRANT ROLE b to ROLE `a`
88+
GRANT ROLE public to ROLE `a`
89+
└──────────────────────────────────────────────────────┘
90+
```
91+
2392
## Examples
2493

2594
This example illustrates how to list privileges granted to a user, a role, and on a specific object.

0 commit comments

Comments
 (0)