Skip to content

Commit 2cb3af9

Browse files
committed
Add docs for Row-level security (RLS)
Fixes DOC-10439, DOC-12948 Summary of changes: - Add 'Row-level security' overview page - Add or update SQL statement docs for: - `CREATE POLICY` - `ALTER POLICY` - `DROP POLICY` - `SHOW POLICIES` - `ALTER TABLE {ENABLE,DISABLE} ROW LEVEL SECURITY` - `ALTER TABLE {FORCE,UNFORCE} ROW LEVEL SECURITY` - `CREATE ROLE ... WITH BYPASSRLS` - `ALTER ROLE ... WITH BYPASSRLS`
1 parent db793ad commit 2cb3af9

File tree

12 files changed

+801
-40
lines changed

12 files changed

+801
-40
lines changed

src/current/_includes/v25.2/sidebar-data/reference.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@
382382
"/${VERSION}/column-level-encryption.html"
383383
]
384384
},
385+
{
386+
"title": "Row-level Security",
387+
"urls": [
388+
"/${VERSION}/row-level-security.html"
389+
]
390+
},
385391
{
386392
"title": "PKI and TLS",
387393
"urls": [

src/current/_includes/v25.2/sidebar-data/sql.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
"/${VERSION}/alter-partition.html"
6565
]
6666
},
67+
{
68+
"title": "<code>ALTER POLICY</code>",
69+
"urls": [
70+
"/${VERSION}/alter-policy.html"
71+
]
72+
},
6773
{
6874
"title": "<code>ALTER PROCEDURE</code>",
6975
"urls": [
@@ -220,6 +226,12 @@
220226
"/${VERSION}/create-logical-replication-stream.html"
221227
]
222228
},
229+
{
230+
"title": "<code>CREATE POLICY</code>",
231+
"urls": [
232+
"/${VERSION}/create-policy.html"
233+
]
234+
},
223235
{
224236
"title": "<code>CREATE PROCEDURE</code>",
225237
"urls": [
@@ -340,6 +352,12 @@
340352
"/${VERSION}/drop-owned-by.html"
341353
]
342354
},
355+
{
356+
"title": "<code>DROP POLICY</code>",
357+
"urls": [
358+
"/${VERSION}/drop-policy.html"
359+
]
360+
},
343361
{
344362
"title": "<code>DROP TRIGGER</code>",
345363
"urls": [
@@ -694,6 +712,12 @@
694712
"/${VERSION}/show-partitions.html"
695713
]
696714
},
715+
{
716+
"title": "<code>SHOW POLICIES</code>",
717+
"urls": [
718+
"/${VERSION}/show-policies.html"
719+
]
720+
},
697721
{
698722
"title": "<code>SHOW RANGES</code>",
699723
"urls": [

src/current/_includes/v25.2/sql/privileges.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Privilege | Levels | Description
22
----------|--------|------------
33
`ALL` | System, Database, Schema, Table, Sequence, Type | For the object to which `ALL` is applied, grants all privileges at the system, database, schema, table, sequence, or type level.
44
`BACKUP` | System, Database, Table | Grants the ability to create [backups]({% link {{ page.version.version }}/backup-and-restore-overview.md %}) at the system, database, or table level.
5+
`BYPASSRLS` | [XXX](XXX): XXX (NEW IN v25.2) Grants the ability to bypass [row-level security (RLS)]({% link {{ page.version.version }}/row-level-security.md %}) policies on a table, granting unrestricted read and write access to all rows.
56
`CANCELQUERY` | System | Grants the ability to cancel queries.
67
`CHANGEFEED` | Table | Grants the ability to create [changefeeds]({% link {{ page.version.version }}/change-data-capture-overview.md %}) on a table.
78
<a id="connect"></a>`CONNECT` | Database | Grants the ability to view a database's metadata, which consists of objects in a database's `information_schema` and `pg_catalog` system catalogs. This allows the role to view the database's table, schemas, user-defined types, and list the database when running `SHOW DATABASES`. The `CONNECT` privilege is also required to run backups of the database.

src/current/_includes/v25.2/sql/role-options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Role option | Description
22
------------|-------------
3+
`BYPASSRLS`/`NOBYPASSRLS` | **New in v25.2** [XXX](XXX):Grants the ability to bypass [row-level security (RLS)]({% link {{ page.version.version }}/row-level-security.md %}) policies on a table, granting unrestricted read and write access to all rows.
34
`CANCELQUERY`/`NOCANCELQUERY` | **Deprecated in v22.2: Use the `CANCELQUERY` [system privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges).** Allow or disallow a role to cancel [queries]({% link {{ page.version.version }}/cancel-query.md %}) and [sessions]({% link {{ page.version.version }}/cancel-session.md %}) of other roles. Without this role option, roles can only cancel their own queries and sessions. Even with the `CANCELQUERY` role option, non-`admin` roles cannot cancel `admin` queries or sessions. This option should usually be combined with `VIEWACTIVITY` so that the role can view other roles' query and session information. <br><br>By default, the role option is set to `NOCANCELQUERY` for all non-`admin` roles.
45
`CONTROLCHANGEFEED`/`NOCONTROLCHANGEFEED` | **Deprecated in v23.1: Use the `CHANGEFEED` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges).** Allow or disallow a role to run [`CREATE CHANGEFEED`]({% link {{ page.version.version }}/create-changefeed.md %}) on tables they have `SELECT` privileges on. <br><br>By default, the role option is set to `NOCONTROLCHANGEFEED` for all non-`admin` roles.
56
`CONTROLJOB`/`NOCONTROLJOB` | Allow or disallow a role to [pause]({% link {{ page.version.version }}/pause-job.md %}), [resume]({% link {{ page.version.version }}/resume-job.md %}), and [cancel]({% link {{ page.version.version }}/cancel-job.md %}) jobs. Non-`admin` roles cannot control jobs created by `admin` roles. <br><br>By default, the role option is set to `NOCONTROLJOB` for all non-`admin` roles.

src/current/v25.2/alter-policy.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: ALTER POLICY
3+
summary: The ALTER POLICY statement ... XXX
4+
toc: true
5+
docs_area: reference.sql
6+
---
7+
8+
The `ALTER POLICY` statement changes the [row-level security (RLS)]({% link {{ page.version.version }}/enum.md %}) policies for ... [XXX](XXX): XXX
9+
10+
## Syntax
11+
12+
[xxx](): this diagram not getting built/added to https://github.com/cockroachdb/generated-diagrams/tree/master/grammar_svg for some reason
13+
14+
<div>
15+
{% remote_include https://github.com/raw/cockroachdb/generated-diagrams/{{ page.release_info.crdb_branch_name }}/grammar_svg/alter_policy_stmt.html %}
16+
</div>
17+
18+
## Parameters
19+
20+
[XXX](XXX): XXX
21+
22+
Parameter | Description
23+
----------|------------
24+
[XXX](XXX): XXX | [XXX](XXX): XXX
25+
26+
## Examples
27+
28+
[XXX](XXX): XXX
29+
30+
## See also
31+
32+
- [Row-level security (RLS) overview]({% link {{ page.version.version }}/row-level-security.md %})
33+
- [`CREATE POLICY`]({% link {{ page.version.version }}/create-policy.md %})
34+
- [`DROP POLICY`]({% link {{ page.version.version }}/drop-policy.md %})
35+
- [`SHOW POLICIES`]({% link {{ page.version.version }}/show-policies.md %})
36+
- [`ALTER TABLE {ENABLE, DISABLE} ROW LEVEL SECURITY`]({% link {{ page.version.version }}/alter-table.md %}#enable-disable-row-level-security)
37+
- [`ALTER ROLE ... WITH BYPASSRLS`]({% link {{ page.version.version }}/alter-role.md %}#allow-a-role-to-bypass-row-level-security-rls)
38+
- [`CREATE ROLE ... WITH BYPASSRLS`]({% link {{ page.version.version }}/create-role.md %}#create-a-role-that-can-bypass-row-level-security-rls)

src/current/v25.2/alter-role.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ The following statements are run by the `root` user that is a member of the `adm
5050
The following example allows a role to log in to the database with a [password]({% link {{ page.version.version }}/authentication.md %}#client-authentication):
5151

5252
~~~ sql
53-
root@:26257/defaultdb> ALTER ROLE carl WITH LOGIN PASSWORD 'An0ther$tr0nGpassW0rD' VALID UNTIL '2021-10-10';
53+
CREATE ROLE carl;
54+
~~~
55+
56+
~~~ sql
57+
-- sqlchecker: ignore
58+
ALTER ROLE carl WITH LOGIN PASSWORD 'An0ther$tr0nGpassW0rD' VALID UNTIL '2021-10-10';
5459
~~~
5560

5661
### Prevent a role from using password authentication
@@ -59,73 +64,77 @@ The following statement prevents the user from using password authentication and
5964

6065
{% include_cached copy-clipboard.html %}
6166
~~~ sql
62-
root@:26257/defaultdb> ALTER ROLE carl WITH PASSWORD NULL;
67+
ALTER ROLE carl WITH PASSWORD NULL;
6368
~~~
6469

6570
### Allow a role to create other roles and manage authentication methods for the new roles
6671

6772
The following example allows the role to [create other roles]({% link {{ page.version.version }}/create-role.md %}) and [manage authentication methods]({% link {{ page.version.version }}/authentication.md %}#client-authentication) for them:
6873

6974
~~~ sql
70-
root@:26257/defaultdb> ALTER ROLE carl WITH CREATEROLE CREATELOGIN;
75+
ALTER ROLE carl WITH CREATEROLE CREATELOGIN;
7176
~~~
7277

7378
### Allow a role to create and rename databases
7479

7580
The following example allows the role to [create]({% link {{ page.version.version }}/create-database.md %}) or [rename]({% link {{ page.version.version }}/alter-database.md %}#rename-to) databases:
7681

7782
~~~ sql
78-
root@:26257/defaultdb> ALTER ROLE carl WITH CREATEDB;
83+
ALTER ROLE carl WITH CREATEDB;
7984
~~~
8085

8186
### Allow a role to pause, resume, and cancel non-admin jobs
8287

8388
The following example allows the role to [pause]({% link {{ page.version.version }}/pause-job.md %}), [resume]({% link {{ page.version.version }}/resume-job.md %}), and [cancel]({% link {{ page.version.version }}/cancel-job.md %}) jobs:
8489

8590
~~~ sql
86-
root@:26257/defaultdb> ALTER ROLE carl WITH CONTROLJOB;
91+
ALTER ROLE carl WITH CONTROLJOB;
8792
~~~
8893

8994
### Allow a role to see and cancel non-admin queries and sessions
9095

9196
The following example allows the role to cancel [queries]({% link {{ page.version.version }}/cancel-query.md %}) and [sessions]({% link {{ page.version.version }}/cancel-session.md %}) for other non-`admin` roles:
9297

9398
~~~ sql
94-
root@:26257/defaultdb> ALTER ROLE carl WITH CANCELQUERY VIEWACTIVITY;
99+
ALTER ROLE carl WITH CANCELQUERY VIEWACTIVITY;
95100
~~~
96101

97102
### Allow a role to control changefeeds
98103

99104
The following example allows the role to run [`CREATE CHANGEFEED`]({% link {{ page.version.version }}/create-changefeed.md %}):
100105

101106
~~~ sql
102-
root@:26257/defaultdb> ALTER ROLE carl WITH CONTROLCHANGEFEED;
107+
ALTER ROLE carl WITH CONTROLCHANGEFEED;
103108
~~~
104109

105110
### Allow a role to modify cluster settings
106111

107112
The following example allows the role to modify [cluster settings]({% link {{ page.version.version }}/cluster-settings.md %}):
108113

109114
~~~ sql
110-
root@:26257/defaultdb> ALTER ROLE carl WITH MODIFYCLUSTERSETTING;
115+
ALTER ROLE carl WITH MODIFYCLUSTERSETTING;
111116
~~~
112117

118+
### Allow a role to bypass row-level security (RLS)
119+
120+
[XXX](XXX): XXX
121+
113122
### Set default session variable values for a role
114123

115124
In the following example, the `root` user creates a role named `max`, and sets the default value of the `timezone` [session variable]({% link {{ page.version.version }}/set-vars.md %}#supported-variables) for the `max` role.
116125

117126
~~~ sql
118-
root@:26257/defaultdb> CREATE ROLE max WITH LOGIN;
127+
CREATE ROLE max WITH LOGIN;
119128
~~~
120129

121130
~~~ sql
122-
root@:26257/defaultdb> ALTER ROLE max SET timezone = 'America/New_York';
131+
ALTER ROLE max SET timezone = 'America/New_York';
123132
~~~
124133

125134
This statement does not affect the default `timezone` value for any role other than `max`:
126135

127136
~~~ sql
128-
root@:26257/defaultdb> SHOW timezone;
137+
SHOW timezone;
129138
~~~
130139

131140
~~~
@@ -138,7 +147,7 @@ root@:26257/defaultdb> SHOW timezone;
138147
To see the default `timezone` value for the `max` role, run the `SHOW` statement as a member of the `max` role:
139148

140149
~~~ sql
141-
max@:26257/defaultdb> SHOW timezone;
150+
SHOW timezone;
142151
~~~
143152

144153
~~~
@@ -155,21 +164,21 @@ max@:26257/defaultdb> SHOW timezone;
155164
In the following example, the `root` user creates a role named `max` and a database named `movr`, and sets the default value of the `statement_timeout` [session variable]({% link {{ page.version.version }}/set-vars.md %}#supported-variables) for the `max` role in the `movr` database.
156165

157166
~~~ sql
158-
root@:26257/defaultdb> CREATE DATABASE movr;
167+
CREATE DATABASE IF NOT EXISTS movr;
159168
~~~
160169

161170
~~~ sql
162-
root@:26257/defaultdb> CREATE ROLE max WITH LOGIN;
171+
CREATE ROLE IF NOT EXISTS max WITH LOGIN;
163172
~~~
164173

165174
~~~ sql
166-
root@:26257/defaultdb> ALTER ROLE max IN DATABASE movr SET statement_timeout = '10s';
175+
ALTER ROLE max IN DATABASE movr SET statement_timeout = '10s';
167176
~~~
168177

169178
This statement does not affect the default `statement_timeout` value for any role other than `max`, or in any database other than `movr`.
170179

171180
~~~ sql
172-
root@:26257/defaultdb> SHOW statement_timeout;
181+
SHOW statement_timeout;
173182
~~~
174183

175184
~~~
@@ -186,7 +195,7 @@ cockroach sql --url 'postgresql://max@localhost:26257/movr?sslmode=disable'
186195
~~~
187196

188197
~~~ sql
189-
max@:26257/movr> SHOW statement_timeout;
198+
SHOW statement_timeout;
190199
~~~
191200

192201
~~~
@@ -203,11 +212,11 @@ max@:26257/movr> SHOW statement_timeout;
203212
In the following example, the `root` user creates a database named `movr`, and sets the default value of the `timezone` [session variable]({% link {{ page.version.version }}/set-vars.md %}#supported-variables) for all roles in that database.
204213

205214
~~~ sql
206-
root@:26257/defaultdb> CREATE DATABASE movr;
215+
CREATE DATABASE IF NOT EXISTS movr;
207216
~~~
208217

209218
~~~ sql
210-
root@:26257/defaultdb> ALTER ROLE ALL IN DATABASE movr SET timezone = 'America/New_York';
219+
ALTER ROLE ALL IN DATABASE movr SET timezone = 'America/New_York';
211220
~~~
212221

213222
{{site.data.alerts.callout_info}}
@@ -217,7 +226,7 @@ This statement is identical to [`ALTER DATABASE movr SET timezone = 'America/New
217226
This statement does not affect the default `timezone` value for any database other than `movr`:
218227

219228
~~~ sql
220-
root@:26257/defaultdb> SHOW timezone;
229+
SHOW timezone;
221230
~~~
222231

223232
~~~
@@ -230,7 +239,7 @@ root@:26257/defaultdb> SHOW timezone;
230239
To see the default `timezone` value for the `max` role, run the `SHOW` statement as a member of the `max` role:
231240

232241
~~~ sql
233-
root@:26257/movr> SHOW timezone;
242+
SHOW timezone;
234243
~~~
235244

236245
~~~
@@ -265,7 +274,7 @@ ALTER ROLE
265274

266275
{% include_cached copy-clipboard.html %}
267276
~~~ sql
268-
ALTER ROLE maxroach WITH SUBJECT 'CN=myName2,OU=myOrgUnit2,O=myOrg2,L=myLocality2,ST=myState2,C=myCountry2' LOGIN;
277+
ALTER ROLE max WITH SUBJECT 'CN=myName2,OU=myOrgUnit2,O=myOrg2,L=myLocality2,ST=myState2,C=myCountry2' LOGIN;
269278
~~~
270279

271280
{% include {{page.version.version}}/misc/cert-auth-using-x509-subject.md %}
@@ -280,3 +289,12 @@ ALTER ROLE maxroach WITH SUBJECT 'CN=myName2,OU=myOrgUnit2,O=myOrg2,L=myLocality
280289
- [SQL Statements]({% link {{ page.version.version }}/sql-statements.md %})
281290
- [Authorization Best Practices]({% link {{ page.version.version }}/security-reference/authorization.md %}#authorization-best-practices)
282291
- [`SHOW DEFAULT SESSION VARIABLES FOR ROLE`]({% link {{ page.version.version }}/show-default-session-variables-for-role.md %})
292+
293+
<!-- sqlchecker test block -->
294+
295+
{% include_cached copy-clipboard.html %}
296+
~~~ sql
297+
DROP ROLE carl;
298+
DROP ROLE max;
299+
DROP DATABASE movr;
300+
~~~

src/current/v25.2/alter-table.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Subcommand | Description | Can combine with other subcommands?
5959
[`RENAME CONSTRAINT`](#rename-constraint) | Change constraints columns. | Yes
6060
[`RENAME TO`](#rename-to) | Change the names of tables. | No
6161
[`RESET {storage parameter}`](#reset-storage-parameter) | Reset a storage parameter on a table to its default value. | Yes
62+
[`{ENABLE, DISABLE} ROW LEVEL SECURITY`](#enable-disable-row-level-security) | [XXX](XXX): XXX | No
63+
[`{FORCE, UNFORCE} ROW LEVEL SECURITY`](#force-unforce-row-level-security) | [XXX](XXX): XXX | No
6264
[`SET {storage parameter}`](#set-storage-parameter) | Set a storage parameter on a table. | Yes
6365
[`SET LOCALITY`](#set-locality) | Set the table locality for a table in a [multi-region database]({% link {{ page.version.version }}/multiregion-overview.md %}). | No
6466
[`SET SCHEMA`](#set-schema) | Change the [schema]({% link {{ page.version.version }}/sql-name-resolution.md %}) of a table. | No
@@ -468,6 +470,34 @@ Parameter | Description |
468470

469471
For usage, see [Synopsis](#synopsis).
470472

473+
### `{ENABLE, DISABLE} ROW LEVEL SECURITY`
474+
475+
[XXX](XXX): XXX
476+
477+
#### Required privileges
478+
479+
[XXX](XXX): GET THIS REVIEWED
480+
481+
The user must be a member of the [`admin`]({% link {{ page.version.version }}/security-reference/authorization.md %}#roles) or [owner]({% link {{ page.version.version }}/security-reference/authorization.md %}#object-ownership) roles, or have the [`BYPASSRLS` privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges) on the table.
482+
483+
#### Parameters
484+
485+
[XXX](XXX): XXX
486+
487+
### `{FORCE, UNFORCE} ROW LEVEL SECURITY`
488+
489+
[XXX](XXX): XXX
490+
491+
#### Required privileges
492+
493+
[XXX](XXX): GET THIS REVIEWED
494+
495+
The user must be a member of the [`admin`]({% link {{ page.version.version }}/security-reference/authorization.md %}#roles) or [owner]({% link {{ page.version.version }}/security-reference/authorization.md %}#object-ownership) roles, or have the [`BYPASSRLS` privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges) on the table.
496+
497+
#### Parameters
498+
499+
[XXX](XXX): XXX
500+
471501
### `SET {storage parameter}`
472502

473503
`ALTER TABLE ... SET {storage parameter}` sets a storage parameter on an existing table.

src/current/v25.2/create-policy.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: CREATE POLICY
3+
summary: The CREATE POLICY statement ... XXX
4+
toc: true
5+
docs_area: reference.sql
6+
---
7+
8+
The `CREATE POLICY` statement changes the [row-level security (RLS)]({% link {{ page.version.version }}/enum.md %}) policies for ... [XXX](XXX): XXX
9+
10+
## Syntax
11+
12+
[xxx](): this diagram not getting built/added to https://github.com/cockroachdb/generated-diagrams/tree/master/grammar_svg for some reason
13+
14+
<div>
15+
{% remote_include https://github.com/raw/cockroachdb/generated-diagrams/{{ page.release_info.crdb_branch_name }}/grammar_svg/create_policy_stmt.html %}
16+
</div>
17+
18+
## Parameters
19+
20+
Parameter | Description
21+
----------|------------
22+
[XXX](XXX): XXX | [XXX](XXX): XXX
23+
24+
## Examples
25+
26+
[XXX](XXX): XXX
27+
28+
## See also
29+
30+
- [Row-level security (RLS) overview]({% link {{ page.version.version }}/row-level-security.md %})
31+
- [`ALTER POLICY`]({% link {{ page.version.version }}/alter-policy.md %})
32+
- [`DROP POLICY`]({% link {{ page.version.version }}/drop-policy.md %})
33+
- [`SHOW POLICIES`]({% link {{ page.version.version }}/show-policies.md %})
34+
- [`ALTER TABLE {ENABLE, DISABLE} ROW LEVEL SECURITY`]({% link {{ page.version.version }}/alter-table.md %}#enable-disable-row-level-security)
35+
- [`ALTER ROLE ... WITH BYPASSRLS`]({% link {{ page.version.version }}/alter-role.md %}#allow-a-role-to-bypass-row-level-security-rls)
36+
- [`CREATE ROLE ... WITH BYPASSRLS`]({% link {{ page.version.version }}/create-role.md %}#create-a-role-that-can-bypass-row-level-security-rls)

0 commit comments

Comments
 (0)