Skip to content

Commit 7bae5a2

Browse files
committed
Get rid of the separate RULE privilege for tables: now only a table's owner
can create or modify rules for the table. Do setRuleCheckAsUser() while loading rules into the relcache, rather than when defining a rule. This ensures that permission checks for tables referenced in a rule are done with respect to the current owner of the rule's table, whereas formerly ALTER TABLE OWNER would fail to update the permission checking for associated rules. Removal of separate RULE privilege is needed to prevent various scenarios in which a grantee of RULE privilege could effectively have any privilege of the table owner. For backwards compatibility, GRANT/REVOKE RULE is still accepted, but it doesn't do anything. Per discussion here: http://archives.postgresql.org/pgsql-hackers/2006-04/msg01138.php
1 parent d5eb52a commit 7bae5a2

21 files changed

+113
-155
lines changed

doc/src/sgml/ddl.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.60 2006/07/14 00:13:05 neilc Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.61 2006/09/05 21:08:33 tgl Exp $ -->
22

33
<chapter id="ddl">
44
<title>Data Definition</title>
@@ -1342,7 +1342,7 @@ ALTER TABLE products RENAME TO items;
13421342
<para>
13431343
There are several different privileges: <literal>SELECT</>,
13441344
<literal>INSERT</>, <literal>UPDATE</>, <literal>DELETE</>,
1345-
<literal>RULE</>, <literal>REFERENCES</>, <literal>TRIGGER</>,
1345+
<literal>REFERENCES</>, <literal>TRIGGER</>,
13461346
<literal>CREATE</>, <literal>CONNECT</>, <literal>TEMPORARY</>,
13471347
<literal>EXECUTE</>, and <literal>USAGE</>.
13481348
The privileges applicable to a particular

doc/src/sgml/func.sgml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.333 2006/09/04 21:47:25 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.334 2006/09/05 21:08:33 tgl Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -9543,9 +9543,10 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');
95439543
the name can be schema-qualified if necessary.
95449544
The desired access privilege type
95459545
is specified by a text string, which must evaluate to one of the
9546-
values <literal>SELECT</literal>, <literal>INSERT</literal>, <literal>UPDATE</literal>,
9547-
<literal>DELETE</literal>, <literal>RULE</literal>, <literal>REFERENCES</literal>, or
9548-
<literal>TRIGGER</literal>. (Case of the string is not significant, however.)
9546+
values <literal>SELECT</literal>, <literal>INSERT</literal>,
9547+
<literal>UPDATE</literal>, <literal>DELETE</literal>,
9548+
<literal>REFERENCES</literal>, or <literal>TRIGGER</literal>.
9549+
(Case of the string is not significant, however.)
95499550
An example is:
95509551
<programlisting>
95519552
SELECT has_table_privilege('myschema.mytable', 'select');

doc/src/sgml/information_schema.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.26 2006/05/02 18:07:51 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.27 2006/09/05 21:08:34 tgl Exp $ -->
22

33
<chapter id="information-schema">
44
<title>The Information Schema</title>
@@ -2832,7 +2832,7 @@ ORDER BY c.ordinal_position;
28322832
Type of the privilege: <literal>SELECT</literal>,
28332833
<literal>DELETE</literal>, <literal>INSERT</literal>,
28342834
<literal>UPDATE</literal>, <literal>REFERENCES</literal>,
2835-
<literal>RULE</literal>, or <literal>TRIGGER</literal>
2835+
or <literal>TRIGGER</literal>
28362836
</entry>
28372837
</row>
28382838

@@ -4418,7 +4418,7 @@ ORDER BY c.ordinal_position;
44184418
Type of the privilege: <literal>SELECT</literal>,
44194419
<literal>DELETE</literal>, <literal>INSERT</literal>,
44204420
<literal>UPDATE</literal>, <literal>REFERENCES</literal>,
4421-
<literal>RULE</literal>, or <literal>TRIGGER</literal>
4421+
or <literal>TRIGGER</literal>
44224422
</entry>
44234423
</row>
44244424

doc/src/sgml/ref/create_rule.sgml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.46 2006/09/02 17:06:52 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.47 2006/09/05 21:08:35 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -200,8 +200,7 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS
200200
<title>Notes</title>
201201

202202
<para>
203-
You must have the privilege <literal>RULE</literal> on a table to
204-
be allowed to define a rule on it.
203+
You must be the owner of a table to create or change rules for it.
205204
</para>
206205

207206
<para>

doc/src/sgml/ref/grant.sgml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/grant.sgml,v 1.60 2006/08/02 16:29:49 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/grant.sgml,v 1.61 2006/09/05 21:08:35 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,7 +20,7 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
GRANT { { SELECT | INSERT | UPDATE | DELETE | RULE | REFERENCES | TRIGGER }
23+
GRANT { { SELECT | INSERT | UPDATE | DELETE | REFERENCES | TRIGGER }
2424
[,...] | ALL [ PRIVILEGES ] }
2525
ON [ TABLE ] <replaceable class="PARAMETER">tablename</replaceable> [, ...]
2626
TO { <replaceable class="PARAMETER">username</replaceable> | GROUP <replaceable class="PARAMETER">groupname</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
@@ -178,16 +178,6 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
178178
</listitem>
179179
</varlistentry>
180180

181-
<varlistentry>
182-
<term>RULE</term>
183-
<listitem>
184-
<para>
185-
Allows the creation of a rule on the table/view. (See the <xref
186-
linkend="sql-createrule" endterm="sql-createrule-title"> statement.)
187-
</para>
188-
</listitem>
189-
</varlistentry>
190-
191181
<varlistentry>
192182
<term>REFERENCES</term>
193183
<listitem>
@@ -418,8 +408,8 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
418408

419409
Access privileges for database "lusitania"
420410
Schema | Name | Type | Access privileges
421-
--------+---------+-------+------------------------------------------------------------
422-
public | mytable | table | {miriam=arwdRxt/miriam,=r/miriam,"group todos=arw/miriam"}
411+
--------+---------+-------+-----------------------------------------------------------
412+
public | mytable | table | {miriam=arwdxt/miriam,=r/miriam,"group todos=arw/miriam"}
423413
(1 row)
424414
</programlisting>
425415
The entries shown by <command>\z</command> are interpreted thus:
@@ -432,15 +422,14 @@ GRANT <replaceable class="PARAMETER">role</replaceable> [, ...] TO <replaceable
432422
w -- UPDATE ("write")
433423
a -- INSERT ("append")
434424
d -- DELETE
435-
R -- RULE
436425
x -- REFERENCES
437426
t -- TRIGGER
438427
X -- EXECUTE
439428
U -- USAGE
440429
C -- CREATE
441430
c -- CONNECT
442431
T -- TEMPORARY
443-
arwdRxt -- ALL PRIVILEGES (for tables)
432+
arwdxt -- ALL PRIVILEGES (for tables)
444433
* -- grant option for preceding privilege
445434

446435
/yyyy -- user who granted this privilege
@@ -463,7 +452,7 @@ and may include some privileges for <literal>PUBLIC</> depending on the
463452
object type, as explained above. The first <command>GRANT</> or
464453
<command>REVOKE</> on an object
465454
will instantiate the default privileges (producing, for example,
466-
<literal>{miriam=arwdRxt/miriam}</>) and then modify them per the
455+
<literal>{miriam=arwdxt/miriam}</>) and then modify them per the
467456
specified request.
468457
</para>
469458

@@ -548,8 +537,7 @@ GRANT <replaceable class="PARAMETER">privileges</replaceable>
548537
</para>
549538

550539
<para>
551-
The <literal>RULE</literal> privilege, and privileges on
552-
databases, tablespaces, schemas, and languages are
540+
Privileges on databases, tablespaces, schemas, and languages are
553541
<productname>PostgreSQL</productname> extensions.
554542
</para>
555543
</refsect1>

doc/src/sgml/ref/revoke.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/revoke.sgml,v 1.39 2006/08/02 16:29:49 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/revoke.sgml,v 1.40 2006/09/05 21:08:35 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -21,7 +21,7 @@ PostgreSQL documentation
2121
<refsynopsisdiv>
2222
<synopsis>
2323
REVOKE [ GRANT OPTION FOR ]
24-
{ { SELECT | INSERT | UPDATE | DELETE | RULE | REFERENCES | TRIGGER }
24+
{ { SELECT | INSERT | UPDATE | DELETE | REFERENCES | TRIGGER }
2525
[,...] | ALL [ PRIVILEGES ] }
2626
ON [ TABLE ] <replaceable class="PARAMETER">tablename</replaceable> [, ...]
2727
FROM { <replaceable class="PARAMETER">username</replaceable> | GROUP <replaceable class="PARAMETER">groupname</replaceable> | PUBLIC } [, ...]

doc/src/sgml/user-manag.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/user-manag.sgml,v 1.36 2006/08/02 16:29:49 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/user-manag.sgml,v 1.37 2006/09/05 21:08:34 tgl Exp $ -->
22

33
<chapter id="user-manag">
44
<title>Database Roles and Privileges</title>
@@ -293,7 +293,7 @@ ALTER ROLE myname SET enable_indexscan TO off;
293293
granted.
294294
There are several different kinds of privilege: <literal>SELECT</>,
295295
<literal>INSERT</>, <literal>UPDATE</>, <literal>DELETE</>,
296-
<literal>RULE</>, <literal>REFERENCES</>, <literal>TRIGGER</>,
296+
<literal>REFERENCES</>, <literal>TRIGGER</>,
297297
<literal>CREATE</>, <literal>CONNECT</>, <literal>TEMPORARY</>,
298298
<literal>EXECUTE</>, and <literal>USAGE</>.
299299
For more information on the different types of privileges supported by

src/backend/catalog/aclchk.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.130 2006/07/14 14:52:17 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.131 2006/09/05 21:08:35 tgl Exp $
1212
*
1313
* NOTES
1414
* See acl.h.
@@ -1328,8 +1328,6 @@ string_to_privilege(const char *privname)
13281328
return ACL_UPDATE;
13291329
if (strcmp(privname, "delete") == 0)
13301330
return ACL_DELETE;
1331-
if (strcmp(privname, "rule") == 0)
1332-
return ACL_RULE;
13331331
if (strcmp(privname, "references") == 0)
13341332
return ACL_REFERENCES;
13351333
if (strcmp(privname, "trigger") == 0)
@@ -1346,6 +1344,8 @@ string_to_privilege(const char *privname)
13461344
return ACL_CREATE_TEMP;
13471345
if (strcmp(privname, "connect") == 0)
13481346
return ACL_CONNECT;
1347+
if (strcmp(privname, "rule") == 0)
1348+
return 0; /* ignore old RULE privileges */
13491349
ereport(ERROR,
13501350
(errcode(ERRCODE_SYNTAX_ERROR),
13511351
errmsg("unrecognized privilege type \"%s\"", privname)));
@@ -1365,8 +1365,6 @@ privilege_to_string(AclMode privilege)
13651365
return "UPDATE";
13661366
case ACL_DELETE:
13671367
return "DELETE";
1368-
case ACL_RULE:
1369-
return "RULE";
13701368
case ACL_REFERENCES:
13711369
return "REFERENCES";
13721370
case ACL_TRIGGER:

src/backend/catalog/information_schema.sql

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2003-2006, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.35 2006/09/04 23:13:01 tgl Exp $
7+
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.36 2006/09/05 21:08:35 tgl Exp $
88
*/
99

1010
/*
@@ -1194,7 +1194,6 @@ CREATE VIEW role_table_grants AS
11941194
SELECT 'INSERT' UNION ALL
11951195
SELECT 'UPDATE' UNION ALL
11961196
SELECT 'REFERENCES' UNION ALL
1197-
SELECT 'RULE' UNION ALL
11981197
SELECT 'TRIGGER') AS pr (type)
11991198

12001199
WHERE c.relnamespace = nc.oid
@@ -1705,7 +1704,6 @@ CREATE VIEW table_constraints AS
17051704
OR has_table_privilege(r.oid, 'INSERT')
17061705
OR has_table_privilege(r.oid, 'UPDATE')
17071706
OR has_table_privilege(r.oid, 'DELETE')
1708-
OR has_table_privilege(r.oid, 'RULE')
17091707
OR has_table_privilege(r.oid, 'REFERENCES')
17101708
OR has_table_privilege(r.oid, 'TRIGGER') )
17111709

@@ -1739,7 +1737,6 @@ CREATE VIEW table_constraints AS
17391737
OR has_table_privilege(r.oid, 'INSERT')
17401738
OR has_table_privilege(r.oid, 'UPDATE')
17411739
OR has_table_privilege(r.oid, 'DELETE')
1742-
OR has_table_privilege(r.oid, 'RULE')
17431740
OR has_table_privilege(r.oid, 'REFERENCES')
17441741
OR has_table_privilege(r.oid, 'TRIGGER') );
17451742

@@ -1785,7 +1782,6 @@ CREATE VIEW table_privileges AS
17851782
SELECT 'INSERT' UNION ALL
17861783
SELECT 'UPDATE' UNION ALL
17871784
SELECT 'REFERENCES' UNION ALL
1788-
SELECT 'RULE' UNION ALL
17891785
SELECT 'TRIGGER') AS pr (type)
17901786

17911787
WHERE c.relnamespace = nc.oid
@@ -1841,7 +1837,6 @@ CREATE VIEW tables AS
18411837
OR has_table_privilege(c.oid, 'INSERT')
18421838
OR has_table_privilege(c.oid, 'UPDATE')
18431839
OR has_table_privilege(c.oid, 'DELETE')
1844-
OR has_table_privilege(c.oid, 'RULE')
18451840
OR has_table_privilege(c.oid, 'REFERENCES')
18461841
OR has_table_privilege(c.oid, 'TRIGGER') );
18471842

@@ -1963,7 +1958,6 @@ CREATE VIEW triggers AS
19631958
OR has_table_privilege(c.oid, 'INSERT')
19641959
OR has_table_privilege(c.oid, 'UPDATE')
19651960
OR has_table_privilege(c.oid, 'DELETE')
1966-
OR has_table_privilege(c.oid, 'RULE')
19671961
OR has_table_privilege(c.oid, 'REFERENCES')
19681962
OR has_table_privilege(c.oid, 'TRIGGER') );
19691963

@@ -2162,7 +2156,6 @@ CREATE VIEW views AS
21622156
OR has_table_privilege(c.oid, 'INSERT')
21632157
OR has_table_privilege(c.oid, 'UPDATE')
21642158
OR has_table_privilege(c.oid, 'DELETE')
2165-
OR has_table_privilege(c.oid, 'RULE')
21662159
OR has_table_privilege(c.oid, 'REFERENCES')
21672160
OR has_table_privilege(c.oid, 'TRIGGER') );
21682161

src/backend/commands/comment.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.90 2006/07/14 14:52:18 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.91 2006/09/05 21:08:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -741,7 +741,6 @@ CommentRule(List *qualname, char *comment)
741741
HeapTuple tuple;
742742
Oid reloid;
743743
Oid ruleoid;
744-
AclResult aclcheck;
745744

746745
/* Separate relname and trig name */
747746
nnames = list_length(qualname);
@@ -819,9 +818,8 @@ CommentRule(List *qualname, char *comment)
819818
}
820819

821820
/* Check object security */
822-
aclcheck = pg_class_aclcheck(reloid, GetUserId(), ACL_RULE);
823-
if (aclcheck != ACLCHECK_OK)
824-
aclcheck_error(aclcheck, ACL_KIND_CLASS,
821+
if (!pg_class_ownercheck(reloid, GetUserId()))
822+
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
825823
get_rel_name(reloid));
826824

827825
/* Call CreateComments() to create/drop the comments */

0 commit comments

Comments
 (0)