pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH v2] use has_privs_for_role for predefined roles
42+ messages / 7 participants
[nested] [flat]

Commits from this thread:
  2022-03-30 26a0c025e2  Document basebackup_to_shell.required_role.
* [PATCH v2] use has_privs_for_role for predefined roles
@ 2021-10-27 21:13 Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joshua Brindle @ 2021-10-27 21:13 UTC (permalink / raw)
  To: pgsql-hackers; +Cc: Joshua Brindle <joshua.brindle@crunchydata.com>

Attached is an updated version of the patch to replace
is_member_of_role with has_privs_for_role for predefined roles. It
does not remove is_member_of_role from acl.h but it does add a warning
not to use that function for privilege checking.

Please consider this for the upcoming commitfest.

Attachments:

0001-use-has_privs_for_roles-for-predefined-role-checks.patch (application/octet-stream, 18.5K) download From 05ad7d8dd2217392fe74ebd1dbaca2410b2dc241 Mon Sep 17 00:00:00 2001 From: Joshua Brindle <joshua.brindle@crunchydata.com> Date: Tue, 26 Oct 2021 14:19:44 -0700 Subject: [PATCH] use has_privs_for_roles for predefined role checks Generally if a role is granted membership to another role with NOINHERIT they must use SET ROLE to access the privileges of that role, however with predefined roles the membership and privilege is conflated, as demonstrated by: CREATE ROLE readrole; CREATE ROLE role2 NOINHERIT; CREATE ROLE brindle LOGIN; GRANT role2 TO brindle; CREATE TABLE foo(i INT); GRANT readrole TO role2; GRANT ALL ON TABLE foo TO readrole; GRANT pg_read_all_stats,pg_read_all_settings,pg_read_server_files,pg_write_server_files,pg_execute_server_program TO role2; Log in as brindle: postgres=> select current_user; current_user -------------- brindle (1 row) postgres=> SELECT * FROM foo; ERROR: permission denied for table foo postgres=> SELECT DISTINCT query FROM pg_stat_activity; query ---------------------------------------------- SELECT DISTINCT query FROM pg_stat_activity; (2 rows) postgres=> SET ROLE readrole; SET postgres=> SELECT * FROM foo; i --- (0 rows) After this patch: postgres=> SELECT DISTINCT query FROM pg_stat_activity; query -------------------------- <insufficient privilege> (1 row) postgres=> SET ROLE pg_read_all_stats; SET postgres=> SELECT DISTINCT query FROM pg_stat_activity; query ---------------------------------------------- SELECT DISTINCT query FROM pg_stat_activity; (2 rows) postgres=> SHOW config_file; ERROR: must be superuser or have privileges of pg_read_all_settings to examine "config_file" postgres=> SET ROLE pg_read_all_settings; SET postgres=> SHOW config_file; config_file ----------------------------------- /var/lib/pgsql/15/postgresql.conf (1 row) With inheritance it works as expected: ALTER ROLE role2 INHERIT; postgres=> SELECT current_user; current_user -------------- brindle (1 row) postgres=> SHOW config_file; config_file ----------------------------------- /var/lib/pgsql/15/postgresql.conf (1 row) Signed-off-by: Joshua Brindle <joshua.brindle@crunchydata.com> --- contrib/adminpack/adminpack.c | 2 +- contrib/file_fdw/file_fdw.c | 8 ++++---- contrib/file_fdw/output/file_fdw.source | 2 +- .../pg_stat_statements/pg_stat_statements.c | 2 +- contrib/pgrowlocks/pgrowlocks.c | 2 +- src/backend/commands/copy.c | 12 +++++------ src/backend/replication/walreceiver.c | 8 ++++---- src/backend/replication/walsender.c | 8 ++++---- src/backend/utils/adt/acl.c | 4 ++++ src/backend/utils/adt/dbsize.c | 8 ++++---- src/backend/utils/adt/genfile.c | 6 +++--- src/backend/utils/adt/pgstatfuncs.c | 2 +- src/backend/utils/misc/guc.c | 20 +++++++++---------- .../unsafe_tests/expected/rolenames.out | 2 +- 14 files changed, 45 insertions(+), 41 deletions(-) diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c index 48c17469104..0457d7b591d 100644 --- a/contrib/adminpack/adminpack.c +++ b/contrib/adminpack/adminpack.c @@ -79,7 +79,7 @@ convert_and_check_filename(text *arg) * files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) return filename; /* diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 2c2f149fb01..a769b2ef7b9 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -269,16 +269,16 @@ file_fdw_validator(PG_FUNCTION_ARGS) * otherwise there'd still be a security hole. */ if (strcmp(def->defname, "filename") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); if (strcmp(def->defname, "program") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + !has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); filename = defGetString(def); } diff --git a/contrib/file_fdw/output/file_fdw.source b/contrib/file_fdw/output/file_fdw.source index 52b4d5f1df7..a1d44ed665a 100644 --- a/contrib/file_fdw/output/file_fdw.source +++ b/contrib/file_fdw/output/file_fdw.source @@ -436,7 +436,7 @@ ALTER FOREIGN TABLE agg_text OWNER TO regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); SET ROLE regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); -ERROR: only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table +ERROR: only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table SET ROLE regress_file_fdw_superuser; -- cleanup RESET ROLE; diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 07fe0e7cdad..b2a4f056478 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1512,7 +1512,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, pgssEntry *entry; /* Superusers or members of pg_read_all_stats members are allowed */ - is_allowed_role = is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); + is_allowed_role = has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); /* hash table must exist already */ if (!pgss || !pgss_hash) diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index 669a7d7730b..b9b724a554d 100644 --- a/contrib/pgrowlocks/pgrowlocks.c +++ b/contrib/pgrowlocks/pgrowlocks.c @@ -130,7 +130,7 @@ pgrowlocks(PG_FUNCTION_ARGS) aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), ACL_SELECT); if (aclresult != ACLCHECK_OK) - aclresult = is_member_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; + aclresult = has_privs_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 53f48531419..e26ff42fd82 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -80,26 +80,26 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, { if (stmt->is_program) { - if (!is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_execute_server_program role to COPY to or from an external program"), + errmsg("must be superuser or have privileges of the pg_execute_server_program role to COPY to or from an external program"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } else { - if (is_from && !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (is_from && !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_read_server_files role to COPY from a file"), + errmsg("must be superuser or have privileges of the pg_read_server_files role to COPY from a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); - if (!is_from && !is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (!is_from && !has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_write_server_files role to COPY to a file"), + errmsg("must be superuser or have privileges of the pg_write_server_files role to COPY to a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index b90e5ca98ea..c8ddb6fc323 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1392,12 +1392,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) /* Fetch values */ values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see details. - * Other users only get the pid value to know whether it is a WAL - * receiver, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know whether + * it is a WAL receiver, but no details. */ MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index d9ab6d6de24..4daf1581bc6 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -3486,12 +3486,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) memset(nulls, 0, sizeof(nulls)); values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see - * details. Other users only get the pid value to know it's a - * walsender, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know + * it's a walsender, but no details. */ MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1); } diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 67f8b29434a..e2ce4582f19 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -4864,6 +4864,8 @@ has_privs_of_role(Oid member, Oid role) * Is member a member of role (directly or indirectly)? * * This is defined to recurse through roles regardless of rolinherit. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role(Oid member, Oid role) @@ -4904,6 +4906,8 @@ check_is_member_of_role(Oid member, Oid role) * * This is identical to is_member_of_role except we ignore superuser * status. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role_nosuper(Oid member, Oid role) diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index d5a7fb13f3c..91ec2615cd5 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -112,12 +112,12 @@ calculate_database_size(Oid dbOid) AclResult aclresult; /* - * User must have connect privilege for target database or be a member of + * User must have connect privilege for target database or have privileges of * pg_read_all_stats */ aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT); if (aclresult != ACLCHECK_OK && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclcheck_error(aclresult, OBJECT_DATABASE, get_database_name(dbOid)); @@ -196,12 +196,12 @@ calculate_tablespace_size(Oid tblspcOid) AclResult aclresult; /* - * User must be a member of pg_read_all_stats or have CREATE privilege for + * User must have privileges of pg_read_all_stats or have CREATE privilege for * target tablespace, either explicitly granted or implicitly because it * is default for current database. */ if (tblspcOid != MyDatabaseTableSpace && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE); if (aclresult != ACLCHECK_OK) diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index c436d9318b6..f87f77093a6 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -58,11 +58,11 @@ convert_and_check_filename(text *arg) canonicalize_path(filename); /* filename can change length here */ /* - * Members of the 'pg_read_server_files' role are allowed to access any - * files on the server as the PG user, so no need to do any further checks + * Roles with privleges of the 'pg_read_server_files' role are allowed to access + * any files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) return filename; /* diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index ff5aedc99cb..56762a7d98d 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -34,7 +34,7 @@ #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) -#define HAS_PGSTAT_PERMISSIONS(role) (is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) +#define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index e91d5a3cfda..e400bfdea13 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -8154,10 +8154,10 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged) return NULL; if (restrict_privileged && (record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -8201,10 +8201,10 @@ GetConfigOptionResetString(const char *name) record = find_option(name, false, false, ERROR); Assert(record != NULL); if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -9448,7 +9448,7 @@ ShowAllGUCConfig(DestReceiver *dest) if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* assign to the values array */ @@ -9515,7 +9515,7 @@ get_explain_guc_options(int *num) /* return only options visible to the current user */ if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* return only options that are different from their boot values */ @@ -9597,10 +9597,10 @@ GetConfigOptionByName(const char *name, const char **varname, bool missing_ok) } if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); if (varname) @@ -9628,7 +9628,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) { if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) *noshow = true; else *noshow = false; @@ -9823,7 +9823,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) * insufficiently-privileged users. */ if (conf->source == PGC_S_FILE && - is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) { values[14] = conf->sourcefile; snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); diff --git a/src/test/modules/unsafe_tests/expected/rolenames.out b/src/test/modules/unsafe_tests/expected/rolenames.out index eb608fdc2ea..88b1ff843be 100644 --- a/src/test/modules/unsafe_tests/expected/rolenames.out +++ b/src/test/modules/unsafe_tests/expected/rolenames.out @@ -1077,7 +1077,7 @@ SHOW session_preload_libraries; SET SESSION AUTHORIZATION regress_role_nopriv; -- fails with role not member of pg_read_all_settings SHOW session_preload_libraries; -ERROR: must be superuser or a member of pg_read_all_settings to examine "session_preload_libraries" +ERROR: must be superuser or have privileges of pg_read_all_settings to examine "session_preload_libraries" RESET SESSION AUTHORIZATION; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- 2.31.1
^ permalink raw reply [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2021-10-27 21:16 ` Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Robert Haas @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: pgsql-hackers

On Wed, Oct 27, 2021 at 5:14 PM Joshua Brindle
<joshua.brindle@crunchydata.com> wrote:
> Attached is an updated version of the patch to replace
> is_member_of_role with has_privs_for_role for predefined roles. It
> does not remove is_member_of_role from acl.h but it does add a warning
> not to use that function for privilege checking.
>
> Please consider this for the upcoming commitfest.

I am not sure I understand what the advantage of this is supposed to be.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2021-10-27 21:20   ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joshua Brindle @ 2021-10-27 21:20 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers

On Wed, Oct 27, 2021 at 5:16 PM Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Wed, Oct 27, 2021 at 5:14 PM Joshua Brindle
> <joshua.brindle@crunchydata.com> wrote:
> > Attached is an updated version of the patch to replace
> > is_member_of_role with has_privs_for_role for predefined roles. It
> > does not remove is_member_of_role from acl.h but it does add a warning
> > not to use that function for privilege checking.
> >
> > Please consider this for the upcoming commitfest.
>
> I am not sure I understand what the advantage of this is supposed to be.

Pre-defined roles currently do not operate the same way other roles do
with respect to inheritance. The patchfile has an explanation and
examples, I wasn't sure if that needed to be repeated in the email or
not.





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2021-10-27 21:35     ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:38       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  0 siblings, 2 replies; 42+ messages in thread

From: Joshua Brindle @ 2021-10-27 21:35 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers

On Wed, Oct 27, 2021 at 5:20 PM Joshua Brindle
<joshua.brindle@crunchydata.com> wrote:
>
> On Wed, Oct 27, 2021 at 5:16 PM Robert Haas <robertmhaas@gmail.com> wrote:
> >
> > On Wed, Oct 27, 2021 at 5:14 PM Joshua Brindle
> > <joshua.brindle@crunchydata.com> wrote:
> > > Attached is an updated version of the patch to replace
> > > is_member_of_role with has_privs_for_role for predefined roles. It
> > > does not remove is_member_of_role from acl.h but it does add a warning
> > > not to use that function for privilege checking.
> > >
> > > Please consider this for the upcoming commitfest.
> >
> > I am not sure I understand what the advantage of this is supposed to be.
>
> Pre-defined roles currently do not operate the same way other roles do
> with respect to inheritance. The patchfile has an explanation and
> examples, I wasn't sure if that needed to be repeated in the email or
> not.

And FWIW several predefined role patches on the list currently
correctly use has_privs_for_role rather than is_memver_of_role so this
brings the older roles to be consistent with the newer ones being
proposed.





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2021-10-27 21:38       ` Bossart, Nathan <bossartn@amazon.com>
  1 sibling, 0 replies; 42+ messages in thread

From: Bossart, Nathan @ 2021-10-27 21:38 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers

On 10/27/21, 2:19 PM, "Robert Haas" <robertmhaas@gmail.com> wrote:
> I am not sure I understand what the advantage of this is supposed to be.

There are a couple of other related threads with some additional
context:

        https://www.postgresql.org/message-id/flat/20211026224731.115337-1-joshua.brindle%40crunchydata.com
        https://www.postgresql.org/message-id/flat/CAGB%2BVh4enxvLBM_BJweWEO12Q0ySLMBWK9iOLaM7e%3DV1Y0YadA%4...

Nathan



^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2021-11-08 20:44       ` Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  1 sibling, 1 reply; 42+ messages in thread

From: Stephen Frost @ 2021-11-08 20:44 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

Greetings,

* Joshua Brindle (joshua.brindle@crunchydata.com) wrote:
> On Wed, Oct 27, 2021 at 5:20 PM Joshua Brindle <joshua.brindle@crunchydata.com> wrote:
> > On Wed, Oct 27, 2021 at 5:16 PM Robert Haas <robertmhaas@gmail.com> wrote:
> > > On Wed, Oct 27, 2021 at 5:14 PM Joshua Brindle
> > > <joshua.brindle@crunchydata.com> wrote:
> > > > Attached is an updated version of the patch to replace
> > > > is_member_of_role with has_privs_for_role for predefined roles. It
> > > > does not remove is_member_of_role from acl.h but it does add a warning
> > > > not to use that function for privilege checking.
> > > >
> > > > Please consider this for the upcoming commitfest.
> > >
> > > I am not sure I understand what the advantage of this is supposed to be.
> >
> > Pre-defined roles currently do not operate the same way other roles do
> > with respect to inheritance. The patchfile has an explanation and
> > examples, I wasn't sure if that needed to be repeated in the email or
> > not.
> 
> And FWIW several predefined role patches on the list currently
> correctly use has_privs_for_role rather than is_memver_of_role so this
> brings the older roles to be consistent with the newer ones being
> proposed.

Right, we really should be consistent here and we're not and that's not
a good thing.  Further, if you're logged in as an unprivileged role and
expect to not see things that you shouldn't, then it's not good for that
to end up happening because you've been GRANT'd a more privileged, but
noinherit, role that was given some predefined roles.  This doesn't end
up being an actual security issue as you could just SET ROLE to that
more privileged role, so it's not that you couldn't see that data, just
that you should have had to SET ROLE to do so.

Reviewing the actual patch, it generally looks good to me except that
you missed updating this comment:

Superusers or members of pg_read_all_stats members are allowed

Thanks,

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
@ 2021-11-08 22:15         ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joshua Brindle @ 2021-11-08 22:15 UTC (permalink / raw)
  To: Stephen Frost <sfrost@snowman.net>; +Cc: Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

On Mon, Nov 8, 2021 at 3:44 PM Stephen Frost <sfrost@snowman.net> wrote:
>
> Greetings,
>
> * Joshua Brindle (joshua.brindle@crunchydata.com) wrote:
> > On Wed, Oct 27, 2021 at 5:20 PM Joshua Brindle <joshua.brindle@crunchydata.com> wrote:
> > > On Wed, Oct 27, 2021 at 5:16 PM Robert Haas <robertmhaas@gmail.com> wrote:
> > > > On Wed, Oct 27, 2021 at 5:14 PM Joshua Brindle
> > > > <joshua.brindle@crunchydata.com> wrote:
> > > > > Attached is an updated version of the patch to replace
> > > > > is_member_of_role with has_privs_for_role for predefined roles. It
> > > > > does not remove is_member_of_role from acl.h but it does add a warning
> > > > > not to use that function for privilege checking.
> > > > >
> > > > > Please consider this for the upcoming commitfest.
> > > >
> > > > I am not sure I understand what the advantage of this is supposed to be.
> > >
> > > Pre-defined roles currently do not operate the same way other roles do
> > > with respect to inheritance. The patchfile has an explanation and
> > > examples, I wasn't sure if that needed to be repeated in the email or
> > > not.
> >
> > And FWIW several predefined role patches on the list currently
> > correctly use has_privs_for_role rather than is_memver_of_role so this
> > brings the older roles to be consistent with the newer ones being
> > proposed.
>
> Right, we really should be consistent here and we're not and that's not
> a good thing.  Further, if you're logged in as an unprivileged role and
> expect to not see things that you shouldn't, then it's not good for that
> to end up happening because you've been GRANT'd a more privileged, but
> noinherit, role that was given some predefined roles.  This doesn't end
> up being an actual security issue as you could just SET ROLE to that
> more privileged role, so it's not that you couldn't see that data, just
> that you should have had to SET ROLE to do so.
>
> Reviewing the actual patch, it generally looks good to me except that
> you missed updating this comment:
>
> Superusers or members of pg_read_all_stats members are allowed

Thanks for the review, attached is an update with that comment fixed
and also sgml documentation changes that I missed earlier.

Attachments:

0001-use-has_privs_for_roles-for-predefined-role-checks.patch (application/octet-stream, 19.7K) download From b0b1effeaaab81db65857d792a343c0079f87c79 Mon Sep 17 00:00:00 2001 From: Joshua Brindle <joshua.brindle@crunchydata.com> Date: Tue, 26 Oct 2021 14:19:44 -0700 Subject: [PATCH] use has_privs_for_roles for predefined role checks Generally if a role is granted membership to another role with NOINHERIT they must use SET ROLE to access the privileges of that role, however with predefined roles the membership and privilege is conflated, as demonstrated by: CREATE ROLE readrole; CREATE ROLE role2 NOINHERIT; CREATE ROLE brindle LOGIN; GRANT role2 TO brindle; CREATE TABLE foo(i INT); GRANT readrole TO role2; GRANT ALL ON TABLE foo TO readrole; GRANT pg_read_all_stats,pg_read_all_settings,pg_read_server_files,pg_write_server_files,pg_execute_server_program TO role2; Log in as brindle: postgres=> select current_user; current_user -------------- brindle (1 row) postgres=> SELECT * FROM foo; ERROR: permission denied for table foo postgres=> SELECT DISTINCT query FROM pg_stat_activity; query ---------------------------------------------- SELECT DISTINCT query FROM pg_stat_activity; (2 rows) postgres=> SET ROLE readrole; SET postgres=> SELECT * FROM foo; i Signed-off-by: Joshua Brindle <joshua.brindle@crunchydata.com> --- contrib/adminpack/adminpack.c | 2 +- contrib/file_fdw/file_fdw.c | 8 ++++---- contrib/file_fdw/output/file_fdw.source | 2 +- .../pg_stat_statements/pg_stat_statements.c | 4 ++-- contrib/pgrowlocks/pgrowlocks.c | 2 +- doc/src/sgml/catalogs.sgml | 12 +++++------ src/backend/commands/copy.c | 12 +++++------ src/backend/replication/walreceiver.c | 8 ++++---- src/backend/replication/walsender.c | 8 ++++---- src/backend/utils/adt/acl.c | 4 ++++ src/backend/utils/adt/dbsize.c | 8 ++++---- src/backend/utils/adt/genfile.c | 6 +++--- src/backend/utils/adt/pgstatfuncs.c | 2 +- src/backend/utils/misc/guc.c | 20 +++++++++---------- .../unsafe_tests/expected/rolenames.out | 2 +- 15 files changed, 52 insertions(+), 48 deletions(-) diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c index 48c17469104..0457d7b591d 100644 --- a/contrib/adminpack/adminpack.c +++ b/contrib/adminpack/adminpack.c @@ -79,7 +79,7 @@ convert_and_check_filename(text *arg) * files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) return filename; /* diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 2c2f149fb01..a769b2ef7b9 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -269,16 +269,16 @@ file_fdw_validator(PG_FUNCTION_ARGS) * otherwise there'd still be a security hole. */ if (strcmp(def->defname, "filename") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); if (strcmp(def->defname, "program") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + !has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); filename = defGetString(def); } diff --git a/contrib/file_fdw/output/file_fdw.source b/contrib/file_fdw/output/file_fdw.source index 52b4d5f1df7..a1d44ed665a 100644 --- a/contrib/file_fdw/output/file_fdw.source +++ b/contrib/file_fdw/output/file_fdw.source @@ -436,7 +436,7 @@ ALTER FOREIGN TABLE agg_text OWNER TO regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); SET ROLE regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); -ERROR: only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table +ERROR: only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table SET ROLE regress_file_fdw_superuser; -- cleanup RESET ROLE; diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 726ba59e2bf..f6120f5c48b 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1511,8 +1511,8 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, HASH_SEQ_STATUS hash_seq; pgssEntry *entry; - /* Superusers or members of pg_read_all_stats members are allowed */ - is_allowed_role = is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); + /* Superusers or roles with the privileges of pg_read_all_stats members are allowed */ + is_allowed_role = has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); /* hash table must exist already */ if (!pgss || !pgss_hash) diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index 669a7d7730b..b9b724a554d 100644 --- a/contrib/pgrowlocks/pgrowlocks.c +++ b/contrib/pgrowlocks/pgrowlocks.c @@ -130,7 +130,7 @@ pgrowlocks(PG_FUNCTION_ARGS) aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), ACL_SELECT); if (aclresult != ACLCHECK_OK) - aclresult = is_member_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; + aclresult = has_privs_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index c1d11be73f7..87254c4b8bd 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -9916,8 +9916,8 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l <para> By default, the <structname>pg_backend_memory_contexts</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with the privileges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> @@ -12358,7 +12358,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Configuration file the current value was set in (null for values set from sources other than configuration files, or when - examined by a user who is neither a superuser or a member of + examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>); helpful when using <literal>include</literal> directives in configuration files </para></entry> @@ -12371,7 +12371,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Line number within the configuration file the current value was set at (null for values set from sources other than configuration files, - or when examined by a user who is neither a superuser or a member of + or when examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>). </para></entry> </row> @@ -12747,8 +12747,8 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> By default, the <structname>pg_shmem_allocations</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with privilges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 53f48531419..e26ff42fd82 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -80,26 +80,26 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, { if (stmt->is_program) { - if (!is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_execute_server_program role to COPY to or from an external program"), + errmsg("must be superuser or have privileges of the pg_execute_server_program role to COPY to or from an external program"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } else { - if (is_from && !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (is_from && !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_read_server_files role to COPY from a file"), + errmsg("must be superuser or have privileges of the pg_read_server_files role to COPY from a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); - if (!is_from && !is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (!is_from && !has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_write_server_files role to COPY to a file"), + errmsg("must be superuser or have privileges of the pg_write_server_files role to COPY to a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 7a7eb3784e7..9de72962322 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1402,12 +1402,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) /* Fetch values */ values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see details. - * Other users only get the pid value to know whether it is a WAL - * receiver, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know whether + * it is a WAL receiver, but no details. */ MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index fff7dfc6409..c9b57f2ff36 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -3487,12 +3487,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) memset(nulls, 0, sizeof(nulls)); values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see - * details. Other users only get the pid value to know it's a - * walsender, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know + * it's a walsender, but no details. */ MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1); } diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 67f8b29434a..e2ce4582f19 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -4864,6 +4864,8 @@ has_privs_of_role(Oid member, Oid role) * Is member a member of role (directly or indirectly)? * * This is defined to recurse through roles regardless of rolinherit. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role(Oid member, Oid role) @@ -4904,6 +4906,8 @@ check_is_member_of_role(Oid member, Oid role) * * This is identical to is_member_of_role except we ignore superuser * status. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role_nosuper(Oid member, Oid role) diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index d5a7fb13f3c..91ec2615cd5 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -112,12 +112,12 @@ calculate_database_size(Oid dbOid) AclResult aclresult; /* - * User must have connect privilege for target database or be a member of + * User must have connect privilege for target database or have privileges of * pg_read_all_stats */ aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT); if (aclresult != ACLCHECK_OK && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclcheck_error(aclresult, OBJECT_DATABASE, get_database_name(dbOid)); @@ -196,12 +196,12 @@ calculate_tablespace_size(Oid tblspcOid) AclResult aclresult; /* - * User must be a member of pg_read_all_stats or have CREATE privilege for + * User must have privileges of pg_read_all_stats or have CREATE privilege for * target tablespace, either explicitly granted or implicitly because it * is default for current database. */ if (tblspcOid != MyDatabaseTableSpace && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE); if (aclresult != ACLCHECK_OK) diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index c436d9318b6..f87f77093a6 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -58,11 +58,11 @@ convert_and_check_filename(text *arg) canonicalize_path(filename); /* filename can change length here */ /* - * Members of the 'pg_read_server_files' role are allowed to access any - * files on the server as the PG user, so no need to do any further checks + * Roles with privleges of the 'pg_read_server_files' role are allowed to access + * any files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) return filename; /* diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index ff5aedc99cb..56762a7d98d 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -34,7 +34,7 @@ #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) -#define HAS_PGSTAT_PERMISSIONS(role) (is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) +#define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index e91d5a3cfda..e400bfdea13 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -8154,10 +8154,10 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged) return NULL; if (restrict_privileged && (record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -8201,10 +8201,10 @@ GetConfigOptionResetString(const char *name) record = find_option(name, false, false, ERROR); Assert(record != NULL); if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -9448,7 +9448,7 @@ ShowAllGUCConfig(DestReceiver *dest) if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* assign to the values array */ @@ -9515,7 +9515,7 @@ get_explain_guc_options(int *num) /* return only options visible to the current user */ if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* return only options that are different from their boot values */ @@ -9597,10 +9597,10 @@ GetConfigOptionByName(const char *name, const char **varname, bool missing_ok) } if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); if (varname) @@ -9628,7 +9628,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) { if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) *noshow = true; else *noshow = false; @@ -9823,7 +9823,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) * insufficiently-privileged users. */ if (conf->source == PGC_S_FILE && - is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) { values[14] = conf->sourcefile; snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); diff --git a/src/test/modules/unsafe_tests/expected/rolenames.out b/src/test/modules/unsafe_tests/expected/rolenames.out index eb608fdc2ea..88b1ff843be 100644 --- a/src/test/modules/unsafe_tests/expected/rolenames.out +++ b/src/test/modules/unsafe_tests/expected/rolenames.out @@ -1077,7 +1077,7 @@ SHOW session_preload_libraries; SET SESSION AUTHORIZATION regress_role_nopriv; -- fails with role not member of pg_read_all_settings SHOW session_preload_libraries; -ERROR: must be superuser or a member of pg_read_all_settings to examine "session_preload_libraries" +ERROR: must be superuser or have privileges of pg_read_all_settings to examine "session_preload_libraries" RESET SESSION AUTHORIZATION; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- 2.31.1
^ permalink raw reply [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2021-11-10 17:45           ` Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Bossart, Nathan @ 2021-11-10 17:45 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; Stephen Frost <sfrost@snowman.net>; +Cc: Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

On 11/8/21, 2:19 PM, "Joshua Brindle" <joshua.brindle@crunchydata.com> wrote:
> Thanks for the review, attached is an update with that comment fixed
> and also sgml documentation changes that I missed earlier.

I think there are a number of documentation changes that are still
missing.  I did a quick scan and saw the "is member of" language in
func.sgml, monitoring.sgml, pgbuffercache.sgml, pgfreespacemap.sgml,
pgrowlocks.sgml, pgstatstatements.sgml, and pgvisibility.sgml.

<para>
 By default, the <structname>pg_shmem_allocations</structname> view can be
-   read only by superusers or members of the <literal>pg_read_all_stats</literal>
-   role.
+   read only by superusers or roles with privilges of the
+   <literal>pg_read_all_stats</literal> role.
</para>
</sect1>

nitpick: "privileges" is misspelled.

Nathan



^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
@ 2021-11-12 20:33             ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joshua Brindle @ 2021-11-12 20:33 UTC (permalink / raw)
  To: Bossart, Nathan <bossartn@amazon.com>; +Cc: Stephen Frost <sfrost@snowman.net>; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

On Wed, Nov 10, 2021 at 12:45 PM Bossart, Nathan <bossartn@amazon.com> wrote:
>
> On 11/8/21, 2:19 PM, "Joshua Brindle" <joshua.brindle@crunchydata.com> wrote:
> > Thanks for the review, attached is an update with that comment fixed
> > and also sgml documentation changes that I missed earlier.
>
> I think there are a number of documentation changes that are still
> missing.  I did a quick scan and saw the "is member of" language in
> func.sgml, monitoring.sgml, pgbuffercache.sgml, pgfreespacemap.sgml,
> pgrowlocks.sgml, pgstatstatements.sgml, and pgvisibility.sgml.

All of these and also adminpack.sgml updated. I think that is all of
them but docs broken across lines and irregular wording makes it
difficult.

> <para>
>  By default, the <structname>pg_shmem_allocations</structname> view can be
> -   read only by superusers or members of the <literal>pg_read_all_stats</literal>
> -   role.
> +   read only by superusers or roles with privilges of the
> +   <literal>pg_read_all_stats</literal> role.
> </para>
> </sect1>
>
> nitpick: "privileges" is misspelled.

Fixed, thanks for reviewing.

Attachments:

0001-use-has_privs_for_roles-for-predefined-role-checks.patch (application/octet-stream, 27.7K) download From 752a3dfb0094dc45a7614553f4fcec15aeaa1a6c Mon Sep 17 00:00:00 2001 From: Joshua Brindle <joshua.brindle@crunchydata.com> Date: Tue, 26 Oct 2021 14:19:44 -0700 Subject: [PATCH] use has_privs_for_roles for predefined role checks Generally if a role is granted membership to another role with NOINHERIT they must use SET ROLE to access the privileges of that role, however with predefined roles the membership and privilege is conflated, as demonstrated by: CREATE ROLE readrole; CREATE ROLE role2 NOINHERIT; CREATE ROLE brindle LOGIN; GRANT role2 TO brindle; CREATE TABLE foo(i INT); GRANT readrole TO role2; GRANT ALL ON TABLE foo TO readrole; GRANT pg_read_all_stats,pg_read_all_settings,pg_read_server_files,pg_write_server_files,pg_execute_server_program TO role2; Log in as brindle: postgres=> select current_user; current_user -------------- brindle (1 row) postgres=> SELECT * FROM foo; ERROR: permission denied for table foo postgres=> SELECT DISTINCT query FROM pg_stat_activity; query ---------------------------------------------- SELECT DISTINCT query FROM pg_stat_activity; (2 rows) postgres=> SET ROLE readrole; SET postgres=> SELECT * FROM foo; i Signed-off-by: Joshua Brindle <joshua.brindle@crunchydata.com> --- contrib/adminpack/adminpack.c | 2 +- contrib/file_fdw/file_fdw.c | 8 ++++---- contrib/file_fdw/output/file_fdw.source | 2 +- .../pg_stat_statements/pg_stat_statements.c | 4 ++-- contrib/pgrowlocks/pgrowlocks.c | 2 +- doc/src/sgml/adminpack.sgml | 6 +++--- doc/src/sgml/catalogs.sgml | 12 +++++------ doc/src/sgml/func.sgml | 12 +++++------ doc/src/sgml/monitoring.sgml | 2 +- doc/src/sgml/pgbuffercache.sgml | 2 +- doc/src/sgml/pgfreespacemap.sgml | 2 +- doc/src/sgml/pgrowlocks.sgml | 2 +- doc/src/sgml/pgstatstatements.sgml | 2 +- doc/src/sgml/pgvisibility.sgml | 4 ++-- src/backend/commands/copy.c | 12 +++++------ src/backend/replication/walreceiver.c | 8 ++++---- src/backend/replication/walsender.c | 8 ++++---- src/backend/utils/adt/acl.c | 4 ++++ src/backend/utils/adt/dbsize.c | 8 ++++---- src/backend/utils/adt/genfile.c | 6 +++--- src/backend/utils/adt/pgstatfuncs.c | 2 +- src/backend/utils/misc/guc.c | 20 +++++++++---------- .../unsafe_tests/expected/rolenames.out | 2 +- 23 files changed, 68 insertions(+), 64 deletions(-) diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c index 48c17469104..0457d7b591d 100644 --- a/contrib/adminpack/adminpack.c +++ b/contrib/adminpack/adminpack.c @@ -79,7 +79,7 @@ convert_and_check_filename(text *arg) * files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) return filename; /* diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 2c2f149fb01..a769b2ef7b9 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -269,16 +269,16 @@ file_fdw_validator(PG_FUNCTION_ARGS) * otherwise there'd still be a security hole. */ if (strcmp(def->defname, "filename") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); if (strcmp(def->defname, "program") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + !has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); filename = defGetString(def); } diff --git a/contrib/file_fdw/output/file_fdw.source b/contrib/file_fdw/output/file_fdw.source index 52b4d5f1df7..a1d44ed665a 100644 --- a/contrib/file_fdw/output/file_fdw.source +++ b/contrib/file_fdw/output/file_fdw.source @@ -436,7 +436,7 @@ ALTER FOREIGN TABLE agg_text OWNER TO regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); SET ROLE regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); -ERROR: only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table +ERROR: only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table SET ROLE regress_file_fdw_superuser; -- cleanup RESET ROLE; diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 726ba59e2bf..f6120f5c48b 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1511,8 +1511,8 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, HASH_SEQ_STATUS hash_seq; pgssEntry *entry; - /* Superusers or members of pg_read_all_stats members are allowed */ - is_allowed_role = is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); + /* Superusers or roles with the privileges of pg_read_all_stats members are allowed */ + is_allowed_role = has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); /* hash table must exist already */ if (!pgss || !pgss_hash) diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index 669a7d7730b..b9b724a554d 100644 --- a/contrib/pgrowlocks/pgrowlocks.c +++ b/contrib/pgrowlocks/pgrowlocks.c @@ -130,7 +130,7 @@ pgrowlocks(PG_FUNCTION_ARGS) aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), ACL_SELECT); if (aclresult != ACLCHECK_OK) - aclresult = is_member_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; + aclresult = has_privs_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), diff --git a/doc/src/sgml/adminpack.sgml b/doc/src/sgml/adminpack.sgml index 0dd89be3534..5702456cd25 100644 --- a/doc/src/sgml/adminpack.sgml +++ b/doc/src/sgml/adminpack.sgml @@ -22,9 +22,9 @@ functions in <xref linkend="functions-admin-genfile-table"/>, which provide read-only access.) Only files within the database cluster directory can be accessed, unless the - user is a superuser or given one of the pg_read_server_files, or pg_write_server_files - roles, as appropriate for the function, but either a relative or absolute path is - allowable. + user is a superuser or given privileges of one of the pg_read_server_files, + or pg_write_server_files roles, as appropriate for the function, but either a + relative or absolute path is allowable. </para> <table id="functions-adminpack-table"> diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index c1d11be73f7..8cfff1da3be 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -9916,8 +9916,8 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l <para> By default, the <structname>pg_backend_memory_contexts</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with the privileges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> @@ -12358,7 +12358,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Configuration file the current value was set in (null for values set from sources other than configuration files, or when - examined by a user who is neither a superuser or a member of + examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>); helpful when using <literal>include</literal> directives in configuration files </para></entry> @@ -12371,7 +12371,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Line number within the configuration file the current value was set at (null for values set from sources other than configuration files, - or when examined by a user who is neither a superuser or a member of + or when examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>). </para></entry> </row> @@ -12747,8 +12747,8 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> By default, the <structname>pg_shmem_allocations</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with privileges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 24447c00177..3bad6b0d08e 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -25321,7 +25321,7 @@ SELECT collation for ('foo' COLLATE "de_DE"); Cancels the current query of the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being canceled or - the calling role has been granted <literal>pg_signal_backend</literal>, + the calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can cancel superuser backends. </para></entry> </row> @@ -25392,7 +25392,7 @@ SELECT collation for ('foo' COLLATE "de_DE"); Terminates the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being terminated or the - calling role has been granted <literal>pg_signal_backend</literal>, + calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can terminate superuser backends. </para> <para> @@ -26666,7 +26666,7 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup()); Computes the total disk space used by the database with the specified name or OID. To use this function, you must have <literal>CONNECT</literal> privilege on the specified database - (which is granted by default) or be a member of + (which is granted by default) or have privileges of the <literal>pg_read_all_stats</literal> role. </para></entry> </row> @@ -26796,7 +26796,7 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup()); Computes the total disk space used in the tablespace with the specified name or OID. To use this function, you must have <literal>CREATE</literal> privilege on the specified tablespace - or be a member of the <literal>pg_read_all_stats</literal> role, + or have privileges of the <literal>pg_read_all_stats</literal> role, unless it is the default tablespace for the current database. </para></entry> </row> @@ -27257,7 +27257,7 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size a dot, directories, and other special files are excluded. </para> <para> - This function is restricted to superusers and members of + This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> @@ -27281,7 +27281,7 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size are excluded. </para> <para> - This function is restricted to superusers and members of + This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3173ec25660..5e603db45aa 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -280,7 +280,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser (sessions belonging to a role that they are a member of). In rows about other sessions, many columns will be null. Note, however, that the existence of a session and its general properties such as its sessions user - and database are visible to all users. Superusers and members of the + and database are visible to all users. Superusers and roles with privileges of built-in role <literal>pg_read_all_stats</literal> (see also <xref linkend="predefined-roles"/>) can see all the information about all sessions. </para> diff --git a/doc/src/sgml/pgbuffercache.sgml b/doc/src/sgml/pgbuffercache.sgml index e68d159d30f..a06fd3e26de 100644 --- a/doc/src/sgml/pgbuffercache.sgml +++ b/doc/src/sgml/pgbuffercache.sgml @@ -24,7 +24,7 @@ </para> <para> - By default, use is restricted to superusers and members of the + By default, use is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgfreespacemap.sgml b/doc/src/sgml/pgfreespacemap.sgml index 5025498249d..0f3aebd27ef 100644 --- a/doc/src/sgml/pgfreespacemap.sgml +++ b/doc/src/sgml/pgfreespacemap.sgml @@ -16,7 +16,7 @@ </para> <para> - By default use is restricted to superusers and members of the + By default use is restricted to superusers and roles with privileges of the <literal>pg_stat_scan_tables</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgrowlocks.sgml b/doc/src/sgml/pgrowlocks.sgml index 392d5f1f9a7..2914bf6e6d6 100644 --- a/doc/src/sgml/pgrowlocks.sgml +++ b/doc/src/sgml/pgrowlocks.sgml @@ -13,7 +13,7 @@ </para> <para> - By default use is restricted to superusers, members of the + By default use is restricted to superusers, roles with privileges of the <literal>pg_stat_scan_tables</literal> role, and users with <literal>SELECT</literal> permissions on the table. </para> diff --git a/doc/src/sgml/pgstatstatements.sgml b/doc/src/sgml/pgstatstatements.sgml index bc9d5bdbe3b..3a7e36bd13c 100644 --- a/doc/src/sgml/pgstatstatements.sgml +++ b/doc/src/sgml/pgstatstatements.sgml @@ -384,7 +384,7 @@ </table> <para> - For security reasons, only superusers and members of the + For security reasons, only superusers and roles with privileges of the <literal>pg_read_all_stats</literal> role are allowed to see the SQL text and <structfield>queryid</structfield> of queries executed by other users. Other users can see the statistics, however, if the view has been installed diff --git a/doc/src/sgml/pgvisibility.sgml b/doc/src/sgml/pgvisibility.sgml index 75336946a61..8090aa5207e 100644 --- a/doc/src/sgml/pgvisibility.sgml +++ b/doc/src/sgml/pgvisibility.sgml @@ -140,8 +140,8 @@ </variablelist> <para> - By default, these functions are executable only by superusers and members of the - <literal>pg_stat_scan_tables</literal> role, with the exception of + By default, these functions are executable only by superusers and roles with privileges + of the <literal>pg_stat_scan_tables</literal> role, with the exception of <function>pg_truncate_visibility_map(relation regclass)</function> which can only be executed by superusers. </para> diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 53f48531419..e26ff42fd82 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -80,26 +80,26 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, { if (stmt->is_program) { - if (!is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_execute_server_program role to COPY to or from an external program"), + errmsg("must be superuser or have privileges of the pg_execute_server_program role to COPY to or from an external program"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } else { - if (is_from && !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (is_from && !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_read_server_files role to COPY from a file"), + errmsg("must be superuser or have privileges of the pg_read_server_files role to COPY from a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); - if (!is_from && !is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (!is_from && !has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_write_server_files role to COPY to a file"), + errmsg("must be superuser or have privileges of the pg_write_server_files role to COPY to a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 7a7eb3784e7..9de72962322 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1402,12 +1402,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) /* Fetch values */ values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see details. - * Other users only get the pid value to know whether it is a WAL - * receiver, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know whether + * it is a WAL receiver, but no details. */ MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 7950afb173c..5e2435a8563 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -3488,12 +3488,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) memset(nulls, 0, sizeof(nulls)); values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see - * details. Other users only get the pid value to know it's a - * walsender, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know + * it's a walsender, but no details. */ MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1); } diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 67f8b29434a..e2ce4582f19 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -4864,6 +4864,8 @@ has_privs_of_role(Oid member, Oid role) * Is member a member of role (directly or indirectly)? * * This is defined to recurse through roles regardless of rolinherit. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role(Oid member, Oid role) @@ -4904,6 +4906,8 @@ check_is_member_of_role(Oid member, Oid role) * * This is identical to is_member_of_role except we ignore superuser * status. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role_nosuper(Oid member, Oid role) diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index d5a7fb13f3c..91ec2615cd5 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -112,12 +112,12 @@ calculate_database_size(Oid dbOid) AclResult aclresult; /* - * User must have connect privilege for target database or be a member of + * User must have connect privilege for target database or have privileges of * pg_read_all_stats */ aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT); if (aclresult != ACLCHECK_OK && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclcheck_error(aclresult, OBJECT_DATABASE, get_database_name(dbOid)); @@ -196,12 +196,12 @@ calculate_tablespace_size(Oid tblspcOid) AclResult aclresult; /* - * User must be a member of pg_read_all_stats or have CREATE privilege for + * User must have privileges of pg_read_all_stats or have CREATE privilege for * target tablespace, either explicitly granted or implicitly because it * is default for current database. */ if (tblspcOid != MyDatabaseTableSpace && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE); if (aclresult != ACLCHECK_OK) diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index c436d9318b6..f87f77093a6 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -58,11 +58,11 @@ convert_and_check_filename(text *arg) canonicalize_path(filename); /* filename can change length here */ /* - * Members of the 'pg_read_server_files' role are allowed to access any - * files on the server as the PG user, so no need to do any further checks + * Roles with privleges of the 'pg_read_server_files' role are allowed to access + * any files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) return filename; /* diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index e64857e5409..8965208af18 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -34,7 +34,7 @@ #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) -#define HAS_PGSTAT_PERMISSIONS(role) (is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) +#define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index e91d5a3cfda..e400bfdea13 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -8154,10 +8154,10 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged) return NULL; if (restrict_privileged && (record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -8201,10 +8201,10 @@ GetConfigOptionResetString(const char *name) record = find_option(name, false, false, ERROR); Assert(record != NULL); if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -9448,7 +9448,7 @@ ShowAllGUCConfig(DestReceiver *dest) if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* assign to the values array */ @@ -9515,7 +9515,7 @@ get_explain_guc_options(int *num) /* return only options visible to the current user */ if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* return only options that are different from their boot values */ @@ -9597,10 +9597,10 @@ GetConfigOptionByName(const char *name, const char **varname, bool missing_ok) } if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); if (varname) @@ -9628,7 +9628,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) { if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) *noshow = true; else *noshow = false; @@ -9823,7 +9823,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) * insufficiently-privileged users. */ if (conf->source == PGC_S_FILE && - is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) { values[14] = conf->sourcefile; snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); diff --git a/src/test/modules/unsafe_tests/expected/rolenames.out b/src/test/modules/unsafe_tests/expected/rolenames.out index eb608fdc2ea..88b1ff843be 100644 --- a/src/test/modules/unsafe_tests/expected/rolenames.out +++ b/src/test/modules/unsafe_tests/expected/rolenames.out @@ -1077,7 +1077,7 @@ SHOW session_preload_libraries; SET SESSION AUTHORIZATION regress_role_nopriv; -- fails with role not member of pg_read_all_settings SHOW session_preload_libraries; -ERROR: must be superuser or a member of pg_read_all_settings to examine "session_preload_libraries" +ERROR: must be superuser or have privileges of pg_read_all_settings to examine "session_preload_libraries" RESET SESSION AUTHORIZATION; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- 2.31.1
^ permalink raw reply [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2021-11-15 22:23               ` Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 42+ messages in thread

From: Bossart, Nathan @ 2021-11-15 22:23 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Stephen Frost <sfrost@snowman.net>; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

On 11/12/21, 12:34 PM, "Joshua Brindle" <joshua.brindle@crunchydata.com> wrote:
> All of these and also adminpack.sgml updated. I think that is all of
> them but docs broken across lines and irregular wording makes it
> difficult.

LGTM.  I've marked this as ready-for-committer.

Nathan



^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
@ 2022-01-04 20:56                 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Tom Lane @ 2022-01-04 20:56 UTC (permalink / raw)
  To: Bossart, Nathan <bossartn@amazon.com>; +Cc: Joshua Brindle <joshua.brindle@crunchydata.com>; Stephen Frost <sfrost@snowman.net>; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

"Bossart, Nathan" <bossartn@amazon.com> writes:
> On 11/12/21, 12:34 PM, "Joshua Brindle" <joshua.brindle@crunchydata.com> wrote:
>> All of these and also adminpack.sgml updated. I think that is all of
>> them but docs broken across lines and irregular wording makes it
>> difficult.

> LGTM.  I've marked this as ready-for-committer.

This needs another rebase --- it's trying to adjust
file_fdw/output/file_fdw.source, which no longer exists
(fix the regular file_fdw.out, instead).

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-01-04 21:51                   ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joshua Brindle @ 2022-01-04 21:51 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

On Tue, Jan 4, 2022 at 3:56 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> "Bossart, Nathan" <bossartn@amazon.com> writes:
> > On 11/12/21, 12:34 PM, "Joshua Brindle" <joshua.brindle@crunchydata.com> wrote:
> >> All of these and also adminpack.sgml updated. I think that is all of
> >> them but docs broken across lines and irregular wording makes it
> >> difficult.
>
> > LGTM.  I've marked this as ready-for-committer.
>
> This needs another rebase --- it's trying to adjust
> file_fdw/output/file_fdw.source, which no longer exists
> (fix the regular file_fdw.out, instead).
>
>                         regards, tom lane

Attached, thanks

Attachments:

v4-0001-use-has_privs_for_roles-for-predefined-role-checks.patch (application/octet-stream, 27.7K) download From 9cf228081f90ffd7c7447907cca629c1c0ab365f Mon Sep 17 00:00:00 2001 From: Joshua Brindle <joshua.brindle@crunchydata.com> Date: Tue, 26 Oct 2021 14:19:44 -0700 Subject: [PATCH] use has_privs_for_roles for predefined role checks Generally if a role is granted membership to another role with NOINHERIT they must use SET ROLE to access the privileges of that role, however with predefined roles the membership and privilege is conflated, as demonstrated by: CREATE ROLE readrole; CREATE ROLE role2 NOINHERIT; CREATE ROLE brindle LOGIN; GRANT role2 TO brindle; CREATE TABLE foo(i INT); GRANT readrole TO role2; GRANT ALL ON TABLE foo TO readrole; GRANT pg_read_all_stats,pg_read_all_settings,pg_read_server_files,pg_write_server_files,pg_execute_server_program TO role2; Log in as brindle: postgres=> select current_user; current_user -------------- brindle (1 row) postgres=> SELECT * FROM foo; ERROR: permission denied for table foo postgres=> SELECT DISTINCT query FROM pg_stat_activity; query ---------------------------------------------- SELECT DISTINCT query FROM pg_stat_activity; (2 rows) postgres=> SET ROLE readrole; SET postgres=> SELECT * FROM foo; i Signed-off-by: Joshua Brindle <joshua.brindle@crunchydata.com> --- contrib/adminpack/adminpack.c | 2 +- contrib/file_fdw/expected/file_fdw.out | 2 +- contrib/file_fdw/file_fdw.c | 8 ++++---- .../pg_stat_statements/pg_stat_statements.c | 4 ++-- contrib/pgrowlocks/pgrowlocks.c | 2 +- doc/src/sgml/adminpack.sgml | 6 +++--- doc/src/sgml/catalogs.sgml | 12 +++++------ doc/src/sgml/func.sgml | 12 +++++------ doc/src/sgml/monitoring.sgml | 2 +- doc/src/sgml/pgbuffercache.sgml | 2 +- doc/src/sgml/pgfreespacemap.sgml | 2 +- doc/src/sgml/pgrowlocks.sgml | 2 +- doc/src/sgml/pgstatstatements.sgml | 2 +- doc/src/sgml/pgvisibility.sgml | 4 ++-- src/backend/commands/copy.c | 12 +++++------ src/backend/replication/walreceiver.c | 8 ++++---- src/backend/replication/walsender.c | 8 ++++---- src/backend/utils/adt/acl.c | 4 ++++ src/backend/utils/adt/dbsize.c | 8 ++++---- src/backend/utils/adt/genfile.c | 6 +++--- src/backend/utils/adt/pgstatfuncs.c | 2 +- src/backend/utils/misc/guc.c | 20 +++++++++---------- .../unsafe_tests/expected/rolenames.out | 2 +- 23 files changed, 68 insertions(+), 64 deletions(-) diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c index 48c1746910..0457d7b591 100644 --- a/contrib/adminpack/adminpack.c +++ b/contrib/adminpack/adminpack.c @@ -79,7 +79,7 @@ convert_and_check_filename(text *arg) * files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) return filename; /* diff --git a/contrib/file_fdw/expected/file_fdw.out b/contrib/file_fdw/expected/file_fdw.out index 891146fef3..c13b7ca307 100644 --- a/contrib/file_fdw/expected/file_fdw.out +++ b/contrib/file_fdw/expected/file_fdw.out @@ -461,7 +461,7 @@ ALTER FOREIGN TABLE agg_text OWNER TO regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); SET ROLE regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); -ERROR: only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table +ERROR: only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table SET ROLE regress_file_fdw_superuser; -- cleanup RESET ROLE; diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 146b524076..2c55318d9e 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -269,16 +269,16 @@ file_fdw_validator(PG_FUNCTION_ARGS) * otherwise there'd still be a security hole. */ if (strcmp(def->defname, "filename") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); if (strcmp(def->defname, "program") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + !has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); filename = defGetString(def); } diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index bede662907..5f48be1f36 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1507,8 +1507,8 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, HASH_SEQ_STATUS hash_seq; pgssEntry *entry; - /* Superusers or members of pg_read_all_stats members are allowed */ - is_allowed_role = is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); + /* Superusers or roles with the privileges of pg_read_all_stats members are allowed */ + is_allowed_role = has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS); /* hash table must exist already */ if (!pgss || !pgss_hash) diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index d8946dc510..3dd8aa7bbe 100644 --- a/contrib/pgrowlocks/pgrowlocks.c +++ b/contrib/pgrowlocks/pgrowlocks.c @@ -130,7 +130,7 @@ pgrowlocks(PG_FUNCTION_ARGS) aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), ACL_SELECT); if (aclresult != ACLCHECK_OK) - aclresult = is_member_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; + aclresult = has_privs_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), diff --git a/doc/src/sgml/adminpack.sgml b/doc/src/sgml/adminpack.sgml index 0dd89be353..5702456cd2 100644 --- a/doc/src/sgml/adminpack.sgml +++ b/doc/src/sgml/adminpack.sgml @@ -22,9 +22,9 @@ functions in <xref linkend="functions-admin-genfile-table"/>, which provide read-only access.) Only files within the database cluster directory can be accessed, unless the - user is a superuser or given one of the pg_read_server_files, or pg_write_server_files - roles, as appropriate for the function, but either a relative or absolute path is - allowable. + user is a superuser or given privileges of one of the pg_read_server_files, + or pg_write_server_files roles, as appropriate for the function, but either a + relative or absolute path is allowable. </para> <table id="functions-adminpack-table"> diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 03e2537b07..5f5a034240 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -9932,8 +9932,8 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l <para> By default, the <structname>pg_backend_memory_contexts</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with the privileges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> @@ -12374,7 +12374,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Configuration file the current value was set in (null for values set from sources other than configuration files, or when - examined by a user who is neither a superuser or a member of + examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>); helpful when using <literal>include</literal> directives in configuration files </para></entry> @@ -12387,7 +12387,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Line number within the configuration file the current value was set at (null for values set from sources other than configuration files, - or when examined by a user who is neither a superuser or a member of + or when examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>). </para></entry> </row> @@ -12763,8 +12763,8 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> By default, the <structname>pg_shmem_allocations</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with privileges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index e58efce586..1f53f1e17d 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -25406,7 +25406,7 @@ SELECT collation for ('foo' COLLATE "de_DE"); Cancels the current query of the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being canceled or - the calling role has been granted <literal>pg_signal_backend</literal>, + the calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can cancel superuser backends. </para></entry> </row> @@ -25477,7 +25477,7 @@ SELECT collation for ('foo' COLLATE "de_DE"); Terminates the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being terminated or the - calling role has been granted <literal>pg_signal_backend</literal>, + calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can terminate superuser backends. </para> <para> @@ -26751,7 +26751,7 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup()); Computes the total disk space used by the database with the specified name or OID. To use this function, you must have <literal>CONNECT</literal> privilege on the specified database - (which is granted by default) or be a member of + (which is granted by default) or have privileges of the <literal>pg_read_all_stats</literal> role. </para></entry> </row> @@ -26881,7 +26881,7 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup()); Computes the total disk space used in the tablespace with the specified name or OID. To use this function, you must have <literal>CREATE</literal> privilege on the specified tablespace - or be a member of the <literal>pg_read_all_stats</literal> role, + or have privileges of the <literal>pg_read_all_stats</literal> role, unless it is the default tablespace for the current database. </para></entry> </row> @@ -27342,7 +27342,7 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size a dot, directories, and other special files are excluded. </para> <para> - This function is restricted to superusers and members of + This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> @@ -27366,7 +27366,7 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size are excluded. </para> <para> - This function is restricted to superusers and members of + This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 62f2a3332b..3f89ebe005 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -280,7 +280,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser (sessions belonging to a role that they are a member of). In rows about other sessions, many columns will be null. Note, however, that the existence of a session and its general properties such as its sessions user - and database are visible to all users. Superusers and members of the + and database are visible to all users. Superusers and roles with privileges of built-in role <literal>pg_read_all_stats</literal> (see also <xref linkend="predefined-roles"/>) can see all the information about all sessions. </para> diff --git a/doc/src/sgml/pgbuffercache.sgml b/doc/src/sgml/pgbuffercache.sgml index e68d159d30..a06fd3e26d 100644 --- a/doc/src/sgml/pgbuffercache.sgml +++ b/doc/src/sgml/pgbuffercache.sgml @@ -24,7 +24,7 @@ </para> <para> - By default, use is restricted to superusers and members of the + By default, use is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgfreespacemap.sgml b/doc/src/sgml/pgfreespacemap.sgml index 5025498249..0f3aebd27e 100644 --- a/doc/src/sgml/pgfreespacemap.sgml +++ b/doc/src/sgml/pgfreespacemap.sgml @@ -16,7 +16,7 @@ </para> <para> - By default use is restricted to superusers and members of the + By default use is restricted to superusers and roles with privileges of the <literal>pg_stat_scan_tables</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgrowlocks.sgml b/doc/src/sgml/pgrowlocks.sgml index 392d5f1f9a..2914bf6e6d 100644 --- a/doc/src/sgml/pgrowlocks.sgml +++ b/doc/src/sgml/pgrowlocks.sgml @@ -13,7 +13,7 @@ </para> <para> - By default use is restricted to superusers, members of the + By default use is restricted to superusers, roles with privileges of the <literal>pg_stat_scan_tables</literal> role, and users with <literal>SELECT</literal> permissions on the table. </para> diff --git a/doc/src/sgml/pgstatstatements.sgml b/doc/src/sgml/pgstatstatements.sgml index bc9d5bdbe3..3a7e36bd13 100644 --- a/doc/src/sgml/pgstatstatements.sgml +++ b/doc/src/sgml/pgstatstatements.sgml @@ -384,7 +384,7 @@ </table> <para> - For security reasons, only superusers and members of the + For security reasons, only superusers and roles with privileges of the <literal>pg_read_all_stats</literal> role are allowed to see the SQL text and <structfield>queryid</structfield> of queries executed by other users. Other users can see the statistics, however, if the view has been installed diff --git a/doc/src/sgml/pgvisibility.sgml b/doc/src/sgml/pgvisibility.sgml index 75336946a6..8090aa5207 100644 --- a/doc/src/sgml/pgvisibility.sgml +++ b/doc/src/sgml/pgvisibility.sgml @@ -140,8 +140,8 @@ </variablelist> <para> - By default, these functions are executable only by superusers and members of the - <literal>pg_stat_scan_tables</literal> role, with the exception of + By default, these functions are executable only by superusers and roles with privileges + of the <literal>pg_stat_scan_tables</literal> role, with the exception of <function>pg_truncate_visibility_map(relation regclass)</function> which can only be executed by superusers. </para> diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 53f4853141..e26ff42fd8 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -80,26 +80,26 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, { if (stmt->is_program) { - if (!is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_execute_server_program role to COPY to or from an external program"), + errmsg("must be superuser or have privileges of the pg_execute_server_program role to COPY to or from an external program"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } else { - if (is_from && !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (is_from && !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_read_server_files role to COPY from a file"), + errmsg("must be superuser or have privileges of the pg_read_server_files role to COPY from a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); - if (!is_from && !is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (!is_from && !has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_write_server_files role to COPY to a file"), + errmsg("must be superuser or have privileges of the pg_write_server_files role to COPY to a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 7a7eb3784e..9de7296232 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1402,12 +1402,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) /* Fetch values */ values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see details. - * Other users only get the pid value to know whether it is a WAL - * receiver, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know whether + * it is a WAL receiver, but no details. */ MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 84915ed95b..c421b25a7b 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -3489,12 +3489,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) memset(nulls, 0, sizeof(nulls)); values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see - * details. Other users only get the pid value to know it's a - * walsender, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know + * it's a walsender, but no details. */ MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1); } diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 67f8b29434..e2ce4582f1 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -4864,6 +4864,8 @@ has_privs_of_role(Oid member, Oid role) * Is member a member of role (directly or indirectly)? * * This is defined to recurse through roles regardless of rolinherit. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role(Oid member, Oid role) @@ -4904,6 +4906,8 @@ check_is_member_of_role(Oid member, Oid role) * * This is identical to is_member_of_role except we ignore superuser * status. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role_nosuper(Oid member, Oid role) diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index d5a7fb13f3..91ec2615cd 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -112,12 +112,12 @@ calculate_database_size(Oid dbOid) AclResult aclresult; /* - * User must have connect privilege for target database or be a member of + * User must have connect privilege for target database or have privileges of * pg_read_all_stats */ aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT); if (aclresult != ACLCHECK_OK && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclcheck_error(aclresult, OBJECT_DATABASE, get_database_name(dbOid)); @@ -196,12 +196,12 @@ calculate_tablespace_size(Oid tblspcOid) AclResult aclresult; /* - * User must be a member of pg_read_all_stats or have CREATE privilege for + * User must have privileges of pg_read_all_stats or have CREATE privilege for * target tablespace, either explicitly granted or implicitly because it * is default for current database. */ if (tblspcOid != MyDatabaseTableSpace && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE); if (aclresult != ACLCHECK_OK) diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index 027ed86400..6c538315ca 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -59,11 +59,11 @@ convert_and_check_filename(text *arg) canonicalize_path(filename); /* filename can change length here */ /* - * Members of the 'pg_read_server_files' role are allowed to access any - * files on the server as the PG user, so no need to do any further checks + * Roles with privleges of the 'pg_read_server_files' role are allowed to access + * any files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) return filename; /* diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index f529c1561a..3e18a7dcc8 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -34,7 +34,7 @@ #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) -#define HAS_PGSTAT_PERMISSIONS(role) (is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) +#define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index f9504d3aec..4f6774e049 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -8160,10 +8160,10 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged) return NULL; if (restrict_privileged && (record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -8207,10 +8207,10 @@ GetConfigOptionResetString(const char *name) record = find_option(name, false, false, ERROR); Assert(record != NULL); if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -9461,7 +9461,7 @@ ShowAllGUCConfig(DestReceiver *dest) if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* assign to the values array */ @@ -9528,7 +9528,7 @@ get_explain_guc_options(int *num) /* return only options visible to the current user */ if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* return only options that are different from their boot values */ @@ -9610,10 +9610,10 @@ GetConfigOptionByName(const char *name, const char **varname, bool missing_ok) } if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); if (varname) @@ -9641,7 +9641,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) { if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) *noshow = true; else *noshow = false; @@ -9836,7 +9836,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) * insufficiently-privileged users. */ if (conf->source == PGC_S_FILE && - is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) { values[14] = conf->sourcefile; snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); diff --git a/src/test/modules/unsafe_tests/expected/rolenames.out b/src/test/modules/unsafe_tests/expected/rolenames.out index eb608fdc2e..88b1ff843b 100644 --- a/src/test/modules/unsafe_tests/expected/rolenames.out +++ b/src/test/modules/unsafe_tests/expected/rolenames.out @@ -1077,7 +1077,7 @@ SHOW session_preload_libraries; SET SESSION AUTHORIZATION regress_role_nopriv; -- fails with role not member of pg_read_all_settings SHOW session_preload_libraries; -ERROR: must be superuser or a member of pg_read_all_settings to examine "session_preload_libraries" +ERROR: must be superuser or have privileges of pg_read_all_settings to examine "session_preload_libraries" RESET SESSION AUTHORIZATION; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- 2.32.0 (Apple Git-132)
^ permalink raw reply [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2022-02-06 16:38                     ` Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-02-06 16:38 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

On 1/4/22 16:51, Joshua Brindle wrote:
> On Tue, Jan 4, 2022 at 3:56 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>
>> "Bossart, Nathan" <bossartn@amazon.com> writes:
>> > On 11/12/21, 12:34 PM, "Joshua Brindle" <joshua.brindle@crunchydata.com> wrote:
>> >> All of these and also adminpack.sgml updated. I think that is all of
>> >> them but docs broken across lines and irregular wording makes it
>> >> difficult.
>>
>> > LGTM.  I've marked this as ready-for-committer.
>>
>> This needs another rebase --- it's trying to adjust
>> file_fdw/output/file_fdw.source, which no longer exists
>> (fix the regular file_fdw.out, instead).
>>
>>                         regards, tom lane
> 
> Attached, thanks

I'd like to pick this patch up and see it through to commit/push. 
Presumably that will include back-patching to all supported pg versions.

Before I go through the effort to back-patch, does anyone want to argue 
that this should *not* be back-patched?

Thanks,

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-02-06 17:24                       ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Tom Lane @ 2022-02-06 17:24 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers

Joe Conway <mail@joeconway.com> writes:
> I'd like to pick this patch up and see it through to commit/push. 
> Presumably that will include back-patching to all supported pg versions.
> Before I go through the effort to back-patch, does anyone want to argue 
> that this should *not* be back-patched?

Hm, I'm -0.5 or so.  I think changing security-related behaviors
in a stable branch is a hard sell unless you are closing a security
hole.  This is a fine improvement for HEAD but I'm inclined to
leave the back branches alone.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-02-07 15:35                         ` Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Robert Haas @ 2022-02-07 15:35 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Joe Conway <mail@joeconway.com>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Sun, Feb 6, 2022 at 12:24 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Joe Conway <mail@joeconway.com> writes:
> > I'd like to pick this patch up and see it through to commit/push.
> > Presumably that will include back-patching to all supported pg versions.
> > Before I go through the effort to back-patch, does anyone want to argue
> > that this should *not* be back-patched?
>
> Hm, I'm -0.5 or so.  I think changing security-related behaviors
> in a stable branch is a hard sell unless you are closing a security
> hole.  This is a fine improvement for HEAD but I'm inclined to
> leave the back branches alone.

I think the threshold to back-patch a clear behavior change is pretty
high, so I do not think it should be back-patched.

I am also not convinced that a sufficient argument has been made for
changing this in master. This isn't the only thread where NOINHERIT
has come up lately, and I have to admit that I'm not a fan. Let's
suppose that I have two users, let's say sunita and sri. In the real
world, Sunita is Sri's manager and needs to be able to perform actions
as Sri when Sri is out of the office, but it isn't desirable for
Sunita to have Sri's privileges in all situations all the time. So we
mark role sunita as NOINHERIT and grant sri to sunita. Then it turns
out that Sunita also needs to be COPY TO/FROM PROGRAM, so we give her
pg_execute_server_program. Now, if she can't exercise this privilege
without setting role to the prefined role, that's bad, isn't it? I
mean, we want her to be able to copy between *her* tables and various
shell commands, not the tables owned by pg_execute_server_program, of
which there are presumably none.

It seems to me that the INHERIT role flag isn't very well-considered.
Inheritance, or the lack of it, ought to be decided separately for
each inherited role. However, that would be a major architectural
change. But in the absence of that, it seems clearly better for
predefined roles to disregard INHERIT and just always grant the rights
they are intended to give. Because if we don't do that, then we end up
with people having to SET ROLE to the predefined role and perform
actions directly as that role, which seems like it can't be what we
want. I almost feel like we ought to be looking for ways of preventing
people from doing SET ROLE to a predefined role altogether, not
encouraging them to do it.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-02-07 16:13                           ` Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-02-07 16:13 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On 2/7/22 10:35, Robert Haas wrote:
> On Sun, Feb 6, 2022 at 12:24 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Joe Conway <mail@joeconway.com> writes:
>> > I'd like to pick this patch up and see it through to commit/push.
>> > Presumably that will include back-patching to all supported pg versions.
>> > Before I go through the effort to back-patch, does anyone want to argue
>> > that this should *not* be back-patched?
>>
>> Hm, I'm -0.5 or so.  I think changing security-related behaviors
>> in a stable branch is a hard sell unless you are closing a security
>> hole.  This is a fine improvement for HEAD but I'm inclined to
>> leave the back branches alone.
> 
> I think the threshold to back-patch a clear behavior change is pretty
> high, so I do not think it should be back-patched.

ok

> I am also not convinced that a sufficient argument has been made for
> changing this in master. This isn't the only thread where NOINHERIT
> has come up lately, and I have to admit that I'm not a fan. Let's
> suppose that I have two users, let's say sunita and sri. In the real
> world, Sunita is Sri's manager and needs to be able to perform actions
> as Sri when Sri is out of the office, but it isn't desirable for
> Sunita to have Sri's privileges in all situations all the time. So we
> mark role sunita as NOINHERIT and grant sri to sunita. Then it turns
> out that Sunita also needs to be COPY TO/FROM PROGRAM, so we give her
> pg_execute_server_program. Now, if she can't exercise this privilege
> without setting role to the prefined role, that's bad, isn't it? I
> mean, we want her to be able to copy between *her* tables and various
> shell commands, not the tables owned by pg_execute_server_program, of
> which there are presumably none.

Easily worked around with one additional level of role:

8<---------------------------------------
nmx=# create user sunita;
CREATE ROLE
nmx=# create user sri superuser;
CREATE ROLE
nmx=# create user sri_alt noinherit;
CREATE ROLE
nmx=# grant sri to sri_alt;
GRANT ROLE
nmx=# grant sri_alt to sunita;
GRANT ROLE
nmx=# grant pg_execute_server_program to sunita;
GRANT ROLE
nmx=# set session authorization sri;
SET
nmx=# create table foo(id int);
CREATE TABLE
nmx=# insert into foo values(42);
INSERT 0 1
nmx=# set session authorization sunita;
SET
nmx=> select * from foo;
ERROR:  permission denied for table foo
nmx=> set role sri;
SET
nmx=# select * from foo;
  id
----
  42
(1 row)

nmx=# reset role;
RESET
nmx=> select current_user;
  current_user
--------------
  sunita
(1 row)

nmx=> create temp table sfoo(f1 text);
CREATE TABLE
nmx=> copy sfoo(f1) from program 'id';
COPY 1
nmx=> select f1 from sfoo;
                                            f1 

----------------------------------------------------------------------------------------
  uid=1001(postgres) gid=1001(postgres) 
groups=1001(postgres),108(ssl-cert),1002(pgconf)
(1 row)
8<---------------------------------------

> It seems to me that the INHERIT role flag isn't very well-considered.
> Inheritance, or the lack of it, ought to be decided separately for
> each inherited role. However, that would be a major architectural
> change.

Agreed -- that would be useful.

> But in the absence of that, it seems clearly better for predefined
> roles to disregard INHERIT and just always grant the rights they are
> intended to give. Because if we don't do that, then we end up with
> people having to SET ROLE to the predefined role and perform actions
> directly as that role, which seems like it can't be what we want. I
> almost feel like we ought to be looking for ways of preventing people
> from doing SET ROLE to a predefined role altogether, not encouraging
> them to do it.
I disagree with this though.

It is confusing and IMHO dangerous that the predefined roles currently 
work differently than regular roles eith respect to privilege inheritance.

In fact, I would extend that argument to the pseudo-role PUBLIC.

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-02-07 17:09                             ` Robert Haas <robertmhaas@gmail.com>
  2022-02-07 17:23                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  0 siblings, 2 replies; 42+ messages in thread

From: Robert Haas @ 2022-02-07 17:09 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Mon, Feb 7, 2022 at 11:13 AM Joe Conway <mail@joeconway.com> wrote:
> Easily worked around with one additional level of role:

Interesting.

> > But in the absence of that, it seems clearly better for predefined
> > roles to disregard INHERIT and just always grant the rights they are
> > intended to give. Because if we don't do that, then we end up with
> > people having to SET ROLE to the predefined role and perform actions
> > directly as that role, which seems like it can't be what we want. I
> > almost feel like we ought to be looking for ways of preventing people
> > from doing SET ROLE to a predefined role altogether, not encouraging
> > them to do it.
> I disagree with this though.
>
> It is confusing and IMHO dangerous that the predefined roles currently
> work differently than regular roles eith respect to privilege inheritance.

I feel like that's kind of a conclusory statement, as opposed to
making an argument. I mean that this tells me something about how you
feel, but it doesn't really help me understand why you feel that way.

I suppose one argument in favor of your position is that if it
happened to be sri who was granted a predefined role, sunita would
inherit the rest of sr's privileges only with SET ROLE, but the
predefined role either way (IIUC, which I might not). If that's so,
then I guess I see the point, but I'm still sort of inclined to think
we're just trading one set of problems in for a different set. I just
have such a hard time imaging anyone using NOINHERIT in anger and
being happy with the result....

--
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-02-07 17:23                               ` Joshua Brindle <joshua.brindle@crunchydata.com>
  1 sibling, 0 replies; 42+ messages in thread

From: Joshua Brindle @ 2022-02-07 17:23 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Joe Conway <mail@joeconway.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Mon, Feb 7, 2022 at 12:09 PM Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Mon, Feb 7, 2022 at 11:13 AM Joe Conway <mail@joeconway.com> wrote:
> > Easily worked around with one additional level of role:
>
> Interesting.
>
> > > But in the absence of that, it seems clearly better for predefined
> > > roles to disregard INHERIT and just always grant the rights they are
> > > intended to give. Because if we don't do that, then we end up with
> > > people having to SET ROLE to the predefined role and perform actions
> > > directly as that role, which seems like it can't be what we want. I
> > > almost feel like we ought to be looking for ways of preventing people
> > > from doing SET ROLE to a predefined role altogether, not encouraging
> > > them to do it.
> > I disagree with this though.
> >
> > It is confusing and IMHO dangerous that the predefined roles currently
> > work differently than regular roles eith respect to privilege inheritance.
>
> I feel like that's kind of a conclusory statement, as opposed to
> making an argument. I mean that this tells me something about how you
> feel, but it doesn't really help me understand why you feel that way.
>
> I suppose one argument in favor of your position is that if it
> happened to be sri who was granted a predefined role, sunita would
> inherit the rest of sr's privileges only with SET ROLE, but the
> predefined role either way (IIUC, which I might not). If that's so,
> then I guess I see the point, but I'm still sort of inclined to think
> we're just trading one set of problems in for a different set. I just
> have such a hard time imaging anyone using NOINHERIT in anger and
> being happy with the result....
>

IMO this is inarguably a plain bug. The inheritance system works one
way for pre-defined roles and another way for other roles - and the
difference isn't even documented.

The question is whether there is a security issue warranting back
patching, which is a bit of a tossup I think. According to git history
it's always worked this way, and the possible breakage of pre-existing
clusters seems maybe not worth it.





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-02-08 11:59                               ` Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  1 sibling, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-02-08 11:59 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On 2/7/22 12:09, Robert Haas wrote:
> On Mon, Feb 7, 2022 at 11:13 AM Joe Conway <mail@joeconway.com> wrote:
>> It is confusing and IMHO dangerous that the predefined roles currently
>> work differently than regular roles eith respect to privilege inheritance.
> 
> I feel like that's kind of a conclusory statement, as opposed to
> making an argument. I mean that this tells me something about how you
> feel, but it doesn't really help me understand why you feel that way.


The argument is that we call these things "predefined roles", but they 
do not behave the same way normal "roles" behave.

Someone not intimately familiar with that fact could easily make bad 
assumptions, and therefore wind up with misconfigured security settings. 
In other words, it violates the principle of least astonishment (POLA).

As Joshua said nearby, it simply jumps out at me as a bug.

-------
After more thought, perhaps the real problem is that these things should 
not have been called "predefined roles" at all. I know, the horse has 
already left the barn on that, but in any case...

They are (to me at least) similar in concept to Linux capabilities in 
that they allow roles other than superusers to do a certain subset of 
the things historically reserved for superusers through a special 
mechanism (hardcoded) rather than through the normal privilege system 
(GRANTS/ACLs).

As an example, the predefined role pg_read_all_settings allows a 
non-superuser to read GUC normally reserved for superuser access only.

If I create a new user "bob" with the default INHERIT attribute, and I 
grant postgres to bob, bob must SET ROLE to postgres in order to access 
the capability to read superuser settings.

This is similar to bob's access to the default superuser privilege to 
read data in someone else's table (must SET ROLE to access that capability).

But it is different from bob's access to inherited privileges which are 
GRANTed:
8<--------------------------
psql nmx
psql (15devel)
Type "help" for help.

nmx=# create user bob;
CREATE ROLE

nmx=# grant postgres to bob;
GRANT ROLE

nmx=# \q
8<--------------------------
-and-
8<--------------------------
psql -U bob nmx
psql (15devel)
Type "help" for help.

nmx=> select current_user;
  current_user
--------------
  bob
(1 row)

nmx=> show stats_temp_directory;
ERROR:  must be superuser or have privileges of pg_read_all_settings to 
examine "stats_temp_directory"
nmx=> set role postgres;
SET
nmx=# show stats_temp_directory;
  stats_temp_directory
----------------------
  pg_stat_tmp
(1 row)

nmx=# select current_user;
  current_user
--------------
  postgres
(1 row)

nmx=# select * from foo;
  id
----
  42
(1 row)

nmx=# reset role;
RESET
nmx=> select current_user;
  current_user
--------------
  bob
(1 row)

nmx=> select * from foo;
ERROR:  permission denied for table foo
nmx=> set role postgres;
SET
nmx=# grant select on table foo to postgres;
GRANT
nmx=# reset role;
RESET
nmx=> select current_user;
  current_user
--------------
  bob
(1 row)

nmx=> select * from foo;
  id
----
  42
(1 row)
8<--------------------------

Joe

-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-02-08 13:45                                 ` Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Robert Haas @ 2022-02-08 13:45 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Tue, Feb 8, 2022 at 6:59 AM Joe Conway <mail@joeconway.com> wrote:
> This is similar to bob's access to the default superuser privilege to
> read data in someone else's table (must SET ROLE to access that capability).
>
> But it is different from bob's access to inherited privileges which are
> GRANTed:

Yeah. I think right here you've put your finger on what's been bugging
me about this: it's similar to one thing, and it's different from
another. To you and Joshua and Stephen, it seems 100% obvious that
these roles should work like grants of other roles. But I think of
them as capabilities derived from the superuser account, and so I'm
sort of tempted to think that they should work the way the superuser
bit does. And that's why I don't think the fact that they work the
other way is "just a bug" -- it's one of two possible ways that
someone could think that it ought to work based on how other things in
the system actually do work.

I'm not hard stuck on the idea that the current behavior is right, but
I don't think that we can really say that we've made things fully
consistent unless we make things like SUPERUSER and BYPASSRLS work the
same way that you want to make predefined roles work. And probably do
something about the INHERIT flag too because the current situation
seems like a hot mess.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-02-08 15:00                                   ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joshua Brindle @ 2022-02-08 15:00 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Joe Conway <mail@joeconway.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Tue, Feb 8, 2022 at 8:46 AM Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Tue, Feb 8, 2022 at 6:59 AM Joe Conway <mail@joeconway.com> wrote:
> > This is similar to bob's access to the default superuser privilege to
> > read data in someone else's table (must SET ROLE to access that capability).
> >
> > But it is different from bob's access to inherited privileges which are
> > GRANTed:
>
> Yeah. I think right here you've put your finger on what's been bugging
> me about this: it's similar to one thing, and it's different from
> another. To you and Joshua and Stephen, it seems 100% obvious that
> these roles should work like grants of other roles. But I think of
> them as capabilities derived from the superuser account, and so I'm
> sort of tempted to think that they should work the way the superuser
> bit does. And that's why I don't think the fact that they work the
> other way is "just a bug" -- it's one of two possible ways that
> someone could think that it ought to work based on how other things in
> the system actually do work.
>
> I'm not hard stuck on the idea that the current behavior is right, but
> I don't think that we can really say that we've made things fully
> consistent unless we make things like SUPERUSER and BYPASSRLS work the
> same way that you want to make predefined roles work. And probably do
> something about the INHERIT flag too because the current situation
> seems like a hot mess.

I think hot mess is an apt description of the current situation, for
example consider that:

src/backend/catalog/aclchk.c
3931: has_privs_of_role(roleid, ROLE_PG_READ_ALL_DATA))
3943: has_privs_of_role(roleid, ROLE_PG_WRITE_ALL_DATA))
4279: (has_privs_of_role(roleid, ROLE_PG_READ_ALL_DATA) ||
4280: has_privs_of_role(roleid, ROLE_PG_WRITE_ALL_DATA)))

src/backend/storage/ipc/signalfuncs.c
82: if (!has_privs_of_role(GetUserId(), proc->roleId) &&
83: !has_privs_of_role(GetUserId(), ROLE_PG_SIGNAL_BACKEND))

src/backend/storage/ipc/procarray.c
3843: if (!has_privs_of_role(GetUserId(), proc->roleId) &&
3844: !has_privs_of_role(GetUserId(), ROLE_PG_SIGNAL_BACKEND))

src/backend/tcop/utility.c
943: if (!has_privs_of_role(GetUserId(), ROLE_PG_CHECKPOINTER))

4 predefined roles currently use has_privs_of_role in master.

Further, pg_monitor, as an SQL-only predefined role, also behaves
consistently with the INHERIT rules that other roles do.

In order for SQL-only predefined roles to ignore INHERIT we would need
to hardcode bypasses for them, which IMO seems like the worst possible
solution to the current inconsistency.





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2022-02-08 15:07                                     ` Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Robert Haas @ 2022-02-08 15:07 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Joe Conway <mail@joeconway.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Tue, Feb 8, 2022 at 10:00 AM Joshua Brindle
<joshua.brindle@crunchydata.com> wrote:
> 4 predefined roles currently use has_privs_of_role in master.
>
> Further, pg_monitor, as an SQL-only predefined role, also behaves
> consistently with the INHERIT rules that other roles do.
>
> In order for SQL-only predefined roles to ignore INHERIT we would need
> to hardcode bypasses for them, which IMO seems like the worst possible
> solution to the current inconsistency.

I agree we need to make the situation consistent. But if you think
there's exactly one problem here and this patch fixes it, I
emphatically disagree.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-02-09 00:38                                       ` Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-02-09 00:38 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On 2/8/22 10:07, Robert Haas wrote:
> On Tue, Feb 8, 2022 at 10:00 AM Joshua Brindle
> <joshua.brindle@crunchydata.com> wrote:
>> 4 predefined roles currently use has_privs_of_role in master.
>>
>> Further, pg_monitor, as an SQL-only predefined role, also behaves
>> consistently with the INHERIT rules that other roles do.
>>
>> In order for SQL-only predefined roles to ignore INHERIT we would need
>> to hardcode bypasses for them, which IMO seems like the worst possible
>> solution to the current inconsistency.
> 
> I agree we need to make the situation consistent. But if you think
> there's exactly one problem here and this patch fixes it, I
> emphatically disagree.


If we were to start all over again with this feature my vote would be to 
do things differently than we have done. I would not have called them 
predefined roles, and I would have used attributes of roles (e.g. make 
rolsuper into a bitmap rather than a boolean) rather than role 
membership to implement them. But I didn't find time to participate in 
the original discussion or review/write the code, so I have little room 
to complain.

However since we did call these things predefined roles, and used role 
membership to implement them, I think they ought to behave both 
self-consistently as a group, and like other real roles.

That is what this patch does unless I am missing something.

I guess an alternative is to discuss a "proper fix", but it seems to me 
that would be a version 16 thing given how late we are in this 
development cycle and how invasive it is likely to be. And doing nothing 
for pg15 is not a very satisfying proposition :-/

Joe


-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-02-09 03:54                                         ` Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Robert Haas @ 2022-02-09 03:54 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Joshua Brindle <joshua.brindle@crunchydata.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Tue, Feb 8, 2022 at 7:38 PM Joe Conway <mail@joeconway.com> wrote:
> If we were to start all over again with this feature my vote would be to
> do things differently than we have done. I would not have called them
> predefined roles, and I would have used attributes of roles (e.g. make
> rolsuper into a bitmap rather than a boolean) rather than role
> membership to implement them. But I didn't find time to participate in
> the original discussion or review/write the code, so I have little room
> to complain.

Yep, fair. I kind of like the predefined role concept myself. I find
it sort of elegant, mostly because I think it scales better than a
bitmask, which can run out of bits surprisingly rapidly. But opinions
can vary, of course.

> However since we did call these things predefined roles, and used role
> membership to implement them, I think they ought to behave both
> self-consistently as a group, and like other real roles.
>
> That is what this patch does unless I am missing something.

Yes, I see that.

> I guess an alternative is to discuss a "proper fix", but it seems to me
> that would be a version 16 thing given how late we are in this
> development cycle and how invasive it is likely to be. And doing nothing
> for pg15 is not a very satisfying proposition :-/

True. The fact that we don't have consistency among existing
predefined roles is IMHO the best argument for this patch. That surely
can't be right.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-02-09 18:13                                           ` Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 20:58                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  0 siblings, 2 replies; 42+ messages in thread

From: Nathan Bossart @ 2022-02-09 18:13 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Joe Conway <mail@joeconway.com>; Joshua Brindle <joshua.brindle@crunchydata.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Tue, Feb 08, 2022 at 10:54:50PM -0500, Robert Haas wrote:
> On Tue, Feb 8, 2022 at 7:38 PM Joe Conway <mail@joeconway.com> wrote:
>> If we were to start all over again with this feature my vote would be to
>> do things differently than we have done. I would not have called them
>> predefined roles, and I would have used attributes of roles (e.g. make
>> rolsuper into a bitmap rather than a boolean) rather than role
>> membership to implement them. But I didn't find time to participate in
>> the original discussion or review/write the code, so I have little room
>> to complain.
> 
> Yep, fair. I kind of like the predefined role concept myself. I find
> it sort of elegant, mostly because I think it scales better than a
> bitmask, which can run out of bits surprisingly rapidly. But opinions
> can vary, of course.

I do wonder if users find the differences between predefined roles and role
attributes confusing.  INHERIT doesn't govern role attributes, but it will
govern predefined roles when this patch is applied.  Maybe the role
attribute system should eventually be deprecated in favor of using
predefined roles for everything.  Or perhaps the predefined roles should be
converted to role attributes.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
@ 2022-02-09 20:58                                             ` Robert Haas <robertmhaas@gmail.com>
  2022-02-09 21:51                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  1 sibling, 1 reply; 42+ messages in thread

From: Robert Haas @ 2022-02-09 20:58 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Joe Conway <mail@joeconway.com>; Joshua Brindle <joshua.brindle@crunchydata.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Wed, Feb 9, 2022 at 1:13 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
> I do wonder if users find the differences between predefined roles and role
> attributes confusing.  INHERIT doesn't govern role attributes, but it will
> govern predefined roles when this patch is applied.  Maybe the role
> attribute system should eventually be deprecated in favor of using
> predefined roles for everything.  Or perhaps the predefined roles should be
> converted to role attributes.

I couldn't agree more. Apparently it's even confusing to developers,
because otherwise (1) we wouldn't have the problem the patch proposes
to fix in the first place and (2) I would have immediately been
convinced of the value of the patch once it showed up. Since those
things didn't happen, this is apparently confusing to (1) whoever
wrote the code that this patch fixes and (2) me.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 20:58                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-02-09 21:51                                               ` Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 0 replies; 42+ messages in thread

From: Joshua Brindle @ 2022-02-09 21:51 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Joe Conway <mail@joeconway.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Wed, Feb 9, 2022 at 3:58 PM Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Wed, Feb 9, 2022 at 1:13 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
> > I do wonder if users find the differences between predefined roles and role
> > attributes confusing.  INHERIT doesn't govern role attributes, but it will
> > govern predefined roles when this patch is applied.  Maybe the role
> > attribute system should eventually be deprecated in favor of using
> > predefined roles for everything.  Or perhaps the predefined roles should be
> > converted to role attributes.
>
> I couldn't agree more. Apparently it's even confusing to developers,
> because otherwise (1) we wouldn't have the problem the patch proposes
> to fix in the first place and (2) I would have immediately been
> convinced of the value of the patch once it showed up. Since those
> things didn't happen, this is apparently confusing to (1) whoever
> wrote the code that this patch fixes and (2) me.
>

My original patch removed is_member_of to address #1 above, but that
was rejected[1]. There is now a warning in the header beside it to
hopefully dissuade improper usage going forward.

1. https://www.postgresql.org/message-id/254275.1635357633%40sss.pgh.pa.us





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
@ 2022-02-09 21:39                                             ` Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  1 sibling, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-02-09 21:39 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; Robert Haas <robertmhaas@gmail.com>; +Cc: Joshua Brindle <joshua.brindle@crunchydata.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On 2/9/22 13:13, Nathan Bossart wrote:
> On Tue, Feb 08, 2022 at 10:54:50PM -0500, Robert Haas wrote:
>> On Tue, Feb 8, 2022 at 7:38 PM Joe Conway <mail@joeconway.com> wrote:
>>> If we were to start all over again with this feature my vote would be to
>>> do things differently than we have done. I would not have called them
>>> predefined roles, and I would have used attributes of roles (e.g. make
>>> rolsuper into a bitmap rather than a boolean) rather than role
>>> membership to implement them. But I didn't find time to participate in
>>> the original discussion or review/write the code, so I have little room
>>> to complain.
>> 
>> Yep, fair. I kind of like the predefined role concept myself. I find
>> it sort of elegant, mostly because I think it scales better than a
>> bitmask, which can run out of bits surprisingly rapidly. But opinions
>> can vary, of course.
> 
> I do wonder if users find the differences between predefined roles and role
> attributes confusing.  INHERIT doesn't govern role attributes, but it will
> govern predefined roles when this patch is applied.  Maybe the role
> attribute system should eventually be deprecated in favor of using
> predefined roles for everything.  Or perhaps the predefined roles should be
> converted to role attributes.

Yep, I was suggesting that the latter would have been preferable to me 
while Robert seemed to prefer the former. Honestly I could be happy with 
either of those solutions, but as I alluded to that is probably a 
discussion for the next development cycle since I don't see us doing 
that big a change in this one.

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-02-10 19:28                                               ` Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Nathan Bossart @ 2022-02-10 19:28 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Robert Haas <robertmhaas@gmail.com>; Joshua Brindle <joshua.brindle@crunchydata.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
> On 2/9/22 13:13, Nathan Bossart wrote:
>> I do wonder if users find the differences between predefined roles and role
>> attributes confusing.  INHERIT doesn't govern role attributes, but it will
>> govern predefined roles when this patch is applied.  Maybe the role
>> attribute system should eventually be deprecated in favor of using
>> predefined roles for everything.  Or perhaps the predefined roles should be
>> converted to role attributes.
> 
> Yep, I was suggesting that the latter would have been preferable to me while
> Robert seemed to prefer the former. Honestly I could be happy with either of
> those solutions, but as I alluded to that is probably a discussion for the
> next development cycle since I don't see us doing that big a change in this
> one.

I agree.  I still think Joshua's proposed patch is a worthwhile improvement
for v15.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
@ 2022-02-10 19:37                                                 ` Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-02-10 19:37 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Robert Haas <robertmhaas@gmail.com>; Joshua Brindle <joshua.brindle@crunchydata.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On 2/10/22 14:28, Nathan Bossart wrote:
> On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
>> On 2/9/22 13:13, Nathan Bossart wrote:
>>> I do wonder if users find the differences between predefined roles and role
>>> attributes confusing.  INHERIT doesn't govern role attributes, but it will
>>> govern predefined roles when this patch is applied.  Maybe the role
>>> attribute system should eventually be deprecated in favor of using
>>> predefined roles for everything.  Or perhaps the predefined roles should be
>>> converted to role attributes.
>> 
>> Yep, I was suggesting that the latter would have been preferable to me while
>> Robert seemed to prefer the former. Honestly I could be happy with either of
>> those solutions, but as I alluded to that is probably a discussion for the
>> next development cycle since I don't see us doing that big a change in this
>> one.
> 
> I agree.  I still think Joshua's proposed patch is a worthwhile improvement
> for v15.

+1

I am planning to get into it in detail this weekend. So far I have 
really just ensured it merges cleanly and passes make world.

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-03-03 16:26                                                   ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joshua Brindle @ 2022-03-03 16:26 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com> wrote:
>
> On 2/10/22 14:28, Nathan Bossart wrote:
> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
> >> On 2/9/22 13:13, Nathan Bossart wrote:
> >>> I do wonder if users find the differences between predefined roles and role
> >>> attributes confusing.  INHERIT doesn't govern role attributes, but it will
> >>> govern predefined roles when this patch is applied.  Maybe the role
> >>> attribute system should eventually be deprecated in favor of using
> >>> predefined roles for everything.  Or perhaps the predefined roles should be
> >>> converted to role attributes.
> >>
> >> Yep, I was suggesting that the latter would have been preferable to me while
> >> Robert seemed to prefer the former. Honestly I could be happy with either of
> >> those solutions, but as I alluded to that is probably a discussion for the
> >> next development cycle since I don't see us doing that big a change in this
> >> one.
> >
> > I agree.  I still think Joshua's proposed patch is a worthwhile improvement
> > for v15.
>
> +1
>
> I am planning to get into it in detail this weekend. So far I have
> really just ensured it merges cleanly and passes make world.
>

Rebased patch to apply to master attached.

Attachments:

v5-0001-use-has_privs_for_roles-for-predefined-role-checks.patch (application/octet-stream, 27.7K) download From 6e6595511c22736664c7bfa5983782e061303c26 Mon Sep 17 00:00:00 2001 From: Joshua Brindle <joshua.brindle@crunchydata.com> Date: Tue, 26 Oct 2021 14:19:44 -0700 Subject: [PATCH] use has_privs_for_roles for predefined role checks Generally if a role is granted membership to another role with NOINHERIT they must use SET ROLE to access the privileges of that role, however with predefined roles the membership and privilege is conflated, as demonstrated by: CREATE ROLE readrole; CREATE ROLE role2 NOINHERIT; CREATE ROLE brindle LOGIN; GRANT role2 TO brindle; CREATE TABLE foo(i INT); GRANT readrole TO role2; GRANT ALL ON TABLE foo TO readrole; GRANT pg_read_all_stats,pg_read_all_settings,pg_read_server_files,pg_write_server_files,pg_execute_server_program TO role2; Log in as brindle: postgres=> select current_user; current_user -------------- brindle (1 row) postgres=> SELECT * FROM foo; ERROR: permission denied for table foo postgres=> SELECT DISTINCT query FROM pg_stat_activity; query ---------------------------------------------- SELECT DISTINCT query FROM pg_stat_activity; (2 rows) postgres=> SET ROLE readrole; SET postgres=> SELECT * FROM foo; i Signed-off-by: Joshua Brindle <joshua.brindle@crunchydata.com> --- contrib/adminpack/adminpack.c | 2 +- contrib/file_fdw/expected/file_fdw.out | 2 +- contrib/file_fdw/file_fdw.c | 8 ++++---- .../pg_stat_statements/pg_stat_statements.c | 4 ++-- contrib/pgrowlocks/pgrowlocks.c | 2 +- doc/src/sgml/adminpack.sgml | 6 +++--- doc/src/sgml/catalogs.sgml | 12 +++++------ doc/src/sgml/func.sgml | 12 +++++------ doc/src/sgml/monitoring.sgml | 2 +- doc/src/sgml/pgbuffercache.sgml | 2 +- doc/src/sgml/pgfreespacemap.sgml | 2 +- doc/src/sgml/pgrowlocks.sgml | 2 +- doc/src/sgml/pgstatstatements.sgml | 2 +- doc/src/sgml/pgvisibility.sgml | 4 ++-- src/backend/commands/copy.c | 12 +++++------ src/backend/replication/walreceiver.c | 8 ++++---- src/backend/replication/walsender.c | 8 ++++---- src/backend/utils/adt/acl.c | 4 ++++ src/backend/utils/adt/dbsize.c | 8 ++++---- src/backend/utils/adt/genfile.c | 6 +++--- src/backend/utils/adt/pgstatfuncs.c | 2 +- src/backend/utils/misc/guc.c | 20 +++++++++---------- .../unsafe_tests/expected/rolenames.out | 2 +- 23 files changed, 68 insertions(+), 64 deletions(-) diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c index d7d84d096f7..03addf1dc5f 100644 --- a/contrib/adminpack/adminpack.c +++ b/contrib/adminpack/adminpack.c @@ -79,7 +79,7 @@ convert_and_check_filename(text *arg) * files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) return filename; /* diff --git a/contrib/file_fdw/expected/file_fdw.out b/contrib/file_fdw/expected/file_fdw.out index 0ac6e4e0d73..14acdb27e5b 100644 --- a/contrib/file_fdw/expected/file_fdw.out +++ b/contrib/file_fdw/expected/file_fdw.out @@ -459,7 +459,7 @@ ALTER FOREIGN TABLE agg_text OWNER TO regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); SET ROLE regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); -ERROR: only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table +ERROR: only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table SET ROLE regress_file_fdw_superuser; -- cleanup RESET ROLE; diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index db08593d97f..4773cadec09 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -269,16 +269,16 @@ file_fdw_validator(PG_FUNCTION_ARGS) * otherwise there'd still be a security hole. */ if (strcmp(def->defname, "filename") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); if (strcmp(def->defname, "program") == 0 && - !is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + !has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("only superuser or a member of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); + errmsg("only superuser or a role with privileges of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); filename = defGetString(def); } diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index d803253ceaf..11dd673bdd5 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1507,8 +1507,8 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, HASH_SEQ_STATUS hash_seq; pgssEntry *entry; - /* Superusers or members of pg_read_all_stats members are allowed */ - is_allowed_role = is_member_of_role(userid, ROLE_PG_READ_ALL_STATS); + /* Superusers or roles with the privileges of pg_read_all_stats members are allowed */ + is_allowed_role = has_privs_of_role(userid, ROLE_PG_READ_ALL_STATS); /* hash table must exist already */ if (!pgss || !pgss_hash) diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index d8946dc5107..3dd8aa7bbe4 100644 --- a/contrib/pgrowlocks/pgrowlocks.c +++ b/contrib/pgrowlocks/pgrowlocks.c @@ -130,7 +130,7 @@ pgrowlocks(PG_FUNCTION_ARGS) aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), ACL_SELECT); if (aclresult != ACLCHECK_OK) - aclresult = is_member_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; + aclresult = has_privs_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), diff --git a/doc/src/sgml/adminpack.sgml b/doc/src/sgml/adminpack.sgml index 0dd89be3534..5702456cd25 100644 --- a/doc/src/sgml/adminpack.sgml +++ b/doc/src/sgml/adminpack.sgml @@ -22,9 +22,9 @@ functions in <xref linkend="functions-admin-genfile-table"/>, which provide read-only access.) Only files within the database cluster directory can be accessed, unless the - user is a superuser or given one of the pg_read_server_files, or pg_write_server_files - roles, as appropriate for the function, but either a relative or absolute path is - allowable. + user is a superuser or given privileges of one of the pg_read_server_files, + or pg_write_server_files roles, as appropriate for the function, but either a + relative or absolute path is allowable. </para> <table id="functions-adminpack-table"> diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 83987a99045..5e909536467 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -9978,8 +9978,8 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l <para> By default, the <structname>pg_backend_memory_contexts</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with the privileges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> @@ -12420,7 +12420,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Configuration file the current value was set in (null for values set from sources other than configuration files, or when - examined by a user who is neither a superuser or a member of + examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>); helpful when using <literal>include</literal> directives in configuration files </para></entry> @@ -12433,7 +12433,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> Line number within the configuration file the current value was set at (null for values set from sources other than configuration files, - or when examined by a user who is neither a superuser or a member of + or when examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>). </para></entry> </row> @@ -12809,8 +12809,8 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> By default, the <structname>pg_shmem_allocations</structname> view can be - read only by superusers or members of the <literal>pg_read_all_stats</literal> - role. + read only by superusers or roles with privileges of the + <literal>pg_read_all_stats</literal> role. </para> </sect1> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index df3cd5987b7..17fc4e8bbb0 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -25435,7 +25435,7 @@ SELECT collation for ('foo' COLLATE "de_DE"); Cancels the current query of the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being canceled or - the calling role has been granted <literal>pg_signal_backend</literal>, + the calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can cancel superuser backends. </para></entry> </row> @@ -25508,7 +25508,7 @@ SELECT collation for ('foo' COLLATE "de_DE"); Terminates the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being terminated or the - calling role has been granted <literal>pg_signal_backend</literal>, + calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can terminate superuser backends. </para> <para> @@ -26783,7 +26783,7 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup()); Computes the total disk space used by the database with the specified name or OID. To use this function, you must have <literal>CONNECT</literal> privilege on the specified database - (which is granted by default) or be a member of + (which is granted by default) or have privileges of the <literal>pg_read_all_stats</literal> role. </para></entry> </row> @@ -26913,7 +26913,7 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup()); Computes the total disk space used in the tablespace with the specified name or OID. To use this function, you must have <literal>CREATE</literal> privilege on the specified tablespace - or be a member of the <literal>pg_read_all_stats</literal> role, + or have privileges of the <literal>pg_read_all_stats</literal> role, unless it is the default tablespace for the current database. </para></entry> </row> @@ -27392,7 +27392,7 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size a dot, directories, and other special files are excluded. </para> <para> - This function is restricted to superusers and members of + This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> @@ -27416,7 +27416,7 @@ SELECT pg_size_pretty(sum(pg_relation_size(relid))) AS total_size are excluded. </para> <para> - This function is restricted to superusers and members of + This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 9fb62fec8ec..821d18c3e49 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -280,7 +280,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser (sessions belonging to a role that they are a member of). In rows about other sessions, many columns will be null. Note, however, that the existence of a session and its general properties such as its sessions user - and database are visible to all users. Superusers and members of the + and database are visible to all users. Superusers and roles with privileges of built-in role <literal>pg_read_all_stats</literal> (see also <xref linkend="predefined-roles"/>) can see all the information about all sessions. </para> diff --git a/doc/src/sgml/pgbuffercache.sgml b/doc/src/sgml/pgbuffercache.sgml index e68d159d30f..a06fd3e26de 100644 --- a/doc/src/sgml/pgbuffercache.sgml +++ b/doc/src/sgml/pgbuffercache.sgml @@ -24,7 +24,7 @@ </para> <para> - By default, use is restricted to superusers and members of the + By default, use is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgfreespacemap.sgml b/doc/src/sgml/pgfreespacemap.sgml index 5025498249d..0f3aebd27ef 100644 --- a/doc/src/sgml/pgfreespacemap.sgml +++ b/doc/src/sgml/pgfreespacemap.sgml @@ -16,7 +16,7 @@ </para> <para> - By default use is restricted to superusers and members of the + By default use is restricted to superusers and roles with privileges of the <literal>pg_stat_scan_tables</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgrowlocks.sgml b/doc/src/sgml/pgrowlocks.sgml index 392d5f1f9a7..2914bf6e6d6 100644 --- a/doc/src/sgml/pgrowlocks.sgml +++ b/doc/src/sgml/pgrowlocks.sgml @@ -13,7 +13,7 @@ </para> <para> - By default use is restricted to superusers, members of the + By default use is restricted to superusers, roles with privileges of the <literal>pg_stat_scan_tables</literal> role, and users with <literal>SELECT</literal> permissions on the table. </para> diff --git a/doc/src/sgml/pgstatstatements.sgml b/doc/src/sgml/pgstatstatements.sgml index bc9d5bdbe3b..3a7e36bd13c 100644 --- a/doc/src/sgml/pgstatstatements.sgml +++ b/doc/src/sgml/pgstatstatements.sgml @@ -384,7 +384,7 @@ </table> <para> - For security reasons, only superusers and members of the + For security reasons, only superusers and roles with privileges of the <literal>pg_read_all_stats</literal> role are allowed to see the SQL text and <structfield>queryid</structfield> of queries executed by other users. Other users can see the statistics, however, if the view has been installed diff --git a/doc/src/sgml/pgvisibility.sgml b/doc/src/sgml/pgvisibility.sgml index 75336946a61..8090aa5207e 100644 --- a/doc/src/sgml/pgvisibility.sgml +++ b/doc/src/sgml/pgvisibility.sgml @@ -140,8 +140,8 @@ </variablelist> <para> - By default, these functions are executable only by superusers and members of the - <literal>pg_stat_scan_tables</literal> role, with the exception of + By default, these functions are executable only by superusers and roles with privileges + of the <literal>pg_stat_scan_tables</literal> role, with the exception of <function>pg_truncate_visibility_map(relation regclass)</function> which can only be executed by superusers. </para> diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 7da7105d44b..7a0c897cc97 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -80,26 +80,26 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, { if (stmt->is_program) { - if (!is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_execute_server_program role to COPY to or from an external program"), + errmsg("must be superuser or have privileges of the pg_execute_server_program role to COPY to or from an external program"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } else { - if (is_from && !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (is_from && !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_read_server_files role to COPY from a file"), + errmsg("must be superuser or have privileges of the pg_read_server_files role to COPY from a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); - if (!is_from && !is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) + if (!is_from && !has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of the pg_write_server_files role to COPY to a file"), + errmsg("must be superuser or have privileges of the pg_write_server_files role to COPY to a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index ceaff097b97..3c9411e2213 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1403,12 +1403,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) /* Fetch values */ values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see details. - * Other users only get the pid value to know whether it is a WAL - * receiver, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know whether + * it is a WAL receiver, but no details. */ MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 5a718b1fe9b..98828e6e8c8 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -3499,12 +3499,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) memset(nulls, 0, sizeof(nulls)); values[0] = Int32GetDatum(pid); - if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* - * Only superusers and members of pg_read_all_stats can see - * details. Other users only get the pid value to know it's a - * walsender, but no details. + * Only superusers and roles with privileges of pg_read_all_stats + * can see details. Other users only get the pid value to know + * it's a walsender, but no details. */ MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1); } diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 0a16f8156cb..1d3dd8978bc 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -4864,6 +4864,8 @@ has_privs_of_role(Oid member, Oid role) * Is member a member of role (directly or indirectly)? * * This is defined to recurse through roles regardless of rolinherit. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role(Oid member, Oid role) @@ -4904,6 +4906,8 @@ check_is_member_of_role(Oid member, Oid role) * * This is identical to is_member_of_role except we ignore superuser * status. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role_nosuper(Oid member, Oid role) diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 3a2f2e1f99d..0576764ac4b 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -112,12 +112,12 @@ calculate_database_size(Oid dbOid) AclResult aclresult; /* - * User must have connect privilege for target database or be a member of + * User must have connect privilege for target database or have privileges of * pg_read_all_stats */ aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT); if (aclresult != ACLCHECK_OK && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclcheck_error(aclresult, OBJECT_DATABASE, get_database_name(dbOid)); @@ -196,12 +196,12 @@ calculate_tablespace_size(Oid tblspcOid) AclResult aclresult; /* - * User must be a member of pg_read_all_stats or have CREATE privilege for + * User must have privileges of pg_read_all_stats or have CREATE privilege for * target tablespace, either explicitly granted or implicitly because it * is default for current database. */ if (tblspcOid != MyDatabaseTableSpace && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE); if (aclresult != ACLCHECK_OK) diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index fe6863d8b44..7c89a861f82 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -59,11 +59,11 @@ convert_and_check_filename(text *arg) canonicalize_path(filename); /* filename can change length here */ /* - * Members of the 'pg_read_server_files' role are allowed to access any - * files on the server as the PG user, so no need to do any further checks + * Roles with privleges of the 'pg_read_server_files' role are allowed to access + * any files on the server as the PG user, so no need to do any further checks * here. */ - if (is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) + if (has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) return filename; /* diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index fd993d0d5fb..590739af467 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -34,7 +34,7 @@ #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) -#define HAS_PGSTAT_PERMISSIONS(role) (is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) +#define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 1e3650184b1..26ac23d8efe 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -8212,10 +8212,10 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged) return NULL; if (restrict_privileged && (record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -8259,10 +8259,10 @@ GetConfigOptionResetString(const char *name) record = find_option(name, false, false, ERROR); Assert(record != NULL); if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) @@ -9534,7 +9534,7 @@ ShowAllGUCConfig(DestReceiver *dest) if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* assign to the values array */ @@ -9601,7 +9601,7 @@ get_explain_guc_options(int *num) /* return only options visible to the current user */ if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* return only options that are different from their boot values */ @@ -9683,10 +9683,10 @@ GetConfigOptionByName(const char *name, const char **varname, bool missing_ok) } if ((record->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", + errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); if (varname) @@ -9753,7 +9753,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) { if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && - !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) *noshow = true; else *noshow = false; @@ -9948,7 +9948,7 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) * insufficiently-privileged users. */ if (conf->source == PGC_S_FILE && - is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) + has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) { values[14] = conf->sourcefile; snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); diff --git a/src/test/modules/unsafe_tests/expected/rolenames.out b/src/test/modules/unsafe_tests/expected/rolenames.out index eb608fdc2ea..88b1ff843be 100644 --- a/src/test/modules/unsafe_tests/expected/rolenames.out +++ b/src/test/modules/unsafe_tests/expected/rolenames.out @@ -1077,7 +1077,7 @@ SHOW session_preload_libraries; SET SESSION AUTHORIZATION regress_role_nopriv; -- fails with role not member of pg_read_all_settings SHOW session_preload_libraries; -ERROR: must be superuser or a member of pg_read_all_settings to examine "session_preload_libraries" +ERROR: must be superuser or have privileges of pg_read_all_settings to examine "session_preload_libraries" RESET SESSION AUTHORIZATION; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- 2.31.1
^ permalink raw reply [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2022-03-20 16:27                                                     ` Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-03-20 16:27 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On 3/3/22 11:26, Joshua Brindle wrote:
> On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com> wrote:
>>
>> On 2/10/22 14:28, Nathan Bossart wrote:
>> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
>> >> On 2/9/22 13:13, Nathan Bossart wrote:
>> >>> I do wonder if users find the differences between predefined roles and role
>> >>> attributes confusing.  INHERIT doesn't govern role attributes, but it will
>> >>> govern predefined roles when this patch is applied.  Maybe the role
>> >>> attribute system should eventually be deprecated in favor of using
>> >>> predefined roles for everything.  Or perhaps the predefined roles should be
>> >>> converted to role attributes.
>> >>
>> >> Yep, I was suggesting that the latter would have been preferable to me while
>> >> Robert seemed to prefer the former. Honestly I could be happy with either of
>> >> those solutions, but as I alluded to that is probably a discussion for the
>> >> next development cycle since I don't see us doing that big a change in this
>> >> one.
>> >
>> > I agree.  I still think Joshua's proposed patch is a worthwhile improvement
>> > for v15.
>>
>> +1
>>
>> I am planning to get into it in detail this weekend. So far I have
>> really just ensured it merges cleanly and passes make world.
> 
> Rebased patch to apply to master attached.

Well longer than I planned, but finally took a closer look.

I made one minor editorial fix to Joshua's patch, rebased to current 
master, and added two missing call sites that presumably are related to 
recent commits for pg_basebackup.

On that last note, I did not find basebackup_to_shell.required_role 
documented at all, and did not attempt to fix that.

When this thread petered out, it seemed that Robert was at least neutral 
on the patch, and everyone else was +1 on applying it to master for pg15.

As such, if there are any other issues, complaints, etc., please speak 
real soon now...

Thanks,

Joe

Attachments:

v6-0001-use-has_privs_for_roles-for-predefined-role-checks.patch (text/x-patch, 38.8K) download Use has_privs_for_roles for predefined role checks Generally if a role is granted membership to another role with NOINHERIT they must use SET ROLE to access the privileges of that role, however with predefined roles the membership and privilege is conflated. Fix that by replacing is_member_of_role with has_privs_for_role for predefined roles. Patch does not remove is_member_of_role from acl.h, but it does add a warning not to use that function for privilege checking. Not backpatched based on hackers list discussion. Author: Joshua Brindle Reviewed-by: Stephen Frost, Nathan Bossart, Joe Conway Discussion: https://postgr.es/m/flat/CAGB+Vh4Zv_TvKt2tv3QNS6tUM_F_9icmuj0zjywwcgVi4PAhFA@mail.gmail.com diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c index d7d84d0..03addf1 100644 *** a/contrib/adminpack/adminpack.c --- b/contrib/adminpack/adminpack.c *************** convert_and_check_filename(text *arg) *** 79,85 **** * files on the server as the PG user, so no need to do any further checks * here. */ ! if (is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) return filename; /* --- 79,85 ---- * files on the server as the PG user, so no need to do any further checks * here. */ ! if (has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) return filename; /* diff --git a/contrib/basebackup_to_shell/basebackup_to_shell.c b/contrib/basebackup_to_shell/basebackup_to_shell.c index d82cb6d..f0ddef1 100644 *** a/contrib/basebackup_to_shell/basebackup_to_shell.c --- b/contrib/basebackup_to_shell/basebackup_to_shell.c *************** _PG_init(void) *** 90,96 **** } /* ! * We choose to defer sanity sanity checking until shell_get_sink(), and so * just pass the target detail through without doing anything. However, we do * permissions checks here, before any real work has been done. */ --- 90,96 ---- } /* ! * We choose to defer sanity checking until shell_get_sink(), and so * just pass the target detail through without doing anything. However, we do * permissions checks here, before any real work has been done. */ *************** shell_check_detail(char *target, char *t *** 103,109 **** StartTransactionCommand(); roleid = get_role_oid(shell_required_role, true); ! if (!is_member_of_role(GetUserId(), roleid)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("permission denied to use basebackup_to_shell"))); --- 103,109 ---- StartTransactionCommand(); roleid = get_role_oid(shell_required_role, true); ! if (!has_privs_of_role(GetUserId(), roleid)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("permission denied to use basebackup_to_shell"))); diff --git a/contrib/file_fdw/expected/file_fdw.out b/contrib/file_fdw/expected/file_fdw.out index 0ac6e4e..14acdb2 100644 *** a/contrib/file_fdw/expected/file_fdw.out --- b/contrib/file_fdw/expected/file_fdw.out *************** ALTER FOREIGN TABLE agg_text OWNER TO re *** 459,465 **** ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); SET ROLE regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); ! ERROR: only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table SET ROLE regress_file_fdw_superuser; -- cleanup RESET ROLE; --- 459,465 ---- ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); SET ROLE regress_file_fdw_user; ALTER FOREIGN TABLE agg_text OPTIONS (SET format 'text'); ! ERROR: only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table SET ROLE regress_file_fdw_superuser; -- cleanup RESET ROLE; diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index db08593..4773cad 100644 *** a/contrib/file_fdw/file_fdw.c --- b/contrib/file_fdw/file_fdw.c *************** file_fdw_validator(PG_FUNCTION_ARGS) *** 269,284 **** * otherwise there'd still be a security hole. */ if (strcmp(def->defname, "filename") == 0 && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("only superuser or a member of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); if (strcmp(def->defname, "program") == 0 && ! !is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("only superuser or a member of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); filename = defGetString(def); } --- 269,284 ---- * otherwise there'd still be a security hole. */ if (strcmp(def->defname, "filename") == 0 && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table"))); if (strcmp(def->defname, "program") == 0 && ! !has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("only superuser or a role with privileges of the pg_execute_server_program role may specify the program option of a file_fdw foreign table"))); filename = defGetString(def); } diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 9e525a6..55786ae 100644 *** a/contrib/pg_stat_statements/pg_stat_statements.c --- b/contrib/pg_stat_statements/pg_stat_statements.c *************** pg_stat_statements_internal(FunctionCall *** 1503,1510 **** HASH_SEQ_STATUS hash_seq; pgssEntry *entry; ! /* Superusers or members of pg_read_all_stats members are allowed */ ! is_allowed_role = is_member_of_role(userid, ROLE_PG_READ_ALL_STATS); /* hash table must exist already */ if (!pgss || !pgss_hash) --- 1503,1510 ---- HASH_SEQ_STATUS hash_seq; pgssEntry *entry; ! /* Superusers or roles with the privileges of pg_read_all_stats members are allowed */ ! is_allowed_role = has_privs_of_role(userid, ROLE_PG_READ_ALL_STATS); /* hash table must exist already */ if (!pgss || !pgss_hash) diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index 713a165..1d4d496 100644 *** a/contrib/pgrowlocks/pgrowlocks.c --- b/contrib/pgrowlocks/pgrowlocks.c *************** pgrowlocks(PG_FUNCTION_ARGS) *** 104,110 **** aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), ACL_SELECT); if (aclresult != ACLCHECK_OK) ! aclresult = is_member_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), --- 104,110 ---- aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), ACL_SELECT); if (aclresult != ACLCHECK_OK) ! aclresult = has_privs_of_role(GetUserId(), ROLE_PG_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV; if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), diff --git a/doc/src/sgml/adminpack.sgml b/doc/src/sgml/adminpack.sgml index 0dd89be..5702456 100644 *** a/doc/src/sgml/adminpack.sgml --- b/doc/src/sgml/adminpack.sgml *************** *** 22,30 **** functions in <xref linkend="functions-admin-genfile-table"/>, which provide read-only access.) Only files within the database cluster directory can be accessed, unless the ! user is a superuser or given one of the pg_read_server_files, or pg_write_server_files ! roles, as appropriate for the function, but either a relative or absolute path is ! allowable. </para> <table id="functions-adminpack-table"> --- 22,30 ---- functions in <xref linkend="functions-admin-genfile-table"/>, which provide read-only access.) Only files within the database cluster directory can be accessed, unless the ! user is a superuser or given privileges of one of the pg_read_server_files, ! or pg_write_server_files roles, as appropriate for the function, but either a ! relative or absolute path is allowable. </para> <table id="functions-adminpack-table"> diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 4dc5b34..5010c63 100644 *** a/doc/src/sgml/catalogs.sgml --- b/doc/src/sgml/catalogs.sgml *************** SCRAM-SHA-256$<replaceable>&lt;iteration *** 10006,10013 **** <para> By default, the <structname>pg_backend_memory_contexts</structname> view can be ! read only by superusers or members of the <literal>pg_read_all_stats</literal> ! role. </para> </sect1> --- 10006,10013 ---- <para> By default, the <structname>pg_backend_memory_contexts</structname> view can be ! read only by superusers or roles with the privileges of the ! <literal>pg_read_all_stats</literal> role. </para> </sect1> *************** SELECT * FROM pg_locks pl LEFT JOIN pg_p *** 12448,12454 **** <para> Configuration file the current value was set in (null for values set from sources other than configuration files, or when ! examined by a user who is neither a superuser or a member of <literal>pg_read_all_settings</literal>); helpful when using <literal>include</literal> directives in configuration files </para></entry> --- 12448,12454 ---- <para> Configuration file the current value was set in (null for values set from sources other than configuration files, or when ! examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>); helpful when using <literal>include</literal> directives in configuration files </para></entry> *************** SELECT * FROM pg_locks pl LEFT JOIN pg_p *** 12461,12467 **** <para> Line number within the configuration file the current value was set at (null for values set from sources other than configuration files, ! or when examined by a user who is neither a superuser or a member of <literal>pg_read_all_settings</literal>). </para></entry> </row> --- 12461,12467 ---- <para> Line number within the configuration file the current value was set at (null for values set from sources other than configuration files, ! or when examined by a user who neither is a superuser nor has privileges of <literal>pg_read_all_settings</literal>). </para></entry> </row> *************** SELECT * FROM pg_locks pl LEFT JOIN pg_p *** 12837,12844 **** <para> By default, the <structname>pg_shmem_allocations</structname> view can be ! read only by superusers or members of the <literal>pg_read_all_stats</literal> ! role. </para> </sect1> --- 12837,12844 ---- <para> By default, the <structname>pg_shmem_allocations</structname> view can be ! read only by superusers or roles with privileges of the ! <literal>pg_read_all_stats</literal> role. </para> </sect1> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 8a802fb..3a9d62b 100644 *** a/doc/src/sgml/func.sgml --- b/doc/src/sgml/func.sgml *************** SELECT collation for ('foo' COLLATE "de_ *** 25435,25441 **** Cancels the current query of the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being canceled or ! the calling role has been granted <literal>pg_signal_backend</literal>, however only superusers can cancel superuser backends. </para></entry> </row> --- 25435,25441 ---- Cancels the current query of the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being canceled or ! the calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can cancel superuser backends. </para></entry> </row> *************** SELECT collation for ('foo' COLLATE "de_ *** 25508,25514 **** Terminates the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being terminated or the ! calling role has been granted <literal>pg_signal_backend</literal>, however only superusers can terminate superuser backends. </para> <para> --- 25508,25514 ---- Terminates the session whose backend process has the specified process ID. This is also allowed if the calling role is a member of the role whose backend is being terminated or the ! calling role has privileges of <literal>pg_signal_backend</literal>, however only superusers can terminate superuser backends. </para> <para> *************** postgres=# SELECT * FROM pg_walfile_name *** 26783,26789 **** Computes the total disk space used by the database with the specified name or OID. To use this function, you must have <literal>CONNECT</literal> privilege on the specified database ! (which is granted by default) or be a member of the <literal>pg_read_all_stats</literal> role. </para></entry> </row> --- 26783,26789 ---- Computes the total disk space used by the database with the specified name or OID. To use this function, you must have <literal>CONNECT</literal> privilege on the specified database ! (which is granted by default) or have privileges of the <literal>pg_read_all_stats</literal> role. </para></entry> </row> *************** postgres=# SELECT * FROM pg_walfile_name *** 26913,26919 **** Computes the total disk space used in the tablespace with the specified name or OID. To use this function, you must have <literal>CREATE</literal> privilege on the specified tablespace ! or be a member of the <literal>pg_read_all_stats</literal> role, unless it is the default tablespace for the current database. </para></entry> </row> --- 26913,26919 ---- Computes the total disk space used in the tablespace with the specified name or OID. To use this function, you must have <literal>CREATE</literal> privilege on the specified tablespace ! or have privileges of the <literal>pg_read_all_stats</literal> role, unless it is the default tablespace for the current database. </para></entry> </row> *************** SELECT pg_size_pretty(sum(pg_relation_si *** 27392,27398 **** a dot, directories, and other special files are excluded. </para> <para> ! This function is restricted to superusers and members of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> --- 27392,27398 ---- a dot, directories, and other special files are excluded. </para> <para> ! This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> *************** SELECT pg_size_pretty(sum(pg_relation_si *** 27416,27422 **** are excluded. </para> <para> ! This function is restricted to superusers and members of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> --- 27416,27422 ---- are excluded. </para> <para> ! This function is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role by default, but other users can be granted EXECUTE to run the function. </para></entry> diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 35b2923..6a6b09d 100644 *** a/doc/src/sgml/monitoring.sgml --- b/doc/src/sgml/monitoring.sgml *************** postgres 27093 0.0 0.0 30096 2752 *** 280,286 **** (sessions belonging to a role that they are a member of). In rows about other sessions, many columns will be null. Note, however, that the existence of a session and its general properties such as its sessions user ! and database are visible to all users. Superusers and members of the built-in role <literal>pg_read_all_stats</literal> (see also <xref linkend="predefined-roles"/>) can see all the information about all sessions. </para> --- 280,286 ---- (sessions belonging to a role that they are a member of). In rows about other sessions, many columns will be null. Note, however, that the existence of a session and its general properties such as its sessions user ! and database are visible to all users. Superusers and roles with privileges of built-in role <literal>pg_read_all_stats</literal> (see also <xref linkend="predefined-roles"/>) can see all the information about all sessions. </para> diff --git a/doc/src/sgml/pgbuffercache.sgml b/doc/src/sgml/pgbuffercache.sgml index e68d159..a06fd3e 100644 *** a/doc/src/sgml/pgbuffercache.sgml --- b/doc/src/sgml/pgbuffercache.sgml *************** *** 24,30 **** </para> <para> ! By default, use is restricted to superusers and members of the <literal>pg_monitor</literal> role. Access may be granted to others using <command>GRANT</command>. </para> --- 24,30 ---- </para> <para> ! By default, use is restricted to superusers and roles with privileges of the <literal>pg_monitor</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgfreespacemap.sgml b/doc/src/sgml/pgfreespacemap.sgml index 1f7867d..3063885 100644 *** a/doc/src/sgml/pgfreespacemap.sgml --- b/doc/src/sgml/pgfreespacemap.sgml *************** *** 16,22 **** </para> <para> ! By default use is restricted to superusers and members of the <literal>pg_stat_scan_tables</literal> role. Access may be granted to others using <command>GRANT</command>. </para> --- 16,22 ---- </para> <para> ! By default use is restricted to superusers and roles with privileges of the <literal>pg_stat_scan_tables</literal> role. Access may be granted to others using <command>GRANT</command>. </para> diff --git a/doc/src/sgml/pgrowlocks.sgml b/doc/src/sgml/pgrowlocks.sgml index 392d5f1..2914bf6 100644 *** a/doc/src/sgml/pgrowlocks.sgml --- b/doc/src/sgml/pgrowlocks.sgml *************** *** 13,19 **** </para> <para> ! By default use is restricted to superusers, members of the <literal>pg_stat_scan_tables</literal> role, and users with <literal>SELECT</literal> permissions on the table. </para> --- 13,19 ---- </para> <para> ! By default use is restricted to superusers, roles with privileges of the <literal>pg_stat_scan_tables</literal> role, and users with <literal>SELECT</literal> permissions on the table. </para> diff --git a/doc/src/sgml/pgstatstatements.sgml b/doc/src/sgml/pgstatstatements.sgml index bc9d5bd..3a7e36b 100644 *** a/doc/src/sgml/pgstatstatements.sgml --- b/doc/src/sgml/pgstatstatements.sgml *************** *** 384,390 **** </table> <para> ! For security reasons, only superusers and members of the <literal>pg_read_all_stats</literal> role are allowed to see the SQL text and <structfield>queryid</structfield> of queries executed by other users. Other users can see the statistics, however, if the view has been installed --- 384,390 ---- </table> <para> ! For security reasons, only superusers and roles with privileges of the <literal>pg_read_all_stats</literal> role are allowed to see the SQL text and <structfield>queryid</structfield> of queries executed by other users. Other users can see the statistics, however, if the view has been installed diff --git a/doc/src/sgml/pgvisibility.sgml b/doc/src/sgml/pgvisibility.sgml index 7533694..8090aa5 100644 *** a/doc/src/sgml/pgvisibility.sgml --- b/doc/src/sgml/pgvisibility.sgml *************** *** 140,147 **** </variablelist> <para> ! By default, these functions are executable only by superusers and members of the ! <literal>pg_stat_scan_tables</literal> role, with the exception of <function>pg_truncate_visibility_map(relation regclass)</function> which can only be executed by superusers. </para> --- 140,147 ---- </variablelist> <para> ! By default, these functions are executable only by superusers and roles with privileges ! of the <literal>pg_stat_scan_tables</literal> role, with the exception of <function>pg_truncate_visibility_map(relation regclass)</function> which can only be executed by superusers. </para> diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml index 4a630b5..36baafd 100644 *** a/doc/src/sgml/ref/pg_basebackup.sgml --- b/doc/src/sgml/ref/pg_basebackup.sgml *************** PostgreSQL documentation *** 237,243 **** <literal>server:/some/path</literal>, the backup will be stored on the machine where the server is running in the <literal>/some/path</literal> directory. Storing a backup on the ! server requires superuser privileges or being granted the <literal>pg_write_server_files</literal> role. If the target is set to <literal>blackhole</literal>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you --- 237,243 ---- <literal>server:/some/path</literal>, the backup will be stored on the machine where the server is running in the <literal>/some/path</literal> directory. Storing a backup on the ! server requires superuser privileges or having privileges of the <literal>pg_write_server_files</literal> role. If the target is set to <literal>blackhole</literal>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 7da7105..7a0c897 100644 *** a/src/backend/commands/copy.c --- b/src/backend/commands/copy.c *************** DoCopy(ParseState *pstate, const CopyStm *** 80,105 **** { if (stmt->is_program) { ! if (!is_member_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a member of the pg_execute_server_program role to COPY to or from an external program"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } else { ! if (is_from && !is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a member of the pg_read_server_files role to COPY from a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); ! if (!is_from && !is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a member of the pg_write_server_files role to COPY to a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } --- 80,105 ---- { if (stmt->is_program) { ! if (!has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or have privileges of the pg_execute_server_program role to COPY to or from an external program"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } else { ! if (is_from && !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or have privileges of the pg_read_server_files role to COPY from a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); ! if (!is_from && !has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or have privileges of the pg_write_server_files role to COPY to a file"), errhint("Anyone can COPY to stdout or from stdin. " "psql's \\copy command also works for anyone."))); } diff --git a/src/backend/replication/basebackup_server.c b/src/backend/replication/basebackup_server.c index a878629..bc16897 100644 *** a/src/backend/replication/basebackup_server.c --- b/src/backend/replication/basebackup_server.c *************** bbsink_server_new(bbsink *next, char *pa *** 69,78 **** /* Replication permission is not sufficient in this case. */ StartTransactionCommand(); ! if (!is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a member of the pg_write_server_files role to create server backup"))); CommitTransactionCommand(); /* --- 69,78 ---- /* Replication permission is not sufficient in this case. */ StartTransactionCommand(); ! if (!has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a role with privileges of the pg_write_server_files role to create server backup"))); CommitTransactionCommand(); /* diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index ceaff09..3c9411e 100644 *** a/src/backend/replication/walreceiver.c --- b/src/backend/replication/walreceiver.c *************** pg_stat_get_wal_receiver(PG_FUNCTION_ARG *** 1403,1414 **** /* Fetch values */ values[0] = Int32GetDatum(pid); ! if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* ! * Only superusers and members of pg_read_all_stats can see details. ! * Other users only get the pid value to know whether it is a WAL ! * receiver, but no details. */ MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } --- 1403,1414 ---- /* Fetch values */ values[0] = Int32GetDatum(pid); ! if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* ! * Only superusers and roles with privileges of pg_read_all_stats ! * can see details. Other users only get the pid value to know whether ! * it is a WAL receiver, but no details. */ MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 2d0292a..cffb348 100644 *** a/src/backend/replication/walsender.c --- b/src/backend/replication/walsender.c *************** pg_stat_get_wal_senders(PG_FUNCTION_ARGS *** 3473,3484 **** memset(nulls, 0, sizeof(nulls)); values[0] = Int32GetDatum(pid); ! if (!is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* ! * Only superusers and members of pg_read_all_stats can see ! * details. Other users only get the pid value to know it's a ! * walsender, but no details. */ MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1); } --- 3473,3484 ---- memset(nulls, 0, sizeof(nulls)); values[0] = Int32GetDatum(pid); ! if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* ! * Only superusers and roles with privileges of pg_read_all_stats ! * can see details. Other users only get the pid value to know ! * it's a walsender, but no details. */ MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1); } diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 0a16f81..1d3dd89 100644 *** a/src/backend/utils/adt/acl.c --- b/src/backend/utils/adt/acl.c *************** has_privs_of_role(Oid member, Oid role) *** 4864,4869 **** --- 4864,4871 ---- * Is member a member of role (directly or indirectly)? * * This is defined to recurse through roles regardless of rolinherit. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role(Oid member, Oid role) *************** check_is_member_of_role(Oid member, Oid *** 4904,4909 **** --- 4906,4913 ---- * * This is identical to is_member_of_role except we ignore superuser * status. + * + * Do not use this for privilege checking, instead use has_privs_of_role() */ bool is_member_of_role_nosuper(Oid member, Oid role) diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 3a2f2e1..0576764 100644 *** a/src/backend/utils/adt/dbsize.c --- b/src/backend/utils/adt/dbsize.c *************** calculate_database_size(Oid dbOid) *** 112,123 **** AclResult aclresult; /* ! * User must have connect privilege for target database or be a member of * pg_read_all_stats */ aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT); if (aclresult != ACLCHECK_OK && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclcheck_error(aclresult, OBJECT_DATABASE, get_database_name(dbOid)); --- 112,123 ---- AclResult aclresult; /* ! * User must have connect privilege for target database or have privileges of * pg_read_all_stats */ aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT); if (aclresult != ACLCHECK_OK && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclcheck_error(aclresult, OBJECT_DATABASE, get_database_name(dbOid)); *************** calculate_tablespace_size(Oid tblspcOid) *** 196,207 **** AclResult aclresult; /* ! * User must be a member of pg_read_all_stats or have CREATE privilege for * target tablespace, either explicitly granted or implicitly because it * is default for current database. */ if (tblspcOid != MyDatabaseTableSpace && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE); if (aclresult != ACLCHECK_OK) --- 196,207 ---- AclResult aclresult; /* ! * User must have privileges of pg_read_all_stats or have CREATE privilege for * target tablespace, either explicitly granted or implicitly because it * is default for current database. */ if (tblspcOid != MyDatabaseTableSpace && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE); if (aclresult != ACLCHECK_OK) diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index 1ed0162..88f279d 100644 *** a/src/backend/utils/adt/genfile.c --- b/src/backend/utils/adt/genfile.c *************** convert_and_check_filename(text *arg) *** 59,69 **** canonicalize_path(filename); /* filename can change length here */ /* ! * Members of the 'pg_read_server_files' role are allowed to access any ! * files on the server as the PG user, so no need to do any further checks * here. */ ! if (is_member_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) return filename; /* --- 59,69 ---- canonicalize_path(filename); /* filename can change length here */ /* ! * Roles with privleges of the 'pg_read_server_files' role are allowed to access ! * any files on the server as the PG user, so no need to do any further checks * here. */ ! if (has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES)) return filename; /* diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index eff45b1..ce84525 100644 *** a/src/backend/utils/adt/pgstatfuncs.c --- b/src/backend/utils/adt/pgstatfuncs.c *************** *** 34,40 **** #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) ! #define HAS_PGSTAT_PERMISSIONS(role) (is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) --- 34,40 ---- #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) ! #define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role)) Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index e7f0a38..c3ef798 100644 *** a/src/backend/utils/misc/guc.c --- b/src/backend/utils/misc/guc.c *************** GetConfigOption(const char *name, bool m *** 8215,8224 **** return NULL; if (restrict_privileged && (record->flags & GUC_SUPERUSER_ONLY) && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) --- 8215,8224 ---- return NULL; if (restrict_privileged && (record->flags & GUC_SUPERUSER_ONLY) && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) *************** GetConfigOptionResetString(const char *n *** 8262,8271 **** record = find_option(name, false, false, ERROR); Assert(record != NULL); if ((record->flags & GUC_SUPERUSER_ONLY) && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) --- 8262,8271 ---- record = find_option(name, false, false, ERROR); Assert(record != NULL); if ((record->flags & GUC_SUPERUSER_ONLY) && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); switch (record->vartype) *************** ShowAllGUCConfig(DestReceiver *dest) *** 9537,9543 **** if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* assign to the values array */ --- 9537,9543 ---- if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* assign to the values array */ *************** get_explain_guc_options(int *num) *** 9604,9610 **** /* return only options visible to the current user */ if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* return only options that are different from their boot values */ --- 9604,9610 ---- /* return only options visible to the current user */ if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) continue; /* return only options that are different from their boot values */ *************** GetConfigOptionByName(const char *name, *** 9686,9695 **** } if ((record->flags & GUC_SUPERUSER_ONLY) && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"", name))); if (varname) --- 9686,9695 ---- } if ((record->flags & GUC_SUPERUSER_ONLY) && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or have privileges of pg_read_all_settings to examine \"%s\"", name))); if (varname) *************** GetConfigOptionByNum(int varnum, const c *** 9756,9762 **** { if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && ! !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) *noshow = true; else *noshow = false; --- 9756,9762 ---- { if ((conf->flags & GUC_NO_SHOW_ALL) || ((conf->flags & GUC_SUPERUSER_ONLY) && ! !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))) *noshow = true; else *noshow = false; *************** GetConfigOptionByNum(int varnum, const c *** 9951,9957 **** * insufficiently-privileged users. */ if (conf->source == PGC_S_FILE && ! is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) { values[14] = conf->sourcefile; snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); --- 9951,9957 ---- * insufficiently-privileged users. */ if (conf->source == PGC_S_FILE && ! has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) { values[14] = conf->sourcefile; snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); diff --git a/src/test/modules/unsafe_tests/expected/rolenames.out b/src/test/modules/unsafe_tests/expected/rolenames.out index eb608fd..88b1ff8 100644 *** a/src/test/modules/unsafe_tests/expected/rolenames.out --- b/src/test/modules/unsafe_tests/expected/rolenames.out *************** SHOW session_preload_libraries; *** 1077,1083 **** SET SESSION AUTHORIZATION regress_role_nopriv; -- fails with role not member of pg_read_all_settings SHOW session_preload_libraries; ! ERROR: must be superuser or a member of pg_read_all_settings to examine "session_preload_libraries" RESET SESSION AUTHORIZATION; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; --- 1077,1083 ---- SET SESSION AUTHORIZATION regress_role_nopriv; -- fails with role not member of pg_read_all_settings SHOW session_preload_libraries; ! ERROR: must be superuser or have privileges of pg_read_all_settings to examine "session_preload_libraries" RESET SESSION AUTHORIZATION; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK;
^ permalink raw reply [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-03-20 16:31                                                       ` Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:34                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:38                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  0 siblings, 2 replies; 42+ messages in thread

From: Joshua Brindle @ 2022-03-20 16:31 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Sun, Mar 20, 2022 at 12:27 PM Joe Conway <mail@joeconway.com> wrote:
>
> On 3/3/22 11:26, Joshua Brindle wrote:
> > On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com> wrote:
> >>
> >> On 2/10/22 14:28, Nathan Bossart wrote:
> >> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
> >> >> On 2/9/22 13:13, Nathan Bossart wrote:
> >> >>> I do wonder if users find the differences between predefined roles and role
> >> >>> attributes confusing.  INHERIT doesn't govern role attributes, but it will
> >> >>> govern predefined roles when this patch is applied.  Maybe the role
> >> >>> attribute system should eventually be deprecated in favor of using
> >> >>> predefined roles for everything.  Or perhaps the predefined roles should be
> >> >>> converted to role attributes.
> >> >>
> >> >> Yep, I was suggesting that the latter would have been preferable to me while
> >> >> Robert seemed to prefer the former. Honestly I could be happy with either of
> >> >> those solutions, but as I alluded to that is probably a discussion for the
> >> >> next development cycle since I don't see us doing that big a change in this
> >> >> one.
> >> >
> >> > I agree.  I still think Joshua's proposed patch is a worthwhile improvement
> >> > for v15.
> >>
> >> +1
> >>
> >> I am planning to get into it in detail this weekend. So far I have
> >> really just ensured it merges cleanly and passes make world.
> >
> > Rebased patch to apply to master attached.
>
> Well longer than I planned, but finally took a closer look.
>
> I made one minor editorial fix to Joshua's patch, rebased to current
> master, and added two missing call sites that presumably are related to
> recent commits for pg_basebackup.

FWIW I pinged Stephen when I saw the basebackup changes included
is_member_of and he didn't think they necessarily needed to be changed
since they aren't accessible to human and you can't SET ROLE on a
replication connection in order to access the role where inheritance
was blocked.

> On that last note, I did not find basebackup_to_shell.required_role
> documented at all, and did not attempt to fix that.
>
> When this thread petered out, it seemed that Robert was at least neutral
> on the patch, and everyone else was +1 on applying it to master for pg15.
>
> As such, if there are any other issues, complaints, etc., please speak
> real soon now...
>
> Thanks,
>
> Joe





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2022-03-20 16:34                                                         ` Joe Conway <mail@joeconway.com>
  2022-03-20 16:37                                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  1 sibling, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-03-20 16:34 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On 3/20/22 12:31, Joshua Brindle wrote:
> On Sun, Mar 20, 2022 at 12:27 PM Joe Conway <mail@joeconway.com> wrote:
>>
>> On 3/3/22 11:26, Joshua Brindle wrote:
>> > On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com> wrote:
>> >>
>> >> On 2/10/22 14:28, Nathan Bossart wrote:
>> >> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
>> >> >> On 2/9/22 13:13, Nathan Bossart wrote:
>> >> >>> I do wonder if users find the differences between predefined roles and role
>> >> >>> attributes confusing.  INHERIT doesn't govern role attributes, but it will
>> >> >>> govern predefined roles when this patch is applied.  Maybe the role
>> >> >>> attribute system should eventually be deprecated in favor of using
>> >> >>> predefined roles for everything.  Or perhaps the predefined roles should be
>> >> >>> converted to role attributes.
>> >> >>
>> >> >> Yep, I was suggesting that the latter would have been preferable to me while
>> >> >> Robert seemed to prefer the former. Honestly I could be happy with either of
>> >> >> those solutions, but as I alluded to that is probably a discussion for the
>> >> >> next development cycle since I don't see us doing that big a change in this
>> >> >> one.
>> >> >
>> >> > I agree.  I still think Joshua's proposed patch is a worthwhile improvement
>> >> > for v15.
>> >>
>> >> +1
>> >>
>> >> I am planning to get into it in detail this weekend. So far I have
>> >> really just ensured it merges cleanly and passes make world.
>> >
>> > Rebased patch to apply to master attached.
>>
>> Well longer than I planned, but finally took a closer look.
>>
>> I made one minor editorial fix to Joshua's patch, rebased to current
>> master, and added two missing call sites that presumably are related to
>> recent commits for pg_basebackup.
> 
> FWIW I pinged Stephen when I saw the basebackup changes included
> is_member_of and he didn't think they necessarily needed to be changed
> since they aren't accessible to human and you can't SET ROLE on a
> replication connection in order to access the role where inheritance
> was blocked.

Maybe worth a discussion, but it seems strange to me to treat them 
differently when the whole purpose of this patch is to make things 
consistent ¯\_(ツ)_/¯

Joe





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:34                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-03-20 16:37                                                           ` Joshua Brindle <joshua.brindle@crunchydata.com>
  0 siblings, 0 replies; 42+ messages in thread

From: Joshua Brindle @ 2022-03-20 16:37 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Bossart, Nathan <bossartn@amazon.com>; Stephen Frost <sfrost@snowman.net>; pgsql-hackers

On Sun, Mar 20, 2022 at 12:34 PM Joe Conway <mail@joeconway.com> wrote:
>
> On 3/20/22 12:31, Joshua Brindle wrote:
> > On Sun, Mar 20, 2022 at 12:27 PM Joe Conway <mail@joeconway.com> wrote:
> >>
> >> On 3/3/22 11:26, Joshua Brindle wrote:
> >> > On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com> wrote:
> >> >>
> >> >> On 2/10/22 14:28, Nathan Bossart wrote:
> >> >> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
> >> >> >> On 2/9/22 13:13, Nathan Bossart wrote:
> >> >> >>> I do wonder if users find the differences between predefined roles and role
> >> >> >>> attributes confusing.  INHERIT doesn't govern role attributes, but it will
> >> >> >>> govern predefined roles when this patch is applied.  Maybe the role
> >> >> >>> attribute system should eventually be deprecated in favor of using
> >> >> >>> predefined roles for everything.  Or perhaps the predefined roles should be
> >> >> >>> converted to role attributes.
> >> >> >>
> >> >> >> Yep, I was suggesting that the latter would have been preferable to me while
> >> >> >> Robert seemed to prefer the former. Honestly I could be happy with either of
> >> >> >> those solutions, but as I alluded to that is probably a discussion for the
> >> >> >> next development cycle since I don't see us doing that big a change in this
> >> >> >> one.
> >> >> >
> >> >> > I agree.  I still think Joshua's proposed patch is a worthwhile improvement
> >> >> > for v15.
> >> >>
> >> >> +1
> >> >>
> >> >> I am planning to get into it in detail this weekend. So far I have
> >> >> really just ensured it merges cleanly and passes make world.
> >> >
> >> > Rebased patch to apply to master attached.
> >>
> >> Well longer than I planned, but finally took a closer look.
> >>
> >> I made one minor editorial fix to Joshua's patch, rebased to current
> >> master, and added two missing call sites that presumably are related to
> >> recent commits for pg_basebackup.
> >
> > FWIW I pinged Stephen when I saw the basebackup changes included
> > is_member_of and he didn't think they necessarily needed to be changed
> > since they aren't accessible to human and you can't SET ROLE on a
> > replication connection in order to access the role where inheritance
> > was blocked.
>
> Maybe worth a discussion, but it seems strange to me to treat them
> differently when the whole purpose of this patch is to make things
> consistent ¯\_(ツ)_/¯
>

I don't have a strong opinion either way, just noting that it's a
possible exception area due to how it is used.

Thanks for committing this.





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
@ 2022-03-20 16:38                                                         ` Stephen Frost <sfrost@snowman.net>
  2022-03-21 20:15                                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  1 sibling, 1 reply; 42+ messages in thread

From: Stephen Frost @ 2022-03-20 16:38 UTC (permalink / raw)
  To: Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Bossart, Nathan <bossartn@amazon.com>; Joe Conway <mail@joeconway.com>; Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>

Greetings,

On Sun, Mar 20, 2022 at 18:31 Joshua Brindle <joshua.brindle@crunchydata.com>
wrote:

> On Sun, Mar 20, 2022 at 12:27 PM Joe Conway <mail@joeconway.com> wrote:
> >
> > On 3/3/22 11:26, Joshua Brindle wrote:
> > > On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com> wrote:
> > >>
> > >> On 2/10/22 14:28, Nathan Bossart wrote:
> > >> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
> > >> >> On 2/9/22 13:13, Nathan Bossart wrote:
> > >> >>> I do wonder if users find the differences between predefined
> roles and role
> > >> >>> attributes confusing.  INHERIT doesn't govern role attributes,
> but it will
> > >> >>> govern predefined roles when this patch is applied.  Maybe the
> role
> > >> >>> attribute system should eventually be deprecated in favor of using
> > >> >>> predefined roles for everything.  Or perhaps the predefined roles
> should be
> > >> >>> converted to role attributes.
> > >> >>
> > >> >> Yep, I was suggesting that the latter would have been preferable
> to me while
> > >> >> Robert seemed to prefer the former. Honestly I could be happy with
> either of
> > >> >> those solutions, but as I alluded to that is probably a discussion
> for the
> > >> >> next development cycle since I don't see us doing that big a
> change in this
> > >> >> one.
> > >> >
> > >> > I agree.  I still think Joshua's proposed patch is a worthwhile
> improvement
> > >> > for v15.
> > >>
> > >> +1
> > >>
> > >> I am planning to get into it in detail this weekend. So far I have
> > >> really just ensured it merges cleanly and passes make world.
> > >
> > > Rebased patch to apply to master attached.
> >
> > Well longer than I planned, but finally took a closer look.
> >
> > I made one minor editorial fix to Joshua's patch, rebased to current
> > master, and added two missing call sites that presumably are related to
> > recent commits for pg_basebackup.
>
> FWIW I pinged Stephen when I saw the basebackup changes included
> is_member_of and he didn't think they necessarily needed to be changed
> since they aren't accessible to human and you can't SET ROLE on a
> replication connection in order to access the role where inheritance
> was blocked.


Yeah, though that should really be very clearly explained in comments
around that code as anything that uses is_member should really be viewed as
an exception.  I also wouldn’t be against using has_privs there anyway and
saying that you shouldn’t be trying to connect as one role on a replication
connection and using the privs of another when you don’t automatically
inherit those rights, but on the assumption that the committer intended
is_member there because SET ROLE isn’t something one does on replication
connections, I’m alright with it being as is.

Kind Regards,

Stephen P Frost

>

^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:38                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
@ 2022-03-21 20:15                                                           ` Joe Conway <mail@joeconway.com>
  2022-03-28 19:31                                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-28 19:56                                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  0 siblings, 2 replies; 42+ messages in thread

From: Joe Conway @ 2022-03-21 20:15 UTC (permalink / raw)
  To: Stephen Frost <sfrost@snowman.net>; Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Bossart, Nathan <bossartn@amazon.com>; Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>

On 3/20/22 12:38, Stephen Frost wrote:
> Greetings,
> 
> On Sun, Mar 20, 2022 at 18:31 Joshua Brindle 
> <joshua.brindle@crunchydata.com <mailto:joshua.brindle@crunchydata.com>> 
> wrote:
> 
>     On Sun, Mar 20, 2022 at 12:27 PM Joe Conway <mail@joeconway.com
>     <mailto:mail@joeconway.com>> wrote:
>      >
>      > On 3/3/22 11:26, Joshua Brindle wrote:
>      > > On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com
>     <mailto:mail@joeconway.com>> wrote:
>      > >>
>      > >> On 2/10/22 14:28, Nathan Bossart wrote:
>      > >> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
>      > >> >> On 2/9/22 13:13, Nathan Bossart wrote:
>      > >> >>> I do wonder if users find the differences between
>     predefined roles and role
>      > >> >>> attributes confusing.  INHERIT doesn't govern role
>     attributes, but it will
>      > >> >>> govern predefined roles when this patch is applied.  Maybe
>     the role
>      > >> >>> attribute system should eventually be deprecated in favor
>     of using
>      > >> >>> predefined roles for everything.  Or perhaps the
>     predefined roles should be
>      > >> >>> converted to role attributes.
>      > >> >>
>      > >> >> Yep, I was suggesting that the latter would have been
>     preferable to me while
>      > >> >> Robert seemed to prefer the former. Honestly I could be
>     happy with either of
>      > >> >> those solutions, but as I alluded to that is probably a
>     discussion for the
>      > >> >> next development cycle since I don't see us doing that big
>     a change in this
>      > >> >> one.
>      > >> >
>      > >> > I agree.  I still think Joshua's proposed patch is a
>     worthwhile improvement
>      > >> > for v15.
>      > >>
>      > >> +1
>      > >>
>      > >> I am planning to get into it in detail this weekend. So far I have
>      > >> really just ensured it merges cleanly and passes make world.
>      > >
>      > > Rebased patch to apply to master attached.
>      >
>      > Well longer than I planned, but finally took a closer look.
>      >
>      > I made one minor editorial fix to Joshua's patch, rebased to current
>      > master, and added two missing call sites that presumably are
>     related to
>      > recent commits for pg_basebackup.
> 
>     FWIW I pinged Stephen when I saw the basebackup changes included
>     is_member_of and he didn't think they necessarily needed to be changed
>     since they aren't accessible to human and you can't SET ROLE on a
>     replication connection in order to access the role where inheritance
>     was blocked.
> 
> Yeah, though that should really be very clearly explained in comments 
> around that code as anything that uses is_member should really be viewed 
> as an exception.  I also wouldn’t be against using has_privs there 
> anyway and saying that you shouldn’t be trying to connect as one role on 
> a replication connection and using the privs of another when you don’t 
> automatically inherit those rights, but on the assumption that the 
> committer intended is_member there because SET ROLE isn’t something one 
> does on replication connections, I’m alright with it being as is.


Robert -- any opinion on this? If I am not mistaken it is code that you 
are actively working on.

Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:38                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2022-03-21 20:15                                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-03-28 19:31                                                             ` Joe Conway <mail@joeconway.com>
  1 sibling, 0 replies; 42+ messages in thread

From: Joe Conway @ 2022-03-28 19:31 UTC (permalink / raw)
  To: Stephen Frost <sfrost@snowman.net>; Joshua Brindle <joshua.brindle@crunchydata.com>; +Cc: Bossart, Nathan <bossartn@amazon.com>; Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>

On 3/21/22 16:15, Joe Conway wrote:
> On 3/20/22 12:38, Stephen Frost wrote:
>> Greetings,
>> 
>> On Sun, Mar 20, 2022 at 18:31 Joshua Brindle 
>> <joshua.brindle@crunchydata.com <mailto:joshua.brindle@crunchydata.com>> 
>> wrote:
>> 
>>     On Sun, Mar 20, 2022 at 12:27 PM Joe Conway <mail@joeconway.com
>>     <mailto:mail@joeconway.com>> wrote:
>>      >
>>      > On 3/3/22 11:26, Joshua Brindle wrote:
>>      > > On Thu, Feb 10, 2022 at 2:37 PM Joe Conway <mail@joeconway.com
>>     <mailto:mail@joeconway.com>> wrote:
>>      > >>
>>      > >> On 2/10/22 14:28, Nathan Bossart wrote:
>>      > >> > On Wed, Feb 09, 2022 at 04:39:11PM -0500, Joe Conway wrote:
>>      > >> >> On 2/9/22 13:13, Nathan Bossart wrote:
>>      > >> >>> I do wonder if users find the differences between
>>     predefined roles and role
>>      > >> >>> attributes confusing.  INHERIT doesn't govern role
>>     attributes, but it will
>>      > >> >>> govern predefined roles when this patch is applied.  Maybe
>>     the role
>>      > >> >>> attribute system should eventually be deprecated in favor
>>     of using
>>      > >> >>> predefined roles for everything.  Or perhaps the
>>     predefined roles should be
>>      > >> >>> converted to role attributes.
>>      > >> >>
>>      > >> >> Yep, I was suggesting that the latter would have been
>>     preferable to me while
>>      > >> >> Robert seemed to prefer the former. Honestly I could be
>>     happy with either of
>>      > >> >> those solutions, but as I alluded to that is probably a
>>     discussion for the
>>      > >> >> next development cycle since I don't see us doing that big
>>     a change in this
>>      > >> >> one.
>>      > >> >
>>      > >> > I agree.  I still think Joshua's proposed patch is a
>>     worthwhile improvement
>>      > >> > for v15.
>>      > >>
>>      > >> +1
>>      > >>
>>      > >> I am planning to get into it in detail this weekend. So far I have
>>      > >> really just ensured it merges cleanly and passes make world.
>>      > >
>>      > > Rebased patch to apply to master attached.
>>      >
>>      > Well longer than I planned, but finally took a closer look.
>>      >
>>      > I made one minor editorial fix to Joshua's patch, rebased to current
>>      > master, and added two missing call sites that presumably are
>>     related to
>>      > recent commits for pg_basebackup.
>> 
>>     FWIW I pinged Stephen when I saw the basebackup changes included
>>     is_member_of and he didn't think they necessarily needed to be changed
>>     since they aren't accessible to human and you can't SET ROLE on a
>>     replication connection in order to access the role where inheritance
>>     was blocked.
>> 
>> Yeah, though that should really be very clearly explained in comments 
>> around that code as anything that uses is_member should really be viewed 
>> as an exception.  I also wouldn’t be against using has_privs there 
>> anyway and saying that you shouldn’t be trying to connect as one role on 
>> a replication connection and using the privs of another when you don’t 
>> automatically inherit those rights, but on the assumption that the 
>> committer intended is_member there because SET ROLE isn’t something one 
>> does on replication connections, I’m alright with it being as is.
> 
> 
> Robert -- any opinion on this? If I am not mistaken it is code that you
> are actively working on.

Lacking any feedback from Robert, I removed my changes related to 
basebackup and pushed Joshua's patch with one minor editorial fix. What 
to do with the basebackup changes can go on the open items list for pg15 
I guess.

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:38                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2022-03-21 20:15                                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-03-28 19:56                                                             ` Robert Haas <robertmhaas@gmail.com>
  2022-03-28 20:03                                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-04-02 17:32                                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  1 sibling, 2 replies; 42+ messages in thread

From: Robert Haas @ 2022-03-28 19:56 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Stephen Frost <sfrost@snowman.net>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; Tom Lane <tgl@sss.pgh.pa.us>

On Mon, Mar 21, 2022 at 4:15 PM Joe Conway <mail@joeconway.com> wrote:
> Robert -- any opinion on this? If I am not mistaken it is code that you
> are actively working on.

Woops, I only just saw this. I don't mind if you want to change the
calls to is_member_of_role() in basebackup_server.c and
basebackup_to_shell.c to has_privs_of_role(). However, it's not clear
to me why it's different than the calls we have in other places, like
calculate_database_size() and the relatively widely-used
check_is_member_of_role(). As long as we have a bunch of different
practices in different parts of the code base I can't see people
getting this right consistently ... leaving aside any possible
disagreement about which way is "right".

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:38                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2022-03-21 20:15                                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-28 19:56                                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-03-28 20:03                                                               ` Joe Conway <mail@joeconway.com>
  1 sibling, 0 replies; 42+ messages in thread

From: Joe Conway @ 2022-03-28 20:03 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Stephen Frost <sfrost@snowman.net>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; Tom Lane <tgl@sss.pgh.pa.us>

On 3/28/22 15:56, Robert Haas wrote:
> On Mon, Mar 21, 2022 at 4:15 PM Joe Conway <mail@joeconway.com> wrote:
>> Robert -- any opinion on this? If I am not mistaken it is code that you
>> are actively working on.
> 
> Woops, I only just saw this. I don't mind if you want to change the
> calls to is_member_of_role() in basebackup_server.c and
> basebackup_to_shell.c to has_privs_of_role().

No worries -- I will take care of that shortly.

> However, it's not clear to me why it's different than the calls we
> have in other places, like calculate_database_size() and the
> relatively widely-used check_is_member_of_role().

I will have to go refresh my memory, but when I looked at those sites 
closely it all made sense to me.

I think most if not all of them were checking for the ability to switch 
to the other role, not actually checking for privileges by virtue of 
belonging to that role.

> As long as we have a bunch of different practices in different parts
> of the code base I can't see people getting this right consistently
> ... leaving aside any possible disagreement about which way is
> "right".
When I take the next pass I can consider whether additional comments 
will help and report back.

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:38                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2022-03-21 20:15                                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-28 19:56                                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
@ 2022-04-02 17:32                                                               ` Joe Conway <mail@joeconway.com>
  2022-04-04 13:05                                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  1 sibling, 1 reply; 42+ messages in thread

From: Joe Conway @ 2022-04-02 17:32 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Stephen Frost <sfrost@snowman.net>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; Tom Lane <tgl@sss.pgh.pa.us>

On 3/28/22 15:56, Robert Haas wrote:
> On Mon, Mar 21, 2022 at 4:15 PM Joe Conway <mail@joeconway.com> wrote:
>> Robert -- any opinion on this? If I am not mistaken it is code that you
>> are actively working on.
> 
> Woops, I only just saw this. I don't mind if you want to change the
> calls to is_member_of_role() in basebackup_server.c and
> basebackup_to_shell.c to has_privs_of_role().

Done as originally posted.

> On that last note, I did not find basebackup_to_shell.required_role 
> documented at all, and did not attempt to fix that.

I saw that Robert added documentation and it already reads correctly I 
believe, except possibly an unrelated issue:

8<--------------
      <para>
       A role which replication whose privileges users are required to 
possess
       in order to make use of the <literal>shell</literal> backup target.
       If this is not set, any replication user may make use of the
       <literal>shell</literal> backup target.
      </para>
8<--------------

Robert, should that actually be:
  s/role which replication/role with replication/
?

Joe





^ permalink  raw  reply  [nested|flat] 42+ messages in thread

* Re: [PATCH v2] use has_privs_for_role for predefined roles
  2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:16 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2021-10-27 21:20   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-10-27 21:35     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-08 20:44       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2021-11-08 22:15         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-10 17:45           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2021-11-12 20:33             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2021-11-15 22:23               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Bossart, Nathan <bossartn@amazon.com>
  2022-01-04 20:56                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-04 21:51                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-06 16:38                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-06 17:24                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-07 15:35                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-07 16:13                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-07 17:09                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 11:59                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-08 13:45                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-08 15:00                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-02-08 15:07                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 00:38                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-09 03:54                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-02-09 18:13                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-09 21:39                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-02-10 19:28                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Nathan Bossart <nathandbossart@gmail.com>
  2022-02-10 19:37                                                 ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-03 16:26                                                   ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:27                                                     ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-20 16:31                                                       ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
  2022-03-20 16:38                                                         ` Re: [PATCH v2] use has_privs_for_role for predefined roles Stephen Frost <sfrost@snowman.net>
  2022-03-21 20:15                                                           ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
  2022-03-28 19:56                                                             ` Re: [PATCH v2] use has_privs_for_role for predefined roles Robert Haas <robertmhaas@gmail.com>
  2022-04-02 17:32                                                               ` Re: [PATCH v2] use has_privs_for_role for predefined roles Joe Conway <mail@joeconway.com>
@ 2022-04-04 13:05                                                                 ` Robert Haas <robertmhaas@gmail.com>
  0 siblings, 0 replies; 42+ messages in thread

From: Robert Haas @ 2022-04-04 13:05 UTC (permalink / raw)
  To: Joe Conway <mail@joeconway.com>; +Cc: Stephen Frost <sfrost@snowman.net>; Joshua Brindle <joshua.brindle@crunchydata.com>; Bossart, Nathan <bossartn@amazon.com>; Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; Tom Lane <tgl@sss.pgh.pa.us>

On Sat, Apr 2, 2022 at 1:32 PM Joe Conway <mail@joeconway.com> wrote:
> I saw that Robert added documentation and it already reads correctly I
> believe, except possibly an unrelated issue:
>
> 8<--------------
>       <para>
>        A role which replication whose privileges users are required to
> possess
>        in order to make use of the <literal>shell</literal> backup target.
>        If this is not set, any replication user may make use of the
>        <literal>shell</literal> backup target.
>       </para>
> 8<--------------
>
> Robert, should that actually be:
>   s/role which replication/role with replication/

Oh, good catch. Actually shouldn't "with replication" just be deleted?

Or maybe it needs to be reworded more, for clarity: "Replication users
must possess the privileges of this role in order to ..."

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 42+ messages in thread


end of thread, other threads:[~2022-04-04 13:05 UTC | newest]

Thread overview: 42+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 21:13 [PATCH v2] use has_privs_for_role for predefined roles Joshua Brindle <joshua.brindle@crunchydata.com>
2021-10-27 21:16 ` Robert Haas <robertmhaas@gmail.com>
2021-10-27 21:20   ` Joshua Brindle <joshua.brindle@crunchydata.com>
2021-10-27 21:35     ` Joshua Brindle <joshua.brindle@crunchydata.com>
2021-10-27 21:38       ` Bossart, Nathan <bossartn@amazon.com>
2021-11-08 20:44       ` Stephen Frost <sfrost@snowman.net>
2021-11-08 22:15         ` Joshua Brindle <joshua.brindle@crunchydata.com>
2021-11-10 17:45           ` Bossart, Nathan <bossartn@amazon.com>
2021-11-12 20:33             ` Joshua Brindle <joshua.brindle@crunchydata.com>
2021-11-15 22:23               ` Bossart, Nathan <bossartn@amazon.com>
2022-01-04 20:56                 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-01-04 21:51                   ` Joshua Brindle <joshua.brindle@crunchydata.com>
2022-02-06 16:38                     ` Joe Conway <mail@joeconway.com>
2022-02-06 17:24                       ` Tom Lane <tgl@sss.pgh.pa.us>
2022-02-07 15:35                         ` Robert Haas <robertmhaas@gmail.com>
2022-02-07 16:13                           ` Joe Conway <mail@joeconway.com>
2022-02-07 17:09                             ` Robert Haas <robertmhaas@gmail.com>
2022-02-07 17:23                               ` Joshua Brindle <joshua.brindle@crunchydata.com>
2022-02-08 11:59                               ` Joe Conway <mail@joeconway.com>
2022-02-08 13:45                                 ` Robert Haas <robertmhaas@gmail.com>
2022-02-08 15:00                                   ` Joshua Brindle <joshua.brindle@crunchydata.com>
2022-02-08 15:07                                     ` Robert Haas <robertmhaas@gmail.com>
2022-02-09 00:38                                       ` Joe Conway <mail@joeconway.com>
2022-02-09 03:54                                         ` Robert Haas <robertmhaas@gmail.com>
2022-02-09 18:13                                           ` Nathan Bossart <nathandbossart@gmail.com>
2022-02-09 20:58                                             ` Robert Haas <robertmhaas@gmail.com>
2022-02-09 21:51                                               ` Joshua Brindle <joshua.brindle@crunchydata.com>
2022-02-09 21:39                                             ` Joe Conway <mail@joeconway.com>
2022-02-10 19:28                                               ` Nathan Bossart <nathandbossart@gmail.com>
2022-02-10 19:37                                                 ` Joe Conway <mail@joeconway.com>
2022-03-03 16:26                                                   ` Joshua Brindle <joshua.brindle@crunchydata.com>
2022-03-20 16:27                                                     ` Joe Conway <mail@joeconway.com>
2022-03-20 16:31                                                       ` Joshua Brindle <joshua.brindle@crunchydata.com>
2022-03-20 16:34                                                         ` Joe Conway <mail@joeconway.com>
2022-03-20 16:37                                                           ` Joshua Brindle <joshua.brindle@crunchydata.com>
2022-03-20 16:38                                                         ` Stephen Frost <sfrost@snowman.net>
2022-03-21 20:15                                                           ` Joe Conway <mail@joeconway.com>
2022-03-28 19:31                                                             ` Joe Conway <mail@joeconway.com>
2022-03-28 19:56                                                             ` Robert Haas <robertmhaas@gmail.com>
2022-03-28 20:03                                                               ` Joe Conway <mail@joeconway.com>
2022-04-02 17:32                                                               ` Joe Conway <mail@joeconway.com>
2022-04-04 13:05                                                                 ` Robert Haas <robertmhaas@gmail.com>

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