Alter Default Privileges Does Not Work For Functions

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Alter Default Privileges Does Not Work For Functions
Date: 2011-02-14 22:15:54
Message-ID: 02b401cbcc94$bfb16050$3f1420f0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

After creating and logging into a new database run this script. The
initial ALTER DEFAULT PRIVILEGES should make all users unable to execute
functions unless given explicit permissions elsewhere. However, the first
call to "testfunc()" succeeds. When I explicitly REVOKE ALL for the
specific function (or all functions in schema) and roles I DO get a
permission denied exception as expected. For those that read the other
thread I had assumed PUBLIC had its EXECUTE privileges revoked due to
executing the ALTER DEFAULT statement. It apparently did not and thus all
users were still able to execute functions via PUBLIC even if their explicit
role had execute revoked.

SET ROLE postgres;

CREATE ROLE impotent;

ALTER DEFAULT PRIVILEGES

IN SCHEMA public

REVOKE ALL ON FUNCTIONS

FROM PUBLIC, impotent;

CREATE FUNCTION testfunc() RETURNS boolean AS $$

BEGIN

RETURN true;

END;

$$ LANGUAGE 'plpgsql';

SET ROLE impotent;

SELECT testfunc(); -- SUCCEEDES

SET ROLE postgres;

REVOKE ALL ON ALL FUNCTIONS IN SCHEMA public FROM PUBLIC, impotent;

SET ROLE impotent;

SELECT testfunc(); --FAILS

David J

Responses

Browse pgsql-general by date

  From Date Subject
Next Message deepak 2011-02-14 22:28:36 Building extensions on Windows using VS2008
Previous Message Merlin Moncure 2011-02-14 21:57:52 Re: SELECT INTO array[i] with PL/pgSQL