Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 88be3f0

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 7743046 commit 88be3f0

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
@@ -68,6 +68,17 @@ in sync when changing the above synopsis!
6868
Note that roles are defined at the database cluster
6969
level, and so are valid in all databases in the cluster.
7070
</para>
71+
72+
<para>
73+
During role creation it is possible to immediately assign the newly created
74+
role to be a member of an existing role, and also assign existing roles
75+
to be members of the newly created role. The rules for which initial
76+
role membership options are enabled described below in the
77+
<literal>IN ROLE</literal>, <literal>ROLE</literal>, and
78+
<literal>ADMIN</literal> clauses. The <xref linkend="sql-grant"/>
79+
command has fine-grained option control during membership creation,
80+
and the ability to modify these options after the new role is created.
81+
</para>
7182
</refsect1>
7283

7384
<refsect1>
@@ -135,24 +146,21 @@ in sync when changing the above synopsis!
135146
<term><literal>NOINHERIT</literal></term>
136147
<listitem>
137148
<para>
138-
When the <literal>GRANT</literal> statement is used to confer
139-
membership in one role to another role, the <literal>GRANT</literal>
140-
may use the <literal>WITH INHERIT</literal> clause to specify whether
141-
the privileges of the granted role should be <quote>inherited</quote>
142-
by the new member. If the <literal>GRANT</literal> statement does not
143-
specify either inheritance behavior, the new <literal>GRANT</literal>
144-
will be created <literal>WITH INHERIT TRUE</literal> if the member
145-
role is set to <literal>INHERIT</literal> and to
146-
<literal>WITH INHERIT FALSE</literal> if it is set to
147-
<literal>NOINHERIT</literal>.
149+
This affects the membership inheritance status when this
150+
role is added as a member of another role, both in this and
151+
future commands. Specifically, it controls the inheritance
152+
status of memberships added with this command using the
153+
<literal>IN ROLE</literal> clause, and in later commands using
154+
the <literal>ROLE</literal> clause. It is also used as the
155+
default inheritance status when adding this role as a member
156+
using the <literal>GRANT</literal> command. If not specified,
157+
<literal>INHERIT</literal> is the default.
148158
</para>
149159

150160
<para>
151161
In <productname>PostgreSQL</productname> versions before 16,
152-
the <literal>GRANT</literal> statement did not support
153-
<literal>WITH INHERIT</literal>. Therefore, changing this role-level
154-
property would also change the behavior of already-existing grants.
155-
This is no longer the case.
162+
inheritance was a role-level attribute that controlled all runtime
163+
membership checks for that role.
156164
</para>
157165
</listitem>
158166
</varlistentry>
@@ -287,9 +295,10 @@ in sync when changing the above synopsis!
287295
<para>
288296
The <literal>IN ROLE</literal> clause causes the new role to
289297
be automatically added as a member of the specified existing
290-
roles. (Note that there is no option to add the new role as an
291-
administrator; use a separate <command>GRANT</command> command
292-
to do that.)
298+
roles. The new membership will have the <literal>SET</literal>
299+
option enabled and the <literal>ADMIN</literal> option disabled.
300+
The <literal>INHERIT</literal> option will be enabled unless the
301+
<literal>NOINHERIT</literal> option is specified.
293302
</para>
294303
</listitem>
295304
</varlistentry>
@@ -308,8 +317,12 @@ in sync when changing the above synopsis!
308317
<listitem>
309318
<para>
310319
The <literal>ROLE</literal> clause causes one or more specified
311-
existing roles to be automatically added as members of the new
312-
role. This in effect makes the new role a <quote>group</quote>.
320+
existing roles to be automatically added as members, with the
321+
<literal>SET</literal> option enabled. This in effect makes the
322+
new role a <quote>group</quote>. Roles named in this clause
323+
with role-level the <literal>INHERIT</literal> attribute will have
324+
the <literal>INHERIT</literal> option enabled in the new membership.
325+
New memberships will have the <literal>ADMIN</literal> option disabled.
313326
</para>
314327
</listitem>
315328
</varlistentry>
@@ -318,10 +331,10 @@ in sync when changing the above synopsis!
318331
<term><literal>ADMIN</literal> <replaceable class="parameter">role_name</replaceable></term>
319332
<listitem>
320333
<para>
321-
The <literal>ADMIN</literal> clause is like <literal>ROLE</literal>,
322-
but the named roles are added to the new role <literal>WITH ADMIN
323-
OPTION</literal>, giving them the right to grant membership in this role
324-
to others.
334+
The <literal>ADMIN</literal> clause has the same effect as
335+
<literal>ROLE</literal>, but the named roles are added as members
336+
of the new role with <literal>ADMIN</literal> enabled, giving
337+
them the right to grant membership in the new role to others.
325338
</para>
326339
</listitem>
327340
</varlistentry>
@@ -374,15 +387,19 @@ in sync when changing the above synopsis!
374387
</para>
375388

376389
<para>
377-
The <literal>INHERIT</literal> attribute governs inheritance of grantable
378-
privileges (that is, access privileges for database objects and role
379-
memberships). It does not apply to the special role attributes set by
380-
<command>CREATE ROLE</command> and <command>ALTER ROLE</command>. For example, being
381-
a member of a role with <literal>CREATEDB</literal> privilege does not immediately
382-
grant the ability to create databases, even if <literal>INHERIT</literal> is set;
383-
it would be necessary to become that role via
384-
<link linkend="sql-set-role"><command>SET ROLE</command></link> before
385-
creating a database.
390+
The role attributes defined here are non-inheritable, i.e., being a
391+
member of a role with, e.g., <literal>CREATEDB</literal> will not
392+
allow the member to create new databases even if the membership grant
393+
has the <literal>INHERIT</literal> option. Of course, if the membership
394+
grant has the <literal>SET</literal> option the member role would be able to
395+
<link linkend="sql-set-role"><command>SET ROLE</command></link> to the
396+
createdb role and then create a new database.
397+
</para>
398+
399+
<para>
400+
The membership grants created by the
401+
<literal>IN ROLE</literal>, <literal>ROLE</literal>, and <literal>ADMIN</literal>
402+
clauses have the role executing this command as the grantee.
386403
</para>
387404

388405
<para>
@@ -481,8 +498,10 @@ CREATE ROLE <replaceable class="parameter">name</replaceable> [ WITH ADMIN <repl
481498

482499
<para>
483500
The behavior specified by the SQL standard is most closely approximated
484-
by giving users the <literal>NOINHERIT</literal> attribute, while roles are
485-
given the <literal>INHERIT</literal> attribute.
501+
creating SQL-standard users as <productname>PostgreSQL</productname>
502+
roles with the <literal>NOINHERIT</literal> option, and SQL-standard
503+
roles as <productname>PostgreSQL</productname> roles with the
504+
<literal>INHERIT</literal> option.
486505
</para>
487506
</refsect1>
488507

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)