Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkAYs-0002Td-PW for pgsql-general@arkaria.postgresql.org; Mon, 30 Jul 2018 15:58:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fkAYr-00048N-7l for pgsql-general@arkaria.postgresql.org; Mon, 30 Jul 2018 15:58:17 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkAYq-00048G-Re for pgsql-general@lists.postgresql.org; Mon, 30 Jul 2018 15:58:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkAYo-0003Fz-56 for pgsql-general@postgresql.org; Mon, 30 Jul 2018 15:58:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w6UFwBdh007183; Mon, 30 Jul 2018 11:58:12 -0400 From: Tom Lane To: =?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= cc: pgsql-general@postgresql.org Subject: Re: Incorrect description of the WITH CHECK in the row security can lead to the security issue In-reply-to: <3298321532002010@sas1-2b3c3045b736.qloud-c.yandex.net> References: <3298321532002010@sas1-2b3c3045b736.qloud-c.yandex.net> Comments: In-reply-to =?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= message dated "Thu, 19 Jul 2018 15:06:50 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7181.1532966291.1@sss.pgh.pa.us> Date: Mon, 30 Jul 2018 11:58:11 -0400 Message-ID: <7182.1532966291@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= writes: > PostgreSQL 10 (in 11 the same > https://www.postgresql.org/docs/10/static/ddl-rowsecurity.html > cite > To use a different policy for rows that are being added to the table > compared to those rows that are visible, the WITH CHECK clause can be used. > This policy would allow all users to view all rows in the users table, but > only modify their own: > CREATE POLICY user_policy ON users > USING (true) > WITH CHECK (user_name = current_user); > end cite > This is is wrong description. Every one can steal other row with such > policy. Yup, you're right, this is too simple. > The right statement to not allow modify rows by other user will be > CREATE POLICY user_policy ON users > USING (user_name = current_user) > WITH CHECK (user_name = current_user); Well, that also hides the other users' rows, which is not what the example claims to do. To make it work as documented, we need something like CREATE POLICY user_sel_policy ON users FOR SELECT USING (true); CREATE POLICY user_mod_policy ON users USING (user_name = current_user); I've pushed a patch along that line. Thanks for the report! regards, tom lane