Skip to content

Commit 21912e3

Browse files
committed
doc: improve role option documentation
Role option management was changed in Postgres 16. This patch improves the docs around these changes, including CREATE ROLE's INHERIT option, inheritance handling, and grant's ability to change role options. Discussion: https://postgr.es/m/Zab9GiV63EENDcWG@momjian.us Co-authored-by: David G. Johnston Backpatch-through: 16
1 parent 16a80e8 commit 21912e3

File tree

3 files changed

+74
-50
lines changed

3 files changed

+74
-50
lines changed

doc/src/sgml/ref/create_role.sgml

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ in sync when changing the above synopsis!
6666
Note that roles are defined at the database cluster
6767
level, and so are valid in all databases in the cluster.
6868
</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>
6980
</refsect1>
7081

7182
<refsect1>
@@ -133,24 +144,21 @@ in sync when changing the above synopsis!
133144
<term><literal>NOINHERIT</literal></term>
134145
<listitem>
135146
<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.
146156
</para>
147157

148158
<para>
149159
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.
154162
</para>
155163
</listitem>
156164
</varlistentry>
@@ -285,9 +293,10 @@ in sync when changing the above synopsis!
285293
<para>
286294
The <literal>IN ROLE</literal> clause causes the new role to
287295
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.
291300
</para>
292301
</listitem>
293302
</varlistentry>
@@ -297,8 +306,12 @@ in sync when changing the above synopsis!
297306
<listitem>
298307
<para>
299308
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.
302315
</para>
303316
</listitem>
304317
</varlistentry>
@@ -307,10 +320,10 @@ in sync when changing the above synopsis!
307320
<term><literal>ADMIN</literal> <replaceable class="parameter">role_name</replaceable></term>
308321
<listitem>
309322
<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.
314327
</para>
315328
</listitem>
316329
</varlistentry>
@@ -353,15 +366,19 @@ in sync when changing the above synopsis!
353366
</para>
354367

355368
<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.
365382
</para>
366383

367384
<para>
@@ -460,8 +477,10 @@ CREATE ROLE <replaceable class="parameter">name</replaceable> [ WITH ADMIN <repl
460477

461478
<para>
462479
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.
465484
</para>
466485

467486
<para>

doc/src/sgml/ref/grant.sgml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,26 @@ GRANT <replaceable class="parameter">role_name</replaceable> [, ...] TO <replace
249249

250250
<para>
251251
This variant of the <command>GRANT</command> command grants membership
252-
in a role to one or more other roles. Membership in a role is significant
252+
in a role to one or more other roles, and the modification of
253+
membership options <literal>SET</literal>, <literal>INHERIT</literal>,
254+
and <literal>ADMIN</literal>; see <xref linkend="role-membership"/>
255+
for details. Membership in a role is significant
253256
because it potentially allows access to the privileges granted to a role
254257
to each of its members, and potentially also the ability to make changes
255258
to the role itself. However, the actual permissions conferred depend on
256-
the options associated with the grant.
259+
the options associated with the grant. To modify that options of
260+
an existing membership, simply specify the membership with updated
261+
option values.
257262
</para>
258263

259264
<para>
260265
Each of the options described below can be set to either
261266
<literal>TRUE</literal> or <literal>FALSE</literal>. The keyword
262267
<literal>OPTION</literal> is accepted as a synonym for
263268
<literal>TRUE</literal>, so that <literal>WITH ADMIN OPTION</literal>
264-
is a synonym for <literal>WITH ADMIN TRUE</literal>.
269+
is a synonym for <literal>WITH ADMIN TRUE</literal>. When altering
270+
an existing membership the omission of an option results in the current
271+
value being retained.
265272
</para>
266273

267274
<para>
@@ -275,15 +282,13 @@ GRANT <replaceable class="parameter">role_name</replaceable> [, ...] TO <replace
275282
</para>
276283

277284
<para>
278-
The <literal>INHERIT</literal> option, if it is set to
279-
<literal>TRUE</literal>, causes the member to inherit the privileges of
280-
the granted role. That is, it can automatically use whatever database
281-
privileges have been granted to that role. If set to
282-
<literal>FALSE</literal>, the member does not inherit the privileges
283-
of the granted role. If this clause is not specified, it defaults to
284-
true if the member role is set to <literal>INHERIT</literal> and to false
285-
if the member role is set to <literal>NOINHERIT</literal>.
286-
See <link linkend="sql-createrole"><command>CREATE ROLE</command></link>.
285+
The <literal>INHERIT</literal> option controls the inheritance status
286+
of the new membership; see <xref linkend="role-membership"/> for
287+
details on inheritance. If it is set to <literal>TRUE</literal>,
288+
it causes the new member to inherit from the granted role. If
289+
set to <literal>FALSE</literal>, the new member does not inherit.
290+
If unspecified when create a new role membership this defaults to
291+
the inheritance attribute of the role being added.
287292
</para>
288293

289294
<para>

doc/src/sgml/user-manag.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ REVOKE <replaceable>group_role</replaceable> FROM <replaceable>role1</replaceabl
409409
than the original login role, and any database objects created are
410410
considered owned by the group role not the login role. Second, member
411411
roles that have been granted membership with the
412-
<literal>INHERIT</literal> option automatically have use
413-
of the privileges of those roles, including any
414-
privileges inherited by those roles.
415-
As an example, suppose we have done:
412+
<literal>INHERIT</literal> option automatically have use of the
413+
privileges of those directly or indirectly a member of, though the
414+
chain stops at memberships lacking the inherit option. As an example,
415+
suppose we have done:
416416
<programlisting>
417417
CREATE ROLE joe LOGIN;
418418
CREATE ROLE admin;

0 commit comments

Comments
 (0)