2005-07-27 01:24:02 +02:00
|
|
|
<!--
|
2010-09-20 22:08:53 +02:00
|
|
|
doc/src/sgml/ref/create_role.sgml
|
2005-07-27 01:24:02 +02:00
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refentry id="sql-createrole">
|
2014-02-24 03:25:35 +01:00
|
|
|
<indexterm zone="sql-createrole">
|
|
|
|
<primary>CREATE ROLE</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2005-07-27 01:24:02 +02:00
|
|
|
<refmeta>
|
2010-04-03 09:23:02 +02:00
|
|
|
<refentrytitle>CREATE ROLE</refentrytitle>
|
2008-11-14 11:22:48 +01:00
|
|
|
<manvolnum>7</manvolnum>
|
2005-07-27 01:24:02 +02:00
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>CREATE ROLE</refname>
|
|
|
|
<refpurpose>define a new database role</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<synopsis>
|
2017-10-09 04:00:57 +02:00
|
|
|
CREATE ROLE <replaceable class="parameter">name</replaceable> [ [ WITH ] <replaceable class="parameter">option</replaceable> [ ... ] ]
|
2005-07-27 01:24:02 +02:00
|
|
|
|
2017-10-09 04:00:57 +02:00
|
|
|
<phrase>where <replaceable class="parameter">option</replaceable> can be:</phrase>
|
2010-11-23 21:27:50 +01:00
|
|
|
|
2005-07-27 01:24:02 +02:00
|
|
|
SUPERUSER | NOSUPERUSER
|
|
|
|
| CREATEDB | NOCREATEDB
|
|
|
|
| CREATEROLE | NOCREATEROLE
|
|
|
|
| INHERIT | NOINHERIT
|
|
|
|
| LOGIN | NOLOGIN
|
2010-12-29 11:05:03 +01:00
|
|
|
| REPLICATION | NOREPLICATION
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
| BYPASSRLS | NOBYPASSRLS
|
2017-10-09 04:00:57 +02:00
|
|
|
| CONNECTION LIMIT <replaceable class="parameter">connlimit</replaceable>
|
2018-11-23 01:10:24 +01:00
|
|
|
| [ ENCRYPTED ] PASSWORD '<replaceable class="parameter">password</replaceable>' | PASSWORD NULL
|
2017-10-09 04:00:57 +02:00
|
|
|
| VALID UNTIL '<replaceable class="parameter">timestamp</replaceable>'
|
|
|
|
| IN ROLE <replaceable class="parameter">role_name</replaceable> [, ...]
|
|
|
|
| ROLE <replaceable class="parameter">role_name</replaceable> [, ...]
|
|
|
|
| ADMIN <replaceable class="parameter">role_name</replaceable> [, ...]
|
|
|
|
| SYSID <replaceable class="parameter">uid</replaceable>
|
2005-07-27 01:24:02 +02:00
|
|
|
</synopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
2020-04-10 16:44:09 +02:00
|
|
|
<!--
|
|
|
|
CAUTION: remember to keep create_user.sgml and create_group.sgml
|
|
|
|
in sync when changing the above synopsis!
|
|
|
|
-->
|
|
|
|
|
2005-07-27 01:24:02 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>CREATE ROLE</command> adds a new role to a
|
|
|
|
<productname>PostgreSQL</productname> database cluster. A role is
|
|
|
|
an entity that can own database objects and have database privileges;
|
2017-10-09 03:44:17 +02:00
|
|
|
a role can be considered a <quote>user</quote>, a <quote>group</quote>, or both
|
2005-07-27 01:24:02 +02:00
|
|
|
depending on how it is used. Refer to
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="user-manag"/> and <xref
|
|
|
|
linkend="client-authentication"/> for information about managing
|
2017-10-09 03:44:17 +02:00
|
|
|
users and authentication. You must have <literal>CREATEROLE</literal>
|
2005-07-27 01:24:02 +02:00
|
|
|
privilege or be a database superuser to use this command.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Note that roles are defined at the database cluster
|
|
|
|
level, and so are valid in all databases in the cluster.
|
|
|
|
</para>
|
2024-02-01 12:11:53 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
During role creation it is possible to immediately assign the newly created
|
|
|
|
role to be a member of an existing role, and also assign existing roles
|
|
|
|
to be members of the newly created role. The rules for which initial
|
|
|
|
role membership options are enabled described below in the
|
|
|
|
<literal>IN ROLE</literal>, <literal>ROLE</literal>, and
|
|
|
|
<literal>ADMIN</literal> clauses. The <xref linkend="sql-grant"/>
|
|
|
|
command has fine-grained option control during membership creation,
|
|
|
|
and the ability to modify these options after the new role is created.
|
|
|
|
</para>
|
2005-07-27 01:24:02 +02:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Parameters</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">name</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The name of the new role.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>SUPERUSER</literal></term>
|
|
|
|
<term><literal>NOSUPERUSER</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
These clauses determine whether the new role is a <quote>superuser</quote>,
|
2005-07-27 01:24:02 +02:00
|
|
|
who can override all access restrictions within the database.
|
|
|
|
Superuser status is dangerous and should be used only when really
|
|
|
|
needed. You must yourself be a superuser to create a new superuser.
|
|
|
|
If not specified,
|
|
|
|
<literal>NOSUPERUSER</literal> is the default.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>CREATEDB</literal></term>
|
|
|
|
<term><literal>NOCREATEDB</literal></term>
|
2005-07-27 01:24:02 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
These clauses define a role's ability to create databases. If
|
|
|
|
<literal>CREATEDB</literal> is specified, the role being
|
|
|
|
defined will be allowed to create new databases. Specifying
|
|
|
|
<literal>NOCREATEDB</literal> will deny a role the ability to
|
|
|
|
create databases. If not specified,
|
|
|
|
<literal>NOCREATEDB</literal> is the default.
|
Adjust interaction of CREATEROLE with role properties.
Previously, a CREATEROLE user without SUPERUSER could not alter
REPLICATION users in any way, and could not set the BYPASSRLS
attribute. However, they could manipulate the CREATEDB property
even if they themselves did not possess it.
With this change, a CREATEROLE user without SUPERUSER can set or
clear the REPLICATION, BYPASSRLS, or CREATEDB property on a new
role or a role that they have rights to manage if and only if
that property is set for their own role.
This implements the standard idea that you can't give permissions
you don't have (but you can give the ones you do have). We might
in the future want to provide more powerful ways to constrain
what a CREATEROLE user can do - for example, to limit whether
CONNECTION LIMIT can be set or the values to which it can be set -
but that is left as future work.
Patch by me, reviewed by Nathan Bossart, Tushar Ahuja, and Neha
Sharma.
Discussion: http://postgr.es/m/CA+TgmobX=LHg_J5aT=0pi9gJy=JdtrUVGAu0zhr-i5v5nNbJDg@mail.gmail.com
2023-01-24 16:57:09 +01:00
|
|
|
Only superuser roles or roles with <literal>CREATEDB</literal>
|
|
|
|
can specify <literal>CREATEDB</literal>.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>CREATEROLE</literal></term>
|
|
|
|
<term><literal>NOCREATEROLE</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
These clauses determine whether a role will be permitted to
|
Restrict the privileges of CREATEROLE users.
Previously, CREATEROLE users were permitted to make nearly arbitrary
changes to roles that they didn't create, with certain exceptions,
particularly superuser roles. Instead, allow CREATEROLE users to make such
changes to roles for which they possess ADMIN OPTION, and to
grant membership only in roles for which they possess ADMIN OPTION.
When a CREATEROLE user who is not a superuser creates a role, grant
ADMIN OPTION on the newly-created role to the creator, so that they
can administer roles they create or for which they have been given
privileges.
With these changes, CREATEROLE users still have very significant
powers that unprivileged users do not receive: they can alter, rename,
drop, comment on, change the password for, and change security labels
on roles. However, they can now do these things only for roles for
which they possess appropriate privileges, rather than all
non-superuser roles; moreover, they cannot grant a role such as
pg_execute_server_program unless they themselves possess it.
Patch by me, reviewed by Mark Dilger.
Discussion: https://postgr.es/m/CA+TgmobN59ct+Emmz6ig1Nua2Q-_o=r6DSD98KfU53kctq_kQw@mail.gmail.com
2023-01-10 18:44:30 +01:00
|
|
|
create, alter, drop, comment on, and change the security label for
|
|
|
|
other roles.
|
2023-02-27 08:55:39 +01:00
|
|
|
See <xref linkend="role-creation"/> for more details about what
|
2023-01-03 20:50:40 +01:00
|
|
|
capabilities are conferred by this privilege.
|
|
|
|
If not specified, <literal>NOCREATEROLE</literal> is the default.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>INHERIT</literal></term>
|
|
|
|
<term><literal>NOINHERIT</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2024-02-01 12:11:53 +01:00
|
|
|
This affects the membership inheritance status when this
|
|
|
|
role is added as a member of another role, both in this and
|
|
|
|
future commands. Specifically, it controls the inheritance
|
|
|
|
status of memberships added with this command using the
|
|
|
|
<literal>IN ROLE</literal> clause, and in later commands using
|
|
|
|
the <literal>ROLE</literal> clause. It is also used as the
|
|
|
|
default inheritance status when adding this role as a member
|
|
|
|
using the <literal>GRANT</literal> command. If not specified,
|
|
|
|
<literal>INHERIT</literal> is the default.
|
2022-08-25 16:06:02 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
In <productname>PostgreSQL</productname> versions before 16,
|
2024-02-01 12:11:53 +01:00
|
|
|
inheritance was a role-level attribute that controlled all runtime
|
|
|
|
membership checks for that role.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>LOGIN</literal></term>
|
|
|
|
<term><literal>NOLOGIN</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
These clauses determine whether a role is allowed to log in;
|
|
|
|
that is, whether the role can be given as the initial session
|
|
|
|
authorization name during client connection. A role having
|
2005-08-15 01:35:38 +02:00
|
|
|
the <literal>LOGIN</literal> attribute can be thought of as a user.
|
2005-07-27 01:24:02 +02:00
|
|
|
Roles without this attribute are useful for managing database
|
|
|
|
privileges, but are not users in the usual sense of the word.
|
|
|
|
If not specified,
|
|
|
|
<literal>NOLOGIN</literal> is the default, except when
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>CREATE ROLE</command> is invoked through its alternative spelling
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<link linkend="sql-createuser"><command>CREATE USER</command></link>.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2010-12-29 11:05:03 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>REPLICATION</literal></term>
|
|
|
|
<term><literal>NOREPLICATION</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-08-11 22:14:55 +02:00
|
|
|
These clauses determine whether a role is a replication role. A role
|
|
|
|
must have this attribute (or be a superuser) in order to be able to
|
|
|
|
connect to the server in replication mode (physical or logical
|
|
|
|
replication) and in order to be able to create or drop replication
|
|
|
|
slots.
|
2017-10-09 03:44:17 +02:00
|
|
|
A role having the <literal>REPLICATION</literal> attribute is a very
|
2010-12-29 11:05:03 +01:00
|
|
|
highly privileged role, and should only be used on roles actually
|
2010-12-30 21:15:55 +01:00
|
|
|
used for replication. If not specified,
|
2012-01-14 17:22:16 +01:00
|
|
|
<literal>NOREPLICATION</literal> is the default.
|
Adjust interaction of CREATEROLE with role properties.
Previously, a CREATEROLE user without SUPERUSER could not alter
REPLICATION users in any way, and could not set the BYPASSRLS
attribute. However, they could manipulate the CREATEDB property
even if they themselves did not possess it.
With this change, a CREATEROLE user without SUPERUSER can set or
clear the REPLICATION, BYPASSRLS, or CREATEDB property on a new
role or a role that they have rights to manage if and only if
that property is set for their own role.
This implements the standard idea that you can't give permissions
you don't have (but you can give the ones you do have). We might
in the future want to provide more powerful ways to constrain
what a CREATEROLE user can do - for example, to limit whether
CONNECTION LIMIT can be set or the values to which it can be set -
but that is left as future work.
Patch by me, reviewed by Nathan Bossart, Tushar Ahuja, and Neha
Sharma.
Discussion: http://postgr.es/m/CA+TgmobX=LHg_J5aT=0pi9gJy=JdtrUVGAu0zhr-i5v5nNbJDg@mail.gmail.com
2023-01-24 16:57:09 +01:00
|
|
|
Only superuser roles or roles with <literal>REPLICATION</literal>
|
|
|
|
can specify <literal>REPLICATION</literal>.
|
2010-12-29 11:05:03 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>BYPASSRLS</literal></term>
|
|
|
|
<term><literal>NOBYPASSRLS</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-10-04 02:19:57 +02:00
|
|
|
These clauses determine whether a role bypasses every row-level
|
|
|
|
security (RLS) policy. <literal>NOBYPASSRLS</literal> is the default.
|
Adjust interaction of CREATEROLE with role properties.
Previously, a CREATEROLE user without SUPERUSER could not alter
REPLICATION users in any way, and could not set the BYPASSRLS
attribute. However, they could manipulate the CREATEDB property
even if they themselves did not possess it.
With this change, a CREATEROLE user without SUPERUSER can set or
clear the REPLICATION, BYPASSRLS, or CREATEDB property on a new
role or a role that they have rights to manage if and only if
that property is set for their own role.
This implements the standard idea that you can't give permissions
you don't have (but you can give the ones you do have). We might
in the future want to provide more powerful ways to constrain
what a CREATEROLE user can do - for example, to limit whether
CONNECTION LIMIT can be set or the values to which it can be set -
but that is left as future work.
Patch by me, reviewed by Nathan Bossart, Tushar Ahuja, and Neha
Sharma.
Discussion: http://postgr.es/m/CA+TgmobX=LHg_J5aT=0pi9gJy=JdtrUVGAu0zhr-i5v5nNbJDg@mail.gmail.com
2023-01-24 16:57:09 +01:00
|
|
|
Only superuser roles or roles with <literal>BYPASSRLS</literal>
|
|
|
|
can specify <literal>BYPASSRLS</literal>.
|
2020-11-03 21:41:32 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
Note that pg_dump will set <literal>row_security</literal> to
|
|
|
|
<literal>OFF</literal> by default, to ensure all contents of a table are
|
|
|
|
dumped out. If the user running pg_dump does not have appropriate
|
2020-11-03 21:41:32 +01:00
|
|
|
permissions, an error will be returned. However, superusers and the
|
|
|
|
owner of the table being dumped always bypass RLS.
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2005-07-31 19:19:22 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>CONNECTION LIMIT</literal> <replaceable class="parameter">connlimit</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If role can log in, this specifies how many concurrent connections
|
2017-02-01 23:52:35 +01:00
|
|
|
the role can make. -1 (the default) means no limit. Note that only
|
|
|
|
normal connections are counted towards this limit. Neither prepared
|
|
|
|
transactions nor background worker connections are counted towards
|
|
|
|
this limit.
|
2005-07-31 19:19:22 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2005-07-27 01:24:02 +02:00
|
|
|
<varlistentry>
|
2018-11-23 01:10:24 +01:00
|
|
|
<term>[ <literal>ENCRYPTED</literal> ] <literal>PASSWORD</literal> '<replaceable class="parameter">password</replaceable>'</term>
|
|
|
|
<term><literal>PASSWORD NULL</literal></term>
|
2005-07-27 01:24:02 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the role's password. (A password is only of use for
|
2005-12-23 17:46:39 +01:00
|
|
|
roles having the <literal>LOGIN</literal> attribute, but you
|
|
|
|
can nonetheless define one for roles without it.) If you do
|
|
|
|
not plan to use password authentication you can omit this
|
|
|
|
option. If no password is specified, the password will be set
|
|
|
|
to null and password authentication will always fail for that
|
|
|
|
user. A null password can optionally be written explicitly as
|
|
|
|
<literal>PASSWORD NULL</literal>.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
Don't allow logging in with empty password.
Some authentication methods allowed it, others did not. In the client-side,
libpq does not even try to authenticate with an empty password, which makes
using empty passwords hazardous: an administrator might think that an
account with an empty password cannot be used to log in, because psql
doesn't allow it, and not realize that a different client would in fact
allow it. To clear that confusion and to be be consistent, disallow empty
passwords in all authentication methods.
All the authentication methods that used plaintext authentication over the
wire, except for BSD authentication, already checked that the password
received from the user was not empty. To avoid forgetting it in the future
again, move the check to the recv_password_packet function. That only
forbids using an empty password with plaintext authentication, however.
MD5 and SCRAM need a different fix:
* In stable branches, check that the MD5 hash stored for the user does not
not correspond to an empty string. This adds some overhead to MD5
authentication, because the server needs to compute an extra MD5 hash, but
it is not noticeable in practice.
* In HEAD, modify CREATE and ALTER ROLE to clear the password if an empty
string, or a password hash that corresponds to an empty string, is
specified. The user-visible behavior is the same as in the stable branches,
the user cannot log in, but it seems better to stop the empty password from
entering the system in the first place. Secondly, it is fairly expensive to
check that a SCRAM hash doesn't correspond to an empty string, because
computing a SCRAM hash is much more expensive than an MD5 hash by design,
so better avoid doing that on every authentication.
We could clear the password on CREATE/ALTER ROLE also in stable branches,
but we would still need to check at authentication time, because even if we
prevent empty passwords from being stored in pg_authid, there might be
existing ones there already.
Reported by Jeroen van der Ham, Ben de Graaff and Jelte Fennema.
Security: CVE-2017-7546
2017-08-07 16:03:42 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
Specifying an empty string will also set the password to null,
|
2017-10-09 03:44:17 +02:00
|
|
|
but that was not the case before <productname>PostgreSQL</productname>
|
Don't allow logging in with empty password.
Some authentication methods allowed it, others did not. In the client-side,
libpq does not even try to authenticate with an empty password, which makes
using empty passwords hazardous: an administrator might think that an
account with an empty password cannot be used to log in, because psql
doesn't allow it, and not realize that a different client would in fact
allow it. To clear that confusion and to be be consistent, disallow empty
passwords in all authentication methods.
All the authentication methods that used plaintext authentication over the
wire, except for BSD authentication, already checked that the password
received from the user was not empty. To avoid forgetting it in the future
again, move the check to the recv_password_packet function. That only
forbids using an empty password with plaintext authentication, however.
MD5 and SCRAM need a different fix:
* In stable branches, check that the MD5 hash stored for the user does not
not correspond to an empty string. This adds some overhead to MD5
authentication, because the server needs to compute an extra MD5 hash, but
it is not noticeable in practice.
* In HEAD, modify CREATE and ALTER ROLE to clear the password if an empty
string, or a password hash that corresponds to an empty string, is
specified. The user-visible behavior is the same as in the stable branches,
the user cannot log in, but it seems better to stop the empty password from
entering the system in the first place. Secondly, it is fairly expensive to
check that a SCRAM hash doesn't correspond to an empty string, because
computing a SCRAM hash is much more expensive than an MD5 hash by design,
so better avoid doing that on every authentication.
We could clear the password on CREATE/ALTER ROLE also in stable branches,
but we would still need to check at authentication time, because even if we
prevent empty passwords from being stored in pg_authid, there might be
existing ones there already.
Reported by Jeroen van der Ham, Ben de Graaff and Jelte Fennema.
Security: CVE-2017-7546
2017-08-07 16:03:42 +02:00
|
|
|
version 10. In earlier versions, an empty string could be used,
|
|
|
|
or not, depending on the authentication method and the exact
|
|
|
|
version, and libpq would refuse to use it in any case.
|
|
|
|
To avoid the ambiguity, specifying an empty string should be
|
|
|
|
avoided.
|
|
|
|
</para>
|
|
|
|
</note>
|
2005-07-27 01:24:02 +02:00
|
|
|
<para>
|
Remove support for password_encryption='off' / 'plain'.
Storing passwords in plaintext hasn't been a good idea for a very long
time, if ever. Now seems like a good time to finally forbid it, since we're
messing with this in PostgreSQL 10 anyway.
Remove the CREATE/ALTER USER UNENCRYPTED PASSSWORD 'foo' syntax, since
storing passwords unencrypted is no longer supported. ENCRYPTED PASSWORD
'foo' is still accepted, but ENCRYPTED is now just a noise-word, it does
the same as just PASSWORD 'foo'.
Likewise, remove the --unencrypted option from createuser, but accept
--encrypted as a no-op for backward compatibility. AFAICS, --encrypted was
a no-op even before this patch, because createuser encrypted the password
before sending it to the server even if --encrypted was not specified. It
added the ENCRYPTED keyword to the SQL command, but since the password was
already in encrypted form, it didn't make any difference. The documentation
was not clear on whether that was intended or not, but it's moot now.
Also, while password_encryption='on' is still accepted as an alias for
'md5', it is now marked as hidden, so that it is not listed as an accepted
value in error hints, for example. That's not directly related to removing
'plain', but it seems better this way.
Reviewed by Michael Paquier
Discussion: https://www.postgresql.org/message-id/16e9b768-fd78-0b12-cfc1-7b6b7f238fde@iki.fi
2017-05-08 10:26:07 +02:00
|
|
|
The password is always stored encrypted in the system catalogs. The
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>ENCRYPTED</literal> keyword has no effect, but is accepted for
|
Remove support for password_encryption='off' / 'plain'.
Storing passwords in plaintext hasn't been a good idea for a very long
time, if ever. Now seems like a good time to finally forbid it, since we're
messing with this in PostgreSQL 10 anyway.
Remove the CREATE/ALTER USER UNENCRYPTED PASSSWORD 'foo' syntax, since
storing passwords unencrypted is no longer supported. ENCRYPTED PASSWORD
'foo' is still accepted, but ENCRYPTED is now just a noise-word, it does
the same as just PASSWORD 'foo'.
Likewise, remove the --unencrypted option from createuser, but accept
--encrypted as a no-op for backward compatibility. AFAICS, --encrypted was
a no-op even before this patch, because createuser encrypted the password
before sending it to the server even if --encrypted was not specified. It
added the ENCRYPTED keyword to the SQL command, but since the password was
already in encrypted form, it didn't make any difference. The documentation
was not clear on whether that was intended or not, but it's moot now.
Also, while password_encryption='on' is still accepted as an alias for
'md5', it is now marked as hidden, so that it is not listed as an accepted
value in error hints, for example. That's not directly related to removing
'plain', but it seems better this way.
Reviewed by Michael Paquier
Discussion: https://www.postgresql.org/message-id/16e9b768-fd78-0b12-cfc1-7b6b7f238fde@iki.fi
2017-05-08 10:26:07 +02:00
|
|
|
backwards compatibility. The method of encryption is determined
|
2017-11-23 15:39:47 +01:00
|
|
|
by the configuration parameter <xref linkend="guc-password-encryption"/>.
|
Remove support for password_encryption='off' / 'plain'.
Storing passwords in plaintext hasn't been a good idea for a very long
time, if ever. Now seems like a good time to finally forbid it, since we're
messing with this in PostgreSQL 10 anyway.
Remove the CREATE/ALTER USER UNENCRYPTED PASSSWORD 'foo' syntax, since
storing passwords unencrypted is no longer supported. ENCRYPTED PASSWORD
'foo' is still accepted, but ENCRYPTED is now just a noise-word, it does
the same as just PASSWORD 'foo'.
Likewise, remove the --unencrypted option from createuser, but accept
--encrypted as a no-op for backward compatibility. AFAICS, --encrypted was
a no-op even before this patch, because createuser encrypted the password
before sending it to the server even if --encrypted was not specified. It
added the ENCRYPTED keyword to the SQL command, but since the password was
already in encrypted form, it didn't make any difference. The documentation
was not clear on whether that was intended or not, but it's moot now.
Also, while password_encryption='on' is still accepted as an alias for
'md5', it is now marked as hidden, so that it is not listed as an accepted
value in error hints, for example. That's not directly related to removing
'plain', but it seems better this way.
Reviewed by Michael Paquier
Discussion: https://www.postgresql.org/message-id/16e9b768-fd78-0b12-cfc1-7b6b7f238fde@iki.fi
2017-05-08 10:26:07 +02:00
|
|
|
If the presented password string is already in MD5-encrypted or
|
|
|
|
SCRAM-encrypted format, then it is stored as-is regardless of
|
2017-10-09 03:44:17 +02:00
|
|
|
<varname>password_encryption</varname> (since the system cannot decrypt
|
Remove support for password_encryption='off' / 'plain'.
Storing passwords in plaintext hasn't been a good idea for a very long
time, if ever. Now seems like a good time to finally forbid it, since we're
messing with this in PostgreSQL 10 anyway.
Remove the CREATE/ALTER USER UNENCRYPTED PASSSWORD 'foo' syntax, since
storing passwords unencrypted is no longer supported. ENCRYPTED PASSWORD
'foo' is still accepted, but ENCRYPTED is now just a noise-word, it does
the same as just PASSWORD 'foo'.
Likewise, remove the --unencrypted option from createuser, but accept
--encrypted as a no-op for backward compatibility. AFAICS, --encrypted was
a no-op even before this patch, because createuser encrypted the password
before sending it to the server even if --encrypted was not specified. It
added the ENCRYPTED keyword to the SQL command, but since the password was
already in encrypted form, it didn't make any difference. The documentation
was not clear on whether that was intended or not, but it's moot now.
Also, while password_encryption='on' is still accepted as an alias for
'md5', it is now marked as hidden, so that it is not listed as an accepted
value in error hints, for example. That's not directly related to removing
'plain', but it seems better this way.
Reviewed by Michael Paquier
Discussion: https://www.postgresql.org/message-id/16e9b768-fd78-0b12-cfc1-7b6b7f238fde@iki.fi
2017-05-08 10:26:07 +02:00
|
|
|
the specified encrypted password string, to encrypt it in a
|
|
|
|
different format). This allows reloading of encrypted passwords
|
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
|
|
|
during dump/restore.
|
|
|
|
</para>
|
2005-07-27 01:24:02 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>VALID UNTIL</literal> '<replaceable class="parameter">timestamp</replaceable>'</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <literal>VALID UNTIL</literal> clause sets a date and
|
|
|
|
time after which the role's password is no longer valid. If
|
|
|
|
this clause is omitted the password will be valid for all time.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>IN ROLE</literal> <replaceable class="parameter">role_name</replaceable></term>
|
2005-07-27 01:24:02 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2023-05-19 04:22:17 +02:00
|
|
|
The <literal>IN ROLE</literal> clause causes the new role to
|
|
|
|
be automatically added as a member of the specified existing
|
2024-02-01 12:11:53 +01:00
|
|
|
roles. The new membership will have the <literal>SET</literal>
|
|
|
|
option enabled and the <literal>ADMIN</literal> option disabled.
|
|
|
|
The <literal>INHERIT</literal> option will be enabled unless the
|
|
|
|
<literal>NOINHERIT</literal> option is specified.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>ROLE</literal> <replaceable class="parameter">role_name</replaceable></term>
|
2005-07-27 01:24:02 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2023-05-19 04:22:17 +02:00
|
|
|
The <literal>ROLE</literal> clause causes one or more specified
|
2024-02-01 12:11:53 +01:00
|
|
|
existing roles to be automatically added as members, with the
|
|
|
|
<literal>SET</literal> option enabled. This in effect makes the
|
|
|
|
new role a <quote>group</quote>. Roles named in this clause
|
2024-03-27 22:58:11 +01:00
|
|
|
with the role-level <literal>INHERIT</literal> attribute will have
|
2024-02-01 12:11:53 +01:00
|
|
|
the <literal>INHERIT</literal> option enabled in the new membership.
|
|
|
|
New memberships will have the <literal>ADMIN</literal> option disabled.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>ADMIN</literal> <replaceable class="parameter">role_name</replaceable></term>
|
2005-07-27 01:24:02 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2024-02-01 12:11:53 +01:00
|
|
|
The <literal>ADMIN</literal> clause has the same effect as
|
|
|
|
<literal>ROLE</literal>, but the named roles are added as members
|
|
|
|
of the new role with <literal>ADMIN</literal> enabled, giving
|
|
|
|
them the right to grant membership in the new role to others.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>SYSID</literal> <replaceable class="parameter">uid</replaceable></term>
|
2005-07-27 01:24:02 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <literal>SYSID</literal> clause is ignored, but is accepted
|
|
|
|
for backwards compatibility.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2010-11-23 21:27:50 +01:00
|
|
|
</refsect1>
|
2005-07-27 01:24:02 +02:00
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<para>
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
Use <link linkend="sql-alterrole"><command>ALTER ROLE</command></link> to
|
|
|
|
change the attributes of a role, and <link linkend="sql-droprole"><command>DROP ROLE</command></link>
|
2010-04-03 09:23:02 +02:00
|
|
|
to remove a role. All the attributes
|
2017-10-09 03:44:17 +02:00
|
|
|
specified by <command>CREATE ROLE</command> can be modified by later
|
|
|
|
<command>ALTER ROLE</command> commands.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The preferred way to add and remove members of roles that are being
|
|
|
|
used as groups is to use
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<link linkend="sql-grant"><command>GRANT</command></link> and
|
|
|
|
<link linkend="sql-revoke"><command>REVOKE</command></link>.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>VALID UNTIL</literal> clause defines an expiration time for a
|
2021-03-10 18:38:43 +01:00
|
|
|
password only, not for the role per se. In
|
2005-07-27 01:24:02 +02:00
|
|
|
particular, the expiration time is not enforced when logging in using
|
|
|
|
a non-password-based authentication method.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2024-02-01 12:11:53 +01:00
|
|
|
The role attributes defined here are non-inheritable, i.e., being a
|
|
|
|
member of a role with, e.g., <literal>CREATEDB</literal> will not
|
|
|
|
allow the member to create new databases even if the membership grant
|
|
|
|
has the <literal>INHERIT</literal> option. Of course, if the membership
|
|
|
|
grant has the <literal>SET</literal> option the member role would be able to
|
|
|
|
<link linkend="sql-set-role"><command>SET ROLE</command></link> to the
|
|
|
|
createdb role and then create a new database.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The membership grants created by the
|
|
|
|
<literal>IN ROLE</literal>, <literal>ROLE</literal>, and <literal>ADMIN</literal>
|
|
|
|
clauses have the role executing this command as the grantee.
|
2005-08-15 01:35:38 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>INHERIT</literal> attribute is the default for reasons of backwards
|
2005-07-27 01:24:02 +02:00
|
|
|
compatibility: in prior releases of <productname>PostgreSQL</productname>,
|
|
|
|
users always had access to all privileges of groups they were members of.
|
2017-10-09 03:44:17 +02:00
|
|
|
However, <literal>NOINHERIT</literal> provides a closer match to the semantics
|
2005-07-27 01:24:02 +02:00
|
|
|
specified in the SQL standard.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<productname>PostgreSQL</productname> includes a program <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="app-createuser"/> that has
|
2005-07-27 01:24:02 +02:00
|
|
|
the same functionality as <command>CREATE ROLE</command> (in fact,
|
|
|
|
it calls this command) but can be run from the command shell.
|
|
|
|
</para>
|
2005-07-31 19:19:22 +02:00
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>CONNECTION LIMIT</literal> option is only enforced approximately;
|
2005-07-31 19:19:22 +02:00
|
|
|
if two new sessions start at about the same time when just one
|
2017-10-09 03:44:17 +02:00
|
|
|
connection <quote>slot</quote> remains for the role, it is possible that
|
2005-07-31 19:19:22 +02:00
|
|
|
both will fail. Also, the limit is never enforced for superusers.
|
|
|
|
</para>
|
2005-12-18 03:17:16 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Caution must be exercised when specifying an unencrypted password
|
|
|
|
with this command. The password will be transmitted to the server
|
|
|
|
in cleartext, and it might also be logged in the client's command
|
|
|
|
history or the server log. The command <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="app-createuser"/>, however, transmits
|
|
|
|
the password encrypted. Also, <xref linkend="app-psql"/>
|
2010-04-03 09:23:02 +02:00
|
|
|
contains a command
|
2005-12-18 03:17:16 +01:00
|
|
|
<command>\password</command> that can be used to safely change the
|
|
|
|
password later.
|
|
|
|
</para>
|
2005-07-27 01:24:02 +02:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Create a role that can log in, but don't give it a password:
|
|
|
|
<programlisting>
|
|
|
|
CREATE ROLE jonathan LOGIN;
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Create a role with a password:
|
|
|
|
<programlisting>
|
|
|
|
CREATE USER davide WITH PASSWORD 'jw8s0F4';
|
|
|
|
</programlisting>
|
2017-10-09 03:44:17 +02:00
|
|
|
(<command>CREATE USER</command> is the same as <command>CREATE ROLE</command> except
|
|
|
|
that it implies <literal>LOGIN</literal>.)
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Create a role with a password that is valid until the end of 2004.
|
|
|
|
After one second has ticked in 2005, the password is no longer
|
|
|
|
valid.
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
<para>
|
2005-07-27 01:24:02 +02:00
|
|
|
Create a role that can create databases and manage roles:
|
|
|
|
<programlisting>
|
|
|
|
CREATE ROLE admin WITH CREATEDB CREATEROLE;
|
2011-08-07 09:49:45 +02:00
|
|
|
</programlisting></para>
|
2005-07-27 01:24:02 +02:00
|
|
|
</refsect1>
|
2010-11-23 21:27:50 +01:00
|
|
|
|
2005-07-27 01:24:02 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Compatibility</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <command>CREATE ROLE</command> statement is in the SQL standard,
|
|
|
|
but the standard only requires the syntax
|
|
|
|
<synopsis>
|
2017-10-09 03:44:17 +02:00
|
|
|
CREATE ROLE <replaceable class="parameter">name</replaceable> [ WITH ADMIN <replaceable class="parameter">role_name</replaceable> ]
|
2005-07-27 01:24:02 +02:00
|
|
|
</synopsis>
|
|
|
|
Multiple initial administrators, and all the other options of
|
|
|
|
<command>CREATE ROLE</command>, are
|
|
|
|
<productname>PostgreSQL</productname> extensions.
|
|
|
|
</para>
|
2010-11-23 21:27:50 +01:00
|
|
|
|
2005-07-27 01:24:02 +02:00
|
|
|
<para>
|
|
|
|
The SQL standard defines the concepts of users and roles, but it
|
|
|
|
regards them as distinct concepts and leaves all commands defining
|
|
|
|
users to be specified by each database implementation. In
|
|
|
|
<productname>PostgreSQL</productname> we have chosen to unify
|
|
|
|
users and roles into a single kind of entity. Roles therefore
|
|
|
|
have many more optional attributes than they do in the standard.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The behavior specified by the SQL standard is most closely approximated
|
2024-02-01 12:11:53 +01:00
|
|
|
creating SQL-standard users as <productname>PostgreSQL</productname>
|
|
|
|
roles with the <literal>NOINHERIT</literal> option, and SQL-standard
|
|
|
|
roles as <productname>PostgreSQL</productname> roles with the
|
|
|
|
<literal>INHERIT</literal> option.
|
2005-07-27 01:24:02 +02:00
|
|
|
</para>
|
2023-10-10 22:44:02 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
The <literal>USER</literal> clause has the same behavior as
|
|
|
|
<literal>ROLE</literal> but has been deprecated:
|
|
|
|
<synopsis>
|
|
|
|
USER <replaceable class="parameter">role_name</replaceable> [, ...]
|
|
|
|
</synopsis>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <literal>IN GROUP</literal> clause has the same behavior as <literal>IN
|
|
|
|
ROLE</literal> but has been deprecated:
|
|
|
|
<synopsis>
|
|
|
|
IN GROUP <replaceable class="parameter">role_name</replaceable> [, ...]
|
|
|
|
</synopsis>
|
|
|
|
</para>
|
2005-07-27 01:24:02 +02:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>See Also</title>
|
|
|
|
|
|
|
|
<simplelist type="inline">
|
2017-11-23 15:39:47 +01:00
|
|
|
<member><xref linkend="sql-set-role"/></member>
|
|
|
|
<member><xref linkend="sql-alterrole"/></member>
|
|
|
|
<member><xref linkend="sql-droprole"/></member>
|
|
|
|
<member><xref linkend="sql-grant"/></member>
|
|
|
|
<member><xref linkend="sql-revoke"/></member>
|
|
|
|
<member><xref linkend="app-createuser"/></member>
|
2023-01-10 18:44:49 +01:00
|
|
|
<member><xref linkend="guc-createrole-self-grant"/></member>
|
2005-07-27 01:24:02 +02:00
|
|
|
</simplelist>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|