@@ -66,6 +66,17 @@ in sync when changing the above synopsis!
66
66
Note that roles are defined at the database cluster
67
67
level, and so are valid in all databases in the cluster.
68
68
</para>
69
+
70
+ <para>
71
+ During role creation it is possible to immediately assign the newly created
72
+ role to be a member of an existing role, and also assign existing roles
73
+ to be members of the newly created role. The rules for which initial
74
+ role membership options are enabled described below in the
75
+ <literal>IN ROLE</literal>, <literal>ROLE</literal>, and
76
+ <literal>ADMIN</literal> clauses. The <xref linkend="sql-grant"/>
77
+ command has fine-grained option control during membership creation,
78
+ and the ability to modify these options after the new role is created.
79
+ </para>
69
80
</refsect1>
70
81
71
82
<refsect1>
@@ -133,24 +144,21 @@ in sync when changing the above synopsis!
133
144
<term><literal>NOINHERIT</literal></term>
134
145
<listitem>
135
146
<para>
136
- When the <literal>GRANT</literal> statement is used to confer
137
- membership in one role to another role, the <literal>GRANT</literal>
138
- may use the <literal>WITH INHERIT</literal> clause to specify whether
139
- the privileges of the granted role should be <quote>inherited</quote>
140
- by the new member. If the <literal>GRANT</literal> statement does not
141
- specify either inheritance behavior, the new <literal>GRANT</literal>
142
- will be created <literal>WITH INHERIT TRUE</literal> if the member
143
- role is set to <literal>INHERIT</literal> and to
144
- <literal>WITH INHERIT FALSE</literal> if it is set to
145
- <literal>NOINHERIT</literal>.
147
+ This affects the membership inheritance status when this
148
+ role is added as a member of another role, both in this and
149
+ future commands. Specifically, it controls the inheritance
150
+ status of memberships added with this command using the
151
+ <literal>IN ROLE</literal> clause, and in later commands using
152
+ the <literal>ROLE</literal> clause. It is also used as the
153
+ default inheritance status when adding this role as a member
154
+ using the <literal>GRANT</literal> command. If not specified,
155
+ <literal>INHERIT</literal> is the default.
146
156
</para>
147
157
148
158
<para>
149
159
In <productname>PostgreSQL</productname> versions before 16,
150
- the <literal>GRANT</literal> statement did not support
151
- <literal>WITH INHERIT</literal>. Therefore, changing this role-level
152
- property would also change the behavior of already-existing grants.
153
- This is no longer the case.
160
+ inheritance was a role-level attribute that controlled all runtime
161
+ membership checks for that role.
154
162
</para>
155
163
</listitem>
156
164
</varlistentry>
@@ -285,9 +293,10 @@ in sync when changing the above synopsis!
285
293
<para>
286
294
The <literal>IN ROLE</literal> clause causes the new role to
287
295
be automatically added as a member of the specified existing
288
- roles. (Note that there is no option to add the new role as an
289
- administrator; use a separate <command>GRANT</command> command
290
- to do that.)
296
+ roles. The new membership will have the <literal>SET</literal>
297
+ option enabled and the <literal>ADMIN</literal> option disabled.
298
+ The <literal>INHERIT</literal> option will be enabled unless the
299
+ <literal>NOINHERIT</literal> option is specified.
291
300
</para>
292
301
</listitem>
293
302
</varlistentry>
@@ -297,8 +306,12 @@ in sync when changing the above synopsis!
297
306
<listitem>
298
307
<para>
299
308
The <literal>ROLE</literal> clause causes one or more specified
300
- existing roles to be automatically added as members of the new
301
- role. This in effect makes the new role a <quote>group</quote>.
309
+ existing roles to be automatically added as members, with the
310
+ <literal>SET</literal> option enabled. This in effect makes the
311
+ new role a <quote>group</quote>. Roles named in this clause
312
+ with role-level the <literal>INHERIT</literal> attribute will have
313
+ the <literal>INHERIT</literal> option enabled in the new membership.
314
+ New memberships will have the <literal>ADMIN</literal> option disabled.
302
315
</para>
303
316
</listitem>
304
317
</varlistentry>
@@ -307,10 +320,10 @@ in sync when changing the above synopsis!
307
320
<term><literal>ADMIN</literal> <replaceable class="parameter">role_name</replaceable></term>
308
321
<listitem>
309
322
<para>
310
- The <literal>ADMIN</literal> clause is like <literal>ROLE</literal>,
311
- but the named roles are added to the new role <literal>WITH ADMIN
312
- OPTION</literal>, giving them the right to grant membership in this role
313
- to others.
323
+ The <literal>ADMIN</literal> clause has the same effect as
324
+ <literal>ROLE</literal>, but the named roles are added as members
325
+ of the new role with <literal>ADMIN</literal> enabled, giving
326
+ them the right to grant membership in the new role to others.
314
327
</para>
315
328
</listitem>
316
329
</varlistentry>
@@ -353,15 +366,19 @@ in sync when changing the above synopsis!
353
366
</para>
354
367
355
368
<para>
356
- The <literal>INHERIT</literal> attribute governs inheritance of grantable
357
- privileges (that is, access privileges for database objects and role
358
- memberships). It does not apply to the special role attributes set by
359
- <command>CREATE ROLE</command> and <command>ALTER ROLE</command>. For example, being
360
- a member of a role with <literal>CREATEDB</literal> privilege does not immediately
361
- grant the ability to create databases, even if <literal>INHERIT</literal> is set;
362
- it would be necessary to become that role via
363
- <link linkend="sql-set-role"><command>SET ROLE</command></link> before
364
- creating a database.
369
+ The role attributes defined here are non-inheritable, i.e., being a
370
+ member of a role with, e.g., <literal>CREATEDB</literal> will not
371
+ allow the member to create new databases even if the membership grant
372
+ has the <literal>INHERIT</literal> option. Of course, if the membership
373
+ grant has the <literal>SET</literal> option the member role would be able to
374
+ <link linkend="sql-set-role"><command>SET ROLE</command></link> to the
375
+ createdb role and then create a new database.
376
+ </para>
377
+
378
+ <para>
379
+ The membership grants created by the
380
+ <literal>IN ROLE</literal>, <literal>ROLE</literal>, and <literal>ADMIN</literal>
381
+ clauses have the role executing this command as the grantee.
365
382
</para>
366
383
367
384
<para>
@@ -460,8 +477,10 @@ CREATE ROLE <replaceable class="parameter">name</replaceable> [ WITH ADMIN <repl
460
477
461
478
<para>
462
479
The behavior specified by the SQL standard is most closely approximated
463
- by giving users the <literal>NOINHERIT</literal> attribute, while roles are
464
- given the <literal>INHERIT</literal> attribute.
480
+ creating SQL-standard users as <productname>PostgreSQL</productname>
481
+ roles with the <literal>NOINHERIT</literal> option, and SQL-standard
482
+ roles as <productname>PostgreSQL</productname> roles with the
483
+ <literal>INHERIT</literal> option.
465
484
</para>
466
485
467
486
<para>
0 commit comments