Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpy04-0002DZ-K5 for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Jul 2019 16:50:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hpy03-0007cL-DX for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Jul 2019 16:50:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpy03-0007c8-2e for pgsql-bugs@lists.postgresql.org; Tue, 23 Jul 2019 16:50:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hpy00-0003Pw-7t for pgsql-bugs@lists.postgresql.org; Tue, 23 Jul 2019 16:50:49 +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 x6NGoeqv005306; Tue, 23 Jul 2019 12:50:40 -0400 From: Tom Lane To: =?gb2312?B?uN8g1MbB+g==?= cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: A function privilege problem In-reply-to: <21A88F6A-E654-4FDE-AB06-3FDBDC0EE231@biss.com> References: <21A88F6A-E654-4FDE-AB06-3FDBDC0EE231@biss.com> Comments: In-reply-to =?gb2312?B?uN8g1MbB+g==?= message dated "Tue, 23 Jul 2019 08:07:04 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <5304.1563900640.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 23 Jul 2019 12:50:40 -0400 Message-ID: <5305.1563900640@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?gb2312?B?uN8g1MbB+g=3D=3D?=3D writes: > Hi ,my postgresql is 11.1 and find a problem about the execute privilege > Now I have a new db user and a UDF. The function=C2=A1=C2=AFs body is u= pdate a table > When I run grant update on table xxx to the new user, find that i can ex= ecute the function and don=C2=A1=C2=AFt report "Execute permission for fun= ctions= xxx=C2=A1=C2=B1=C2=A3=C2=ACIs this right=C2=A3=C2=BF This is not a bug. Per the GRANT manual page [1]: PostgreSQL grants default privileges on some types of objects to PUBLIC. No privileges are granted to PUBLIC by default on tables, table columns, sequences, foreign data wrappers, foreign servers, large objects, schemas, or tablespaces. For other types of objects, the default privileges granted to PUBLIC are as follows: CONNECT and TEMPORARY (create temporary tables) privileges for databases; EXECUTE privilege for functions and procedures; and USAGE privilege for languages and data types (including domains). The object owner can, of course, REVOKE both default and expressly granted privileges. (For maximum security, issue the REVOKE in the same transaction that creates the object; then there is no window in which another user can use the object.) Also, these initial default privilege settings can be changed using the ALTER DEFAULT PRIVILEGES command. So the new user is making use of the default grant of EXECUTE to PUBLIC. If you don't want that, revoke execute privilege on that function from PUBLIC and then grant it to just the users who should be allowed to call the function. regards, tom lane [1] https://www.postgresql.org/docs/current/sql-grant.html