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 1oYe86-0004tc-HL for pgsql-general@arkaria.postgresql.org; Thu, 15 Sep 2022 01:57:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oYe84-00024C-ME for pgsql-general@arkaria.postgresql.org; Thu, 15 Sep 2022 01:57:24 +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 1oYe84-000243-8m for pgsql-general@lists.postgresql.org; Thu, 15 Sep 2022 01:57:24 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oYe7v-0005dz-65 for pgsql-general@lists.postgresql.org; Thu, 15 Sep 2022 01:57:21 +0000 Received: by mail-qv1-xf34.google.com with SMTP id l14so4701965qvq.8 for ; Wed, 14 Sep 2022 18:57:15 -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=AYLDxgpIwQVQFo4vL/G+d1GGu0hNtF7tPxLpQsQpbB8=; b=h2weHwovNPiL/c18XV5j+3HJBbVrD0TS7Y5QXT0ZGwqVJZ9xqjl+nSmdE8j5pc+Gjj EpTFrkoSxp1/wxmWt8GGmJ6Cu/9a2y+V2A5PCTiOYOE5EExiAsQZDCwogT1qkjWKRLGr /1KsLKbsmmqrXzcJWV+9/6/ZxSmRIkrnKcny5g9xn2S5HAn/tdNVTd8FoOzDdkK7UBQN aEhYvVo1d7GLgjScbp3AaBDJJVKvHLqrzI2uj19EDM/Sx0vbEhx2C9+3yccmd8AzbuXW 5iwXVDbOdvHNggVXtXi042aZU1IGeSHX78yau7VqR+gWh/xO/S7INZf1IYGNB0ty6428 idGw== 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=AYLDxgpIwQVQFo4vL/G+d1GGu0hNtF7tPxLpQsQpbB8=; b=wQPMfR4/EiBM0sMj8KG3R7HjRD3Q6M/WqvUPC6zyEBSeDQO4Pz0Q7hhyxsRhUbYIiU pnJ+ptaZfIQ7fjNh5K/jc6xqMBbit3DS6aQoham2Dz2e+g3qKyvtcKsHkuauNcKijCAG CxuXKzGBmB05ucSbk89LsSlNiw74tGHXdapDG7CUb3NMs+tBK2sVnfulKRcehWO4zkFw rNDkpGtjCH8ejXj2w2QaO2+3BaXef/Pf94OWvUAEqRxxdg1KB/jSjXZeMGTbkPgB7rn6 XjbE8WiT/X+/gXfQm+Gi/aXYX9hUltaIfuJtLjCEWAT3qihC58NQjnXYxyVQBQzgLl9v GGxg== X-Gm-Message-State: ACgBeo0fWnJYtN3kz4xp8v3/8sFUiiMMDAcUJmzcNRRXjAqTq3uaZeV7 QVkvnYZRwH0eh8tOvYA5eGQr/TDhGn6miw== X-Google-Smtp-Source: AA6agR4/gTKHnxVeJTEkyKx2ovJYqrCVJf2k+LEXKuxiWwFreMDOxAsuUCLChHhbXuRdz152wCM5/w== X-Received: by 2002:a05:6214:f6a:b0:4a7:fe99:a39f with SMTP id iy10-20020a0562140f6a00b004a7fe99a39fmr34673549qvb.26.1663207032799; Wed, 14 Sep 2022 18:57:12 -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 u5-20020a05620a0c4500b006c73c3d288esm3078612qki.131.2022.09.14.18.57.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Sep 2022 18:57:12 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------k0zYQcS1TCbZtAynQmPaEIoW" Message-ID: <2bc1d63b-5376-bd25-4592-d86b77e4a4b8@gmail.com> Date: Wed, 14 Sep 2022 21:57:11 -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> From: Mladen Gogala In-Reply-To: <10F360BB-3149-45E6-BFFE-10B9AE31F1A6@yugabyte.com> 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. --------------k0zYQcS1TCbZtAynQmPaEIoW Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 9/12/22 18:51, Bryn Llewellyn wrote: > I'll use "kill" here a shorthand for using the "pg_terminate_backend()" built-in function. I read about it in the "Server Signaling Functions" section of the enclosing "System Administration Functions" section of the current doc: > > www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL > > And I tried a few tests. All of the outcomes were just as the doc promised. > > I'm troubled by the notion that (as it seems) one session that authorizes as the role "r1" can easily list all other concurrent sessions that are also authorized as "r1"—and kill them all without restriction. (The doc does say "Use of these functions is usually restricted to superusers, with noted exceptions." So I s'pose that I'm talking about one of these noted exceptions.) > > It's common to design a three tier app so that the middle tier always authorizes as just a single role—say, "client"—and where the operations that "client" can perform are limited as the overall design specifies. The maximal example of this paradigm defines the API to the database functionality by granting "execute" to just the designed set of subprograms. Here, the subprograms and the tables that they access all have owners other than "client". (The authorization of external principals, and ow their identity is mapped to a unique key for use within that database, is outside the scope of what I write about here.) > > It seems far-fetched to think that the requirements spec for every such design would deliberately specify: > > — Must be possible for any "client" session to kill all other concurrent "client" sessions. > > Yet the paradigm is that the database API expresses exactly and only what the design says that it should. Ergo, the paradigm is, in general, unimplementable. > > I appreciate that (while the privileges that "client" has are unchanged) a just-killed session can easily reconnect by trying what they had just tried again. But not before suffering the fatal "57P01: terminating connection due to administrator command" error. > > The implication is that every client program must follow every database call with defensive code to detect error "57P01" and programmatically re-try. (Maybe some drivers can do this automatically. But I haven't found out if whatever psql uses can do this. Nor have I found out how to write re-try code in psql.) > > Does anybody else find all this as troubling as I do? And, if so, might a remedy be possible? Maybe something like this: > > — Define a new privilege as a cousin to "pg_signal_backend". I'll call it "pg_signal_backend_for_self_role" here. This would govern the possibility that a session can kill another session that authorized as the same role as itself. > > — Document the fact that "pg_signal_backend_for_self_role" is implicitly granted to a newly-created role (just as it's documented that "execute… to public" is implicitly granted to a newly created subprogram). > > — Allow "revoke pg_signal_backend_for_self_role from…"—by all means with extra rules like only a superuser can do this. > > > Bryn, you can revoke execute on pg_terminate_backend from public and that will, by extension, revoke it from all users who do not have DBA privilege or have not been explicitly granted the "execute" privilege on pg_terminate_backend. This doesn't look like a big problem because applications usually don't contain code for killing other user's sessions. I am not sure that GTA is running on top of Postgres database. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------k0zYQcS1TCbZtAynQmPaEIoW Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 9/12/22 18:51, Bryn Llewellyn wrote:
I'll use "kill" here a shorthand for using the "pg_terminate_backend()" built-in function. I read about it in the "Server Signaling Functions" section of the enclosing "System Administration Functions" section of the current doc:

www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL

And I tried a few tests. All of the outcomes were just as the doc promised.

I'm troubled by the notion that (as it seems) one session that authorizes as the role "r1" can easily list all other concurrent sessions that are also authorized as "r1"—and kill them all without restriction. (The doc does say "Use of these functions is usually restricted to superusers, with noted exceptions." So I s'pose that I'm talking about one of these noted exceptions.)

It's common to design a three tier app so that the middle tier always authorizes as just a single role—say, "client"—and where the operations that "client" can perform are limited as the overall design specifies. The maximal example of this paradigm defines the API to the database functionality by granting "execute" to just the designed set of subprograms. Here, the subprograms and the tables that they access all have owners other than "client". (The authorization of external principals, and ow their identity is mapped to a unique key for use within that database, is outside the scope of what I write about here.)

It seems far-fetched to think that the requirements spec for every such design would deliberately specify:

— Must be possible for any "client" session to kill all other concurrent "client" sessions.

Yet the paradigm is that the database API expresses exactly and only what the design says that it should. Ergo, the paradigm is, in general, unimplementable.

I appreciate that (while the privileges that "client" has are unchanged) a just-killed session can easily reconnect by trying what they had just tried again. But not before suffering the fatal "57P01: terminating connection due to administrator command" error.

The implication is that every client program must follow every database call with defensive code to detect error "57P01" and programmatically re-try. (Maybe some drivers can do this automatically. But I haven't found out if whatever psql uses can do this. Nor have I found out how to write re-try code in psql.)

Does anybody else find all this as troubling as I do? And, if so, might a remedy be possible? Maybe something like this:

— Define a new privilege as a cousin to "pg_signal_backend". I'll call it "pg_signal_backend_for_self_role" here. This would govern the possibility that a session can kill another session that authorized as the same role as itself.

— Document the fact that "pg_signal_backend_for_self_role" is implicitly granted to a newly-created role (just as it's documented that "execute… to public" is implicitly granted to a newly created subprogram).

— Allow "revoke pg_signal_backend_for_self_role from…"—by all means with extra rules like only a superuser can do this.




Bryn, you can revoke execute on pg_terminate_backend from public and that will, by extension, revoke it from all users who do not have DBA privilege or have not been explicitly granted the "execute" privilege on pg_terminate_backend. This doesn't look like a big problem because applications usually don't contain code for killing other user's sessions. I am not sure that GTA is running on top of Postgres database.

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