From: Shinya Kato <Shinya11.Kato@oss.nttdata.com>
To: Przemysław Sztoch <przemyslaw@sztoch.pl>
Cc: Nathan Bossart <nathandbossart@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: Daniel Gustafsson <daniel@yesql.se>
Cc: pgsql-hackers@postgresql.org
Subject: Re: Add --{no-,}bypassrls flags to createuser
Date: Thu, 19 May 2022 10:35:23 +0900
Message-ID: <4975ec63b73cfe4034867e90edbe16f8@oss.nttdata.com> (raw)
In-Reply-To: <a720383d-9bf2-fcb7-22fa-aeea114c86a5@sztoch.pl>
References: <850d0579cdad54a37fd777d6b11421ec@oss.nttdata.com>
<20220415.153341.594036939490942414.horikyota.ntt@gmail.com>
<CA+TgmoYO090Xkwp--vCo0FGrFZBTG=V7wE3EF5WEAPcrFTpbSg@mail.gmail.com>
<20220419.105012.1677795152077894444.horikyota.ntt@gmail.com>
<CA+TgmoaTNwzZ6LXgaMzB03J6iijAPqSys39xHd7e6Fwb__3V1g@mail.gmail.com>
<YmDdxXPVNR8Km0v/@paquier.xyz>
<CA+TgmoYeZg5deFv+r-dDvWQLuSOiTNAUbcsx4kY2XhGSeGz7FA@mail.gmail.com>
<CAKFQuwa7kaFmEMszAAkpy-RiYZjW4M3MGo4-EidExZbOAgwQkg@mail.gmail.com>
<20220425201947.GA2935432@nathanxps13>
<d2d771c6cf1ed0f59513eb01c0cc0c78@oss.nttdata.com>
<a720383d-9bf2-fcb7-22fa-aeea114c86a5@sztoch.pl>
Thanks for reviews and comments!
On 2022-05-06 07:08, Przemysław Sztoch wrote:
> Thanks for the new patch! Would you mind adding some tests for the new
> options?
I created a new patch to test the new options!
However, not all option tests exist, so it may be necessary to consider
whether to actually add this test.
> Too bad there's no --comment parameter to do COMMENT ON ROLE name IS
> 'Comment';
>
> As you already make such changes in createuser, I would like to ask
> for an additional --comment parameter
> that will allow sysadmins to set a comment with additional information
> about the new DB user.
> psql is scary for some. :-)
Since the createuser command is a wrapper for the CREATE ROLE command, I
do not think it is appropriate to add options that the CREATE ROLE
command does not have.
--
Regards,
--
Shinya Kato
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Attachments:
[text/x-diff] v5-add-bypassrls-flag-to-createuser.patch (10.1K, ../4975ec63b73cfe4034867e90edbe16f8@oss.nttdata.com/2-v5-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..189ca5bb67 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>--member=<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..73cd1b479e 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'},+ {"member", 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 members = {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(&members, 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 (members.head != NULL)+ {+ SimpleStringListCell *cell;++ appendPQExpBufferStr(&sql, " ROLE ");++ for (cell = members.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,6 +405,8 @@ 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"));
@@ -356,16 +417,20 @@ help(const char *progname)
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, --member=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"));
diff --git a/src/bin/scripts/t/040_createuser.pl b/src/bin/scripts/t/040_createuser.plindex 2a34be81cf..5df5134a26 100644--- a/src/bin/scripts/t/040_createuser.pl+++ b/src/bin/scripts/t/040_createuser.pl@@ -32,6 +32,22 @@ $node->issues_sql_like(
[ 'createuser', '-s', 'regress_user3' ],
qr/statement: CREATE ROLE regress_user3 SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;/,
'create a superuser');
+$node->issues_sql_like(+ [ 'createuser', 'regress_role2', '-a', 'regress_user1' ],+ qr/statement: CREATE ROLE regress_role2 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN ADMIN regress_user1;/,+ 'create a role and add it to another user with admin option');+$node->issues_sql_like(+ [ 'createuser', 'regress_role3', '-m', 'regress_user1' ],+ qr/statement: CREATE ROLE regress_role3 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN ROLE regress_user1;/,+ 'create a role and add it to another user');+$node->issues_sql_like(+ [ 'createuser', 'regress_user4', '-v', '20291231' ],+ qr/statement: CREATE ROLE regress_user4 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN VALID UNTIL \'20291231\';/,+ 'create a user with a password expiration timestamp');+$node->issues_sql_like(+ [ 'createuser', 'regress_user5', '--bypassrls' ],+ qr/statement: CREATE ROLE regress_user5 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN BYPASSRLS;/,+ 'create a BYPASSRLS user');
$node->command_fails([ 'createuser', 'regress_user1' ],
'fails if role already exists');
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, przemyslaw@sztoch.pl, nathandbossart@gmail.com, david.g.johnston@gmail.com, robertmhaas@gmail.com, michael@paquier.xyz, horikyota.ntt@gmail.com, daniel@yesql.se
Subject: Re: Add --{no-,}bypassrls flags to createuser
In-Reply-To: <4975ec63b73cfe4034867e90edbe16f8@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