Re: Allow non-superuser to cancel superuser tasks. - Mailing list pgsql-hackers

From Leung, Anthony
Subject Re: Allow non-superuser to cancel superuser tasks.
Date
Msg-id E35F20FF-4E2A-440C-8097-79B5748AD2DF@amazon.com
Whole thread Raw
In response to Re: Allow non-superuser to cancel superuser tasks.  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Allow non-superuser to cancel superuser tasks.
List pgsql-hackers
>>> There is pg_read_all_stats as well, so I don't see a big issue in
>>> requiring to be a member of this role as well for the sake of what's
>>> proposing here.
>>
>> Well, that tells you quite a bit more than just which PIDs correspond to
>> autovacuum workers, but maybe that's good enough for now.
>
> That may be a good initial compromise, for now.

Sounds good to me. I will update the documentation.


> And we should try to reshape things so as we get an ERROR like
> "permission denied to terminate process" or "permission denied to
> cancel query" for all the error paths, including autovacuum workers 
> and backends, so as we never leak any information about the backend
> types involved when a role has no permission to issue the signal.
> Perhaps that's the most intuitive thing as well, because autovacuum
> workers are backends. One thing that we could do is to mention both
> pg_signal_backend and pg_signal_autovacuum in the errdetail, and have
> both cases be handled by SIGNAL_BACKEND_NOPERMISSION on failure.

I understand your concern that we should avoid exposing the fact that the backend which the user is attempting to
terminateis an AV worker unless the user has pg_signal_backend privileges and pg_signal_autovacuum privileges. 
 
But Im not following how we can re-use SIGNAL_BACKEND_NOPERMISSION for this. If we return SIGNAL_BACKEND_NOPERMISSION
hereas the following, it'll stay return the "permission denied to terminate / cancel query" errmsg and errdetail in
pg_cancel/terminate_backend.

    /*
     * If the backend is autovacuum worker, allow user with the privileges of
     * pg_signal_autovacuum role to signal the backend.
     */
    if (pgstat_get_backend_type(GetNumberFromPGProc(proc)) == B_AUTOVAC_WORKER)
    {
        if (!has_privs_of_role(GetUserId(), ROLE_PG_SIGNAL_AUTOVACUUM))
            return SIGNAL_BACKEND_NOPERMISSION;
    }

Are you suggesting that we check if the backend is B_AUTOVAC in pg_cancel/ terminate_backend? That seems a bit unclean
tome since pg_cancel_backend & pg_cancel_backend does not access to the procNumber to check the type of the backend.
 

IMHO, we can keep SIGNAL_BACKEND_NOAUTOVACUUM but just improve the errmsg / errdetail to not expose that the backend is
anAV worker. It'll also be helpful if you can suggest what errdetail we should use here.
 

Thanks
--
Anthony Leung
Amazon Web Services: https://aws.amazon.com





pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: PostgreSQL 17 Release Management Team & Feature Freeze
Next
From: Tomas Vondra
Date:
Subject: Re: PostgreSQL 17 Release Management Team & Feature Freeze