Re: pgsql: Fix search_path to a safe value during maintenance operations.

David G. Johnston <david.g.johnston@gmail.com>

From: "David G. Johnston" <david.g.johnston@gmail.com>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Noah Misch <noah@leadboat.com>, Tom Lane <tgl@sss.pgh.pa.us>, Jeff Davis <jdavis@postgresql.org>, "pgsql-committers@lists.postgresql.org" <pgsql-committers@lists.postgresql.org>
Date: 2023-06-13T01:31:21Z
Lists: pgsql-hackers
On Monday, June 12, 2023, David G. Johnston <david.g.johnston@gmail.com>
wrote:

> On Mon, Jun 12, 2023 at 5:40 PM Jeff Davis <pgsql@j-davis.com> wrote:
>
>> On Mon, 2023-06-12 at 13:05 -0400, Noah Misch wrote:
>> > The timing was not great, but this is fixing a purported defect in an
>> > older
>> > v16 feature.  If the MAINTAIN privilege is actually fine, we're all
>> > set for
>> > v16.  If MAINTAIN does have a material problem that $SUBJECT had
>> > fixed, we
>> > should either revert MAINTAIN, un-revert $SUBJECT, or fix the problem
>> > a
>> > different way.
>>
>> Someone with the MAINTAIN privilege on a table can use search_path
>> tricks against the table owner, if the code is susceptible, because
>> maintenance code runs with the privileges of the table owner.
>>
>>
> Only change the search_path if someone other than the table owner or
> superuser is running the command (which should only be possible via the new
> MAINTAIN privilege)?
>

On a related note, are we OK with someone using this privilege setting
their own default_statistics_target?

https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-DEFAULT-STATISTICS-TARGET

My prior attempt to open up analyze had brought this up as a reason to
avoid having someone besides the table owner allowed to analyze the table.

David J.

Commits

  1. Fix search_path to a safe value during maintenance operations.

  2. Revert MAINTAIN privilege and pg_maintain predefined role.

  3. Add grantable MAINTAIN privilege and pg_maintain role.

  4. Revoke PUBLIC CREATE from public schema, now owned by pg_database_owner.