Proposal: GRANT cascade to implicit sequences

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Proposal: GRANT cascade to implicit sequences
Date: 2004-10-13 06:37:35
Message-ID: 20041013063735.GA33916@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'd like to propose that certain GRANTs on a table cascade to the
table's implicit sequences. In the current implementation (as of
7.4.5 and 8.0.0beta3), a table owner must typically issue GRANT
statements on both the table and its sequences to allow other users
to insert records into the table. The GRANT on the sequences seems
superfluous.

Consider, for example, what's probably the most common use of
sequences: a SERIAL type representing a table's primary key:

CREATE TABLE foo (
id SERIAL PRIMARY KEY,
item VARCHAR(32) NOT NULL
);

The table owner might issue the following GRANT:

GRANT SELECT, INSERT ON foo TO otheruser;

When the other user attempts to insert a record into the table, the
insert fails:

=> INSERT INTO foo (item) VALUES ('first item');
ERROR: permission denied for sequence foo_id_seq

In addition to granting permission for the table, the table owner
must also grant permission for the sequence that represents the
primary key (UPDATE allows nextval(), SELECT allows currval()):

GRANT UPDATE, SELECT ON foo_id_seq TO otheruser;

The other user's insert now works:

=> INSERT INTO foo (item) VALUES ('first item');
INSERT 0 1

The need to issue a GRANT for the implicit sequence seems superfluous:
the ability to insert records into a table typically also implies
the ability to use the thing that generates the primary keys. I
haven't considered all cases, but it seems reasonable that at least
{GRANT | REVOKE} {INSERT | ALL} on a table should cascade to the
appropriate permissions on the table's implicit sequences.

Comments? Can anybody think of why cascading GRANT and REVOKE to
implicit sequences might be A Bad Idea?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message postgres2008 2004-10-13 07:26:36 how to open stat mode in db
Previous Message John Ossmann 2004-10-13 04:58:07 capacity of datatype "text"