Re: predefined role(s) for VACUUM and ANALYZE

Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Andrew Dunstan <andrew@dunslane.net>, Corey Huinker <corey.huinker@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Stephen Frost <sfrost@snowman.net>, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, "David G. Johnston" <david.g.johnston@gmail.com>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>, Michael Paquier <michael@paquier.xyz>, Robert Haas <robertmhaas@gmail.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2022-12-06T11:47:50Z
Lists: pgsql-hackers

Attachments

Nathan Bossart <nathandbossart@gmail.com> writes:

> diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
> index 3b5ea3c137..bd967eaa78 100644
> --- a/src/backend/catalog/aclchk.c
> +++ b/src/backend/catalog/aclchk.c
> @@ -4202,6 +4202,26 @@ pg_class_aclmask_ext(Oid table_oid, Oid roleid, AclMode mask,
>  		has_privs_of_role(roleid, ROLE_PG_WRITE_ALL_DATA))
>  		result |= (mask & (ACL_INSERT | ACL_UPDATE | ACL_DELETE));
>  
> +	/*
> +	 * Check if ACL_VACUUM is being checked and, if so, and not already set as
> +	 * part of the result, then check if the user is a member of the
> +	 * pg_vacuum_all_tables role, which allows VACUUM on all relations.
> +	 */
> +	if (mask & ACL_VACUUM &&
> +		!(result & ACL_VACUUM) &&
> +		has_privs_of_role(roleid, ROLE_PG_VACUUM_ALL_TABLES))
> +		result |= ACL_VACUUM;
> +
> +	/*
> +	 * Check if ACL_ANALYZE is being checked and, if so, and not already set as
> +	 * part of the result, then check if the user is a member of the
> +	 * pg_analyze_all_tables role, which allows ANALYZE on all relations.
> +	 */
> +	if (mask & ACL_ANALYZE &&
> +		!(result & ACL_ANALYZE) &&
> +		has_privs_of_role(roleid, ROLE_PG_ANALYZE_ALL_TABLES))
> +		result |= ACL_ANALYZE;
> +
>  	return result;
>  }

These checks are getting rather repetitive, how about a data-driven
approach, along the lines of the below patch?  I'm not quite happy with
the naming of the struct and its members (and maybe it should be in a
header?), suggestions welcome.

- ilmari

Commits

  1. Provide non-superuser predefined roles for vacuum and analyze

  2. Provide per-table permissions for vacuum and analyze.

  3. Expand AclMode to 64 bits

  4. Simplify WARNING messages from skipped vacuum/analyze on a table

  5. Allow granting SET and ALTER SYSTEM privileges on GUC parameters.

  6. Add String object access hooks