From: Shinya Kato <Shinya11.Kato@oss.nttdata.com>
To: Daniel Gustafsson <daniel@yesql.se>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Add --{no-,}bypassrls flags to createuser
Date: Fri, 15 Apr 2022 14:55:48 +0900
Message-ID: <850d0579cdad54a37fd777d6b11421ec@oss.nttdata.com> (raw)
In-Reply-To: <25D72E41-9ED2-4EED-B18E-E7979E031DDB@yesql.se>
References: <69a9851035cf0f0477bcc5d742b031a3@oss.nttdata.com>
<20220413.154625.2001259434473326066.horikyota.ntt@gmail.com>
<YlZ3SWm36Nho+xAI@paquier.xyz>
<20220413.173502.518232247235383609.horikyota.ntt@gmail.com>
<bf6a11c8844b90118d254003a4d48911@oss.nttdata.com>
<25D72E41-9ED2-4EED-B18E-E7979E031DDB@yesql.se>
On 2022-04-14 18:57, Daniel Gustafsson wrote:
>> On 14 Apr 2022, at 09:42, Shinya Kato <Shinya11.Kato@oss.nttdata.com>
>> wrote:
>
>> To add the ROLE clause, the originally existing --role option
>> (corresponding to the IN ROLE clause) is changed to the --in-role
>> option. Would this not be good from a backward compatibility
>> standpoint?
>
> - printf(_(" -g, --role=ROLE new role will be a member of
> this role\n"));
> + printf(_(" -g, --in-role=ROLE new role will be a member of
> this role\n"));
> + printf(_(" -G, --role=ROLE this role will be a member of
> new role\n"));
>
> Won't this make existing scripts to behave differently after an
> upgrade? That
> seems like something we should avoid at all costs.
I understand. For backward compatibility, I left the ROLE clause option
as it is and changed the IN ROLE clause option to --membership option.
--
Regards,
--
Shinya Kato
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Attachments:
[text/x-diff] v3-add-bypassrls-flag-to-createuser.patch (9.1K, ../850d0579cdad54a37fd777d6b11421ec@oss.nttdata.com/2-v3-add-bypassrls-flag-to-createuser.patch)
download | inline diff:diff --git a/doc/src/sgml/ref/createuser.sgml b/doc/src/sgml/ref/createuser.sgmlindex 17579e50af..20c60092c0 100644--- a/doc/src/sgml/ref/createuser.sgml+++ b/doc/src/sgml/ref/createuser.sgml@@ -76,6 +76,20 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>+ <term><option>-a <replaceable class="parameter">role</replaceable></option></term>+ <term><option>--admin=<replaceable class="parameter">role</replaceable></option></term>+ <listitem>+ <para>+ The new role will be added immediately as a member with admin option+ of this role.+ Multiple roles to which new role will be added as a member with admin+ option can be specified by writing multiple+ <option>-a</option> switches.+ </para>+ </listitem>+ </varlistentry>+
<varlistentry>
<term><option>-c <replaceable class="parameter">number</replaceable></option></term>
<term><option>--connection-limit=<replaceable class="parameter">number</replaceable></option></term>
@@ -204,6 +218,19 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>+ <term><option>-m <replaceable class="parameter">role</replaceable></option></term>+ <term><option>--membership=<replaceable class="parameter">role</replaceable></option></term>+ <listitem>+ <para>+ The new role will be added immediately as a member of this role.+ Multiple roles to which new role will be added as a member+ can be specified by writing multiple+ <option>-m</option> switches.+ </para>+ </listitem>+ </varlistentry>+
<varlistentry>
<term><option>-P</option></term>
<term><option>--pwprompt</option></term>
@@ -258,6 +285,17 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>+ <term><option>-v <replaceable class="parameter">timestamp</replaceable></option></term>+ <term><option>--valid-until=<replaceable class="parameter">timestamp</replaceable></option></term>+ <listitem>+ <para>+ Set a timestamp after which the role's password is no longer valid.+ The default is to set no expiration.+ </para>+ </listitem>+ </varlistentry>+
<varlistentry>
<term><option>-V</option></term>
<term><option>--version</option></term>
@@ -290,6 +328,28 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>+ <term><option>--bypassrls</option></term>+ <listitem>+ <para>+ The new user will have the <literal>BYPASSRLS</literal> privilege,+ which is described more fully in the documentation for <xref+ linkend="sql-createrole"/>.+ </para>+ </listitem>+ </varlistentry>++ <varlistentry>+ <term><option>--no-bypassrls</option></term>+ <listitem>+ <para>+ The new user will not have the <literal>BYPASSRLS</literal>+ privilege, which is described more fully in the documentation for <xref+ linkend="sql-createrole"/>.+ </para>+ </listitem>+ </varlistentry>+
<varlistentry>
<term><option>-?</option></term>
<term><option>--help</option></term>
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.cindex bfba0d09d1..f7ec842cb7 100644--- a/src/bin/scripts/createuser.c+++ b/src/bin/scripts/createuser.c@@ -51,6 +51,11 @@ main(int argc, char *argv[])
{"connection-limit", required_argument, NULL, 'c'},
{"pwprompt", no_argument, NULL, 'P'},
{"encrypted", no_argument, NULL, 'E'},
+ {"bypassrls", no_argument, NULL, 4},+ {"no-bypassrls", no_argument, NULL, 5},+ {"valid-until", required_argument, NULL, 'v'},+ {"membership", required_argument, NULL, 'm'},+ {"admin", required_argument, NULL, 'a'},
{NULL, 0, NULL, 0}
};
@@ -69,6 +74,9 @@ main(int argc, char *argv[])
int conn_limit = -2; /* less than minimum valid value */
bool pwprompt = false;
char *newpassword = NULL;
+ SimpleStringList memberships = {NULL, NULL};+ SimpleStringList admins = {NULL, NULL};+ char *timestamp = NULL;
/* Tri-valued variables. */
enum trivalue createdb = TRI_DEFAULT,
@@ -76,7 +84,8 @@ main(int argc, char *argv[])
createrole = TRI_DEFAULT,
inherit = TRI_DEFAULT,
login = TRI_DEFAULT,
- replication = TRI_DEFAULT;+ replication = TRI_DEFAULT,+ bypassrls = TRI_DEFAULT;
PQExpBufferData sql;
@@ -89,7 +98,7 @@ main(int argc, char *argv[])
handle_help_version_opts(argc, argv, "createuser", help);
- while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSrRiIlLc:PE",+ while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSrRiIlLc:PEv:m:a:",
long_options, &optindex)) != -1)
{
switch (c)
@@ -165,6 +174,21 @@ main(int argc, char *argv[])
case 3:
interactive = true;
break;
+ case 4:+ bypassrls = TRI_YES;+ break;+ case 5:+ bypassrls = TRI_NO;+ break;+ case 'v':+ timestamp = pg_strdup(optarg);+ break;+ case 'm':+ simple_string_list_append(&memberships, optarg);+ break;+ case 'a':+ simple_string_list_append(&admins, optarg);+ break;
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -304,8 +328,14 @@ main(int argc, char *argv[])
appendPQExpBufferStr(&sql, " REPLICATION");
if (replication == TRI_NO)
appendPQExpBufferStr(&sql, " NOREPLICATION");
+ if (bypassrls == TRI_YES)+ appendPQExpBufferStr(&sql, " BYPASSRLS");+ if (bypassrls == TRI_NO)+ appendPQExpBufferStr(&sql, " NOBYPASSRLS");
if (conn_limit >= -1)
appendPQExpBuffer(&sql, " CONNECTION LIMIT %d", conn_limit);
+ if (timestamp != NULL)+ appendPQExpBuffer(&sql, " VALID UNTIL '%s'", timestamp);
if (roles.head != NULL)
{
SimpleStringListCell *cell;
@@ -320,6 +350,35 @@ main(int argc, char *argv[])
appendPQExpBufferStr(&sql, fmtId(cell->val));
}
}
+ if (memberships.head != NULL)+ {+ SimpleStringListCell *cell;++ appendPQExpBufferStr(&sql, " ROLE ");++ for (cell = memberships.head; cell; cell = cell->next)+ {+ if (cell->next)+ appendPQExpBuffer(&sql, "%s,", fmtId(cell->val));+ else+ appendPQExpBufferStr(&sql, fmtId(cell->val));+ }+ }+ if (admins.head != NULL)+ {+ SimpleStringListCell *cell;++ appendPQExpBufferStr(&sql, " ADMIN ");++ for (cell = admins.head; cell; cell = cell->next)+ {+ if (cell->next)+ appendPQExpBuffer(&sql, "%s,", fmtId(cell->val));+ else+ appendPQExpBufferStr(&sql, fmtId(cell->val));+ }+ }+
appendPQExpBufferChar(&sql, ';');
if (echo)
@@ -346,26 +405,32 @@ help(const char *progname)
printf(_("Usage:\n"));
printf(_(" %s [OPTION]... [ROLENAME]\n"), progname);
printf(_("\nOptions:\n"));
+ printf(_(" -a, --admin=ROLE this role will be a member of new role\n"+ " with admin option\n"));
printf(_(" -c, --connection-limit=N connection limit for role (default: no limit)\n"));
printf(_(" -d, --createdb role can create new databases\n"));
printf(_(" -D, --no-createdb role cannot create databases (default)\n"));
printf(_(" -e, --echo show the commands being sent to the server\n"));
- printf(_(" -g, --role=ROLE new role will be a member of this role\n"));+ printf(_(" -g, --role=ROLE new role will be a member of this role\n"));
printf(_(" -i, --inherit role inherits privileges of roles it is a\n"
" member of (default)\n"));
printf(_(" -I, --no-inherit role does not inherit privileges\n"));
printf(_(" -l, --login role can login (default)\n"));
printf(_(" -L, --no-login role cannot login\n"));
+ printf(_(" -m, --membership=ROLE this role will be a member of new role\n"));
printf(_(" -P, --pwprompt assign a password to new role\n"));
printf(_(" -r, --createrole role can create new roles\n"));
printf(_(" -R, --no-createrole role cannot create roles (default)\n"));
printf(_(" -s, --superuser role will be superuser\n"));
printf(_(" -S, --no-superuser role will not be superuser (default)\n"));
+ printf(_(" -v, --valid-until password expiration timestamp for role\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" --interactive prompt for missing role name and attributes rather\n"
" than using defaults\n"));
printf(_(" --replication role can initiate replication\n"));
printf(_(" --no-replication role cannot initiate replication\n"));
+ printf(_(" --bypassrls role can bypass row-level security (RLS) policy\n"));+ printf(_(" --no-bypassrls role cannot bypass row-level security (RLS) policy\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: Shinya11.Kato@oss.nttdata.com, daniel@yesql.se, horikyota.ntt@gmail.com, robertmhaas@gmail.com, michael@paquier.xyz
Subject: Re: Add --{no-,}bypassrls flags to createuser
In-Reply-To: <850d0579cdad54a37fd777d6b11421ec@oss.nttdata.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox