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 1ffBMV-0005LD-DN for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Jul 2018 21:48:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ffBMT-00085N-NU for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Jul 2018 21:48:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ffBMT-00085G-Hc for pgsql-bugs@lists.postgresql.org; Mon, 16 Jul 2018 21:48:53 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ffBMP-0003ZF-Dt for pgsql-bugs@lists.postgresql.org; Mon, 16 Jul 2018 21:48:53 +0000 Received: by mail-wr1-x444.google.com with SMTP id q10-v6so33343067wrd.4 for ; Mon, 16 Jul 2018 14:48:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=bwj8797/GzYqJwqy8x1/D7VZCjU0pNIK2//eA4aKEdw=; b=HPjfvvtM/eBgMsLPOmN4eHvHJKkYeXLAzK5lI7aR9jcdbAqrcNmsXAXxsIUkaR+JJ8 17WhTZwbCk5k0x2ZCv3h8Triz49FXaCIovvj0WIjQKw4M4v7je44NcK2eaa0f8VSVTn7 JPGaDJ+qxvBCXfMrEoAKKm+R4Pl6GRDr071+eZ07+fJ6CjqdfgtaYO2wj7ikQmNCrIhN +odMTB0WyYyJHuv2JqsTcQnJuSxjXiN5XAPdp7s8MGUDbZK7WbnaxwcnjME2GHL7yFDl OCqA9Pd+T/fzXNMMgx8lxmvQl2rZeZJNx/LzF0UacnbTdLMvi3AgqNp3a7DrCq8QMR13 2CBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bwj8797/GzYqJwqy8x1/D7VZCjU0pNIK2//eA4aKEdw=; b=sGZkwhXAzLBlUlrplTWJlmpfll4rhuTvEjKEC+Ocw0TgbS1ULbK8jurlfI0ObztG5J uMMk5q4GHPYz+EXxz8PCX11FoC8gf3cwkcttgO1jD9V+1mwmyrcVePiCYj3sEBnonB5A fkYfdGs75XJscr8R5S2Smu94bbDGlGhne37mFBzZ23vAOYt/GUZ1uYnQP+lM2VIu0VAP scA7iCdUswu3MHDJYKjV0l55p82Rdl2EAlNKy2nrbRiu/lhoKaV0EC7j9tA20GvgZwnw Fr0N8PxRDiGGtovf1ts4UUhdwpJM8uj6LWrB6C7xuItx/P9uPRa3y/aRq2Z1PkTYUYo6 pnxQ== X-Gm-Message-State: AOUpUlGDRWShKqLLeSHvsDy/7dyKt+KdzuNMOVYtwWe4jrSHqgVrG75f 55FC3jdYe5oz6zjZ01Fya5bnIw== X-Google-Smtp-Source: AAOMgpfn/s9+vvSHBSovc/WU8pM1LGyn48iDtc1n606q9O2FWbVZcMqSVAU0q2sdQOeFy0c0I3U1Mw== X-Received: by 2002:adf:ee4e:: with SMTP id w14-v6mr14010773wro.63.1531777728344; Mon, 16 Jul 2018 14:48:48 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id f20-v6sm16098759wmd.3.2018.07.16.14.48.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jul 2018 14:48:47 -0700 (PDT) Subject: Re: BUG #15281: Set role does not affect superuser privleges To: torcher999@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <153175290278.1396.6851104739737410645@wrigleys.postgresql.org> From: Tomas Vondra Message-ID: Date: Mon, 16 Jul 2018 23:48:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <153175290278.1396.6851104739737410645@wrigleys.postgresql.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 07/16/2018 04:55 PM, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 15281 > Logged by: Michal Wozny > Email address: torcher999@gmail.com > PostgreSQL version: 10.4 > Operating system: Windows Server 2012 R2 > Description: > > Here are the two scenarios I tested: > > 1) as a session_user: superuser and current_user: non-superuser I can edit > others' tables > 2) as a session_user: non-superuser and current_user: superuser I cannot > edit others' tables > > The documentation contradicts 1) explicitly, 2) implicitly: > > "when a superuser chooses to SET ROLE to a non-superuser role, they lose > their superuser privileges." > Source: https://www.postgresql.org/docs/current/static/sql-set-role.html > > > Steps to reproduce: > > Preconditions: > create two non-superusers [user1, user2] > create one superuser [user0] > grant user0 to user1 > create a table [u2_tab] with owner user2 > > 1) > disconnect > connect as user0 > set role user1 > rename u2_tab > > expected: cannot rename u2_tab > actual: can rename u2_tab > > 2) > disconnect > connect as user1 > set role user0 > rename u2_tab > > expected: can rename u2_tab > actual: cannot rename u2_tab > > SQL steps: > > Preconditions: > CREATE USER user0 WITH SUPERUSER > CREATE USER user1 > GRANT user0 to user1 > CREATE USER user2 > CREATE TABLE public.u2_tab > ALTER TABLE public.u2_tab OWNER TO user2 > > 1) > DISCONNECT > CONNECT TO db AS user0 > SET ROLE user1 > ALTER TABLE public.u2_tab RENAME TO u2_tab1 > > 2) > DISCONNECT > CONNECT TO db AS user1 > SET ROLE user0 > ALTER TABLE public.u2_tab1 RENAME TO u2_tab2 > It's usually a good idea to provide exact scripts / output so that people can reproduce the issue easily. For me it behaves like this: 1) non-superuser test=# drop table u2_tab ; DROP TABLE test=# drop role user1; DROP ROLE test=# drop role user2; DROP ROLE test=# drop role user0; DROP ROLE test=# CREATE USER user0 WITH SUPERUSER; CREATE ROLE test=# CREATE USER user1; CREATE ROLE test=# CREATE USER user2; CREATE ROLE test=# CREATE TABLE public.u2_tab(); CREATE TABLE test=# ALTER TABLE public.u2_tab OWNER TO user2; ALTER TABLE test=# \c - user0 You are now connected to database "test" as user "user0". test=# SET ROLE user1; SET test=> ALTER TABLE public.u2_tab RENAME TO u2_tab1; ERROR: must be owner of table u2_tab 2) superuser test=# drop table u2_tab ; DROP TABLE test=# drop role user0; DROP ROLE test=# drop role user1; DROP ROLE test=# drop role user2; DROP ROLE test=# test=# test=# test=# test=# CREATE USER user0 WITH SUPERUSER; CREATE ROLE test=# CREATE USER user1; CREATE ROLE test=# CREATE USER user2; CREATE ROLE test=# CREATE TABLE public.u2_tab(); CREATE TABLE test=# ALTER TABLE public.u2_tab OWNER TO user2; ALTER TABLE test=# \c - user0 You are now connected to database "test" as user "user0". test=# ALTER TABLE public.u2_tab RENAME TO u2_tab1; ALTER TABLE So, correct in both cases. I'm not on Windows, but I don't see why would it behave differently there. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services