Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYeau-0008F0-Ka for pgsql-general@arkaria.postgresql.org; Thu, 15 Sep 2022 02:27:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oYeat-0000a2-J2 for pgsql-general@arkaria.postgresql.org; Thu, 15 Sep 2022 02:27:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYeat-0000ZY-5V for pgsql-general@lists.postgresql.org; Thu, 15 Sep 2022 02:27:11 +0000 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oYeaq-0005rv-3B for pgsql-general@lists.postgresql.org; Thu, 15 Sep 2022 02:27:10 +0000 Received: by mail-qt1-x830.google.com with SMTP id cj27so455977qtb.7 for ; Wed, 14 Sep 2022 19:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date; bh=joknjfER7QeMED7AayxSBfe264zklscn26W6e1YBlpI=; b=YG08+o9ltsoiwn1LVjnmEqjbfhvDpUOvZqT127YkplQ05xn/7opjlZN14dEnua57G8 A3zebe0KixLrdttZNGx3VjTlJx51QRLVeBuT7UKU0cZxwLtVebl1j5aVv1uJ6rtgEkq9 O5fISaWX0+J2RMJQqekJoZiEB0xl8QzfuvE3TEx0FkYahgWNn12NMGR5TR0JoFW4aY9M jeN45vRfU2tuu7VniCgZUcoaJSDewLiIZivPQti9Zs1eNico84OgdmgERKegINYSJ/hm XM1U5Ts2SwapvTiYlFvQx8oOyVvhHDkaOEKfIG0FL4j+PidA7XBicuV7gDqM3zsbhR3t a+yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date; bh=joknjfER7QeMED7AayxSBfe264zklscn26W6e1YBlpI=; b=xGob0J8IZnsBtIzQgChyc1d+TmKMrio/8wY2aI2wMcE//i4yxAs+4HJBv2ySgiOD1k yiStopC+/ivbLyw8QV093uM3On4RtVbYg1N1fYiWbP2rriYFhUENCHeIIAhOM83O/dT9 iTZJrXVImFunXl/l/+VI2qeBKspkgbVS4FjukO6MOEn8DMX8hM720j/a94y4FAa9XQuL JMJ7EQlTszYKQaN+eqqjNCZ7IWQwEqR3MDs7aqbc8VXu+xwPVfcapgQY0BJx8USN6/nY IQqLzh3T88ZtrGsH/GiGaGqmk9qbXLv6O+q8b7RUtYOAX76FupFno11y4dZGaOv5Bypo HjTQ== X-Gm-Message-State: ACgBeo0aRKZlbGHrhgneFrkowpe6pmyt31MfLuYuc3FtF4i83LZQ/un4 pVQr4dbAorGoTzLAjVw3v+7AVphsfBFg4A== X-Google-Smtp-Source: AA6agR7zLJfVYvOqCjbUYgGdFzMvdFbHqQbmB7w81msWFbb5uGDW5Ac4WLCg6GyNBbLd++jCHsqVhw== X-Received: by 2002:a05:622a:1aa1:b0:35b:d970:c0a7 with SMTP id s33-20020a05622a1aa100b0035bd970c0a7mr10586332qtc.401.1663208826144; Wed, 14 Sep 2022 19:27:06 -0700 (PDT) Received: from [192.168.2.100] (pool-72-79-30-4.nwrknj.east.verizon.net. [72.79.30.4]) by smtp.gmail.com with ESMTPSA id m10-20020a05622a118a00b0035bb0cd479csm3087092qtk.40.2022.09.14.19.27.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Sep 2022 19:27:05 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------ccdD0f0dMdVAd31OyJMUo6sp" Message-ID: Date: Wed, 14 Sep 2022 22:27:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: Is it possible to stop sessions killing eachother when they all authorize as the same role? Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <10F360BB-3149-45E6-BFFE-10B9AE31F1A6@yugabyte.com> <2F078227-5EEF-4553-89FF-046A6AF12F25@yugabyte.com> <1883844.1663044542@sss.pgh.pa.us> From: Mladen Gogala In-Reply-To: <1883844.1663044542@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------ccdD0f0dMdVAd31OyJMUo6sp Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 9/13/22 00:49, Tom Lane wrote: > Bryn Llewellyn writes: >> My non-superuser normalrole with direct login, "u1", is *still* able to invoke pg_terminate_backend() and kill other "u1" sessions—even after this (as a super-user): > Really? > > I did this in 14.5: > > regression=# revoke execute on function pg_terminate_backend from public; > REVOKE > regression=# select proacl from pg_proc where proname = 'pg_terminate_backend'; > proacl > ----------------------- > {postgres=X/postgres} > (1 row) > > (as expected, the superuser's own execute permission is all that remains) > > regression=# create user joe; > CREATE ROLE > regression=# \c - joe > You are now connected to database "regression" as user "joe". > regression=> select pg_terminate_backend(42); > ERROR: permission denied for function pg_terminate_backend > >> It very much looks as if what I have describe was deemed to be a bug (after that behavior had survived from at least version 11) and that it's now been fixed! > No, it very much looks like pilot error. But you've not shown > us exactly what your test consisted of, so it's hard to say just > where it went off the rails. > > regards, tom lane > > Tom, I did the same thing on 14.5, and it behaves as Bryn alleges: postgres=# select proacl from pg_proc where proname = 'pg_terminate_backend';         proacl -----------------------  {postgres=X/postgres} (1 row) So,the only user who should be able to execute pg_terminate_backend is "postgres". Let's try with user "scott". mgogala@umajor ~]$ psql -U scott Password for user scott: psql (14.5) Type "help" for help. scott=> select pid from pg_stat_activity where usename='scott'; pid ----- 66 79 (2 rows) scott=> select pg_terminate_backend(66); pg_terminate_backend ---------------------- t (1 row) User scott has no special privileges: postgres=# select usesuper,usecreatedb,usebypassrls from pg_user where usename='scott'; usesuper | usecreatedb | usebypassrls ----------+-------------+-------------- f | f | f (1 row) Yet, it is still able to execute the function in question. My version is the following: scott=> select version(); version -------------------------------------------------------------------------------- -------------------------  PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (R ed Hat 8.5.0-10), 64-bit (1 row) Regards -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------ccdD0f0dMdVAd31OyJMUo6sp Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 9/13/22 00:49, Tom Lane wrote:
Bryn Llewellyn <bryn@yugabyte.com> writes:
My  non-superuser normalrole with direct login, "u1", is *still* able to invoke pg_terminate_backend() and kill other "u1" sessions—even after this (as a super-user):
Really?

I did this in 14.5:

regression=# revoke execute on function pg_terminate_backend from public;
REVOKE
regression=# select proacl from pg_proc where proname = 'pg_terminate_backend';
        proacl         
-----------------------
 {postgres=X/postgres}
(1 row)

(as expected, the superuser's own execute permission is all that remains)

regression=# create user joe;
CREATE ROLE
regression=# \c - joe
You are now connected to database "regression" as user "joe".
regression=> select pg_terminate_backend(42);
ERROR:  permission denied for function pg_terminate_backend

It very much looks as if what I have describe was deemed to be a bug (after that behavior had survived from at least version 11) and that it's now been fixed!
No, it very much looks like pilot error.  But you've not shown
us exactly what your test consisted of, so it's hard to say just
where it went off the rails.

			regards, tom lane


Tom, I did the same thing on 14.5, and it behaves as Bryn alleges:

postgres=# select proacl from pg_proc where proname = 'pg_terminate_backend';
        proacl         
-----------------------
 {postgres=X/postgres}
(1 row)

So, the only user who should be able to execute pg_terminate_backend is "postgres". Let's try with user "scott".
mgogala@umajor ~]$ psql -U scott
Password for user scott: 
psql (14.5)
Type "help" for help.

scott=> select pid from pg_stat_activity where usename='scott';
 pid 
-----
  66
  79
(2 rows)

scott=> select pg_terminate_backend(66);
 pg_terminate_backend 
----------------------
 t
(1 row)

User scott has no special privileges:

postgres=# select usesuper,usecreatedb,usebypassrls from pg_user where usename='scott';
usesuper | usecreatedb | usebypassrls
----------+-------------+--------------
f | f | f
(1 row)


Yet, it is still able to execute the function in question. My version is the following:

scott=> select version();
                                                 version                        
                         
--------------------------------------------------------------------------------
-------------------------
 PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (R
ed Hat 8.5.0-10), 64-bit
(1 row)


Regards

-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
--------------ccdD0f0dMdVAd31OyJMUo6sp--