mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Allow GRANTED BY clause in normal GRANT and REVOKE statements
The SQL standard allows a GRANTED BY clause on GRANT and REVOKE (privilege) statements that can specify CURRENT_USER or CURRENT_ROLE. In PostgreSQL, both of these are the default behavior. Since we already have all the parsing support for this for the GRANT (role) statement, we might as well add basic support for this for the privilege variant as well. This allows us to check off SQL feature T332. In the future, perhaps more interesting things could be done with this, too. Reviewed-by: Simon Riggs <simon@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/f2feac44-b4c5-f38f-3699-2851d6a76dc9@2ndquadrant.com
This commit is contained in:
@ -26,58 +26,71 @@ GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
|
||||
ON { [ TABLE ] <replaceable class="parameter">table_name</replaceable> [, ...]
|
||||
| ALL TABLES IN SCHEMA <replaceable class="parameter">schema_name</replaceable> [, ...] }
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { { SELECT | INSERT | UPDATE | REFERENCES } ( <replaceable class="parameter">column_name</replaceable> [, ...] )
|
||||
[, ...] | ALL [ PRIVILEGES ] ( <replaceable class="parameter">column_name</replaceable> [, ...] ) }
|
||||
ON [ TABLE ] <replaceable class="parameter">table_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { { USAGE | SELECT | UPDATE }
|
||||
[, ...] | ALL [ PRIVILEGES ] }
|
||||
ON { SEQUENCE <replaceable class="parameter">sequence_name</replaceable> [, ...]
|
||||
| ALL SEQUENCES IN SCHEMA <replaceable class="parameter">schema_name</replaceable> [, ...] }
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
|
||||
ON DATABASE <replaceable>database_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { USAGE | ALL [ PRIVILEGES ] }
|
||||
ON DOMAIN <replaceable>domain_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { USAGE | ALL [ PRIVILEGES ] }
|
||||
ON FOREIGN DATA WRAPPER <replaceable>fdw_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { USAGE | ALL [ PRIVILEGES ] }
|
||||
ON FOREIGN SERVER <replaceable>server_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { EXECUTE | ALL [ PRIVILEGES ] }
|
||||
ON { { FUNCTION | PROCEDURE | ROUTINE } <replaceable>routine_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) ] [, ...]
|
||||
| ALL { FUNCTIONS | PROCEDURES | ROUTINES } IN SCHEMA <replaceable class="parameter">schema_name</replaceable> [, ...] }
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { USAGE | ALL [ PRIVILEGES ] }
|
||||
ON LANGUAGE <replaceable>lang_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
|
||||
ON LARGE OBJECT <replaceable class="parameter">loid</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] }
|
||||
ON SCHEMA <replaceable>schema_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { CREATE | ALL [ PRIVILEGES ] }
|
||||
ON TABLESPACE <replaceable>tablespace_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT { USAGE | ALL [ PRIVILEGES ] }
|
||||
ON TYPE <replaceable>type_name</replaceable> [, ...]
|
||||
TO <replaceable class="parameter">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
|
||||
GRANT <replaceable class="parameter">role_name</replaceable> [, ...] TO <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ WITH ADMIN OPTION ]
|
||||
@ -133,6 +146,12 @@ GRANT <replaceable class="parameter">role_name</replaceable> [, ...] TO <replace
|
||||
to <literal>PUBLIC</literal>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If <literal>GRANTED BY</literal> is specified, the specified grantor must
|
||||
be the current user. This clause is currently present in this form only
|
||||
for SQL compatibility.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
There is no need to grant privileges to the owner of an object
|
||||
(usually the user that created it),
|
||||
@ -410,9 +429,9 @@ GRANT admins TO joe;
|
||||
|
||||
<para>
|
||||
The SQL standard allows the <literal>GRANTED BY</literal> option to
|
||||
be used in all forms of <command>GRANT</command>. PostgreSQL only
|
||||
supports it when granting role membership, and even then only superusers
|
||||
may use it in nontrivial ways.
|
||||
specify only <literal>CURRENT_USER</literal> or
|
||||
<literal>CURRENT_ROLE</literal>. The other variants are PostgreSQL
|
||||
extensions.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -27,6 +27,7 @@ REVOKE [ GRANT OPTION FOR ]
|
||||
ON { [ TABLE ] <replaceable class="parameter">table_name</replaceable> [, ...]
|
||||
| ALL TABLES IN SCHEMA <replaceable>schema_name</replaceable> [, ...] }
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
@ -34,6 +35,7 @@ REVOKE [ GRANT OPTION FOR ]
|
||||
[, ...] | ALL [ PRIVILEGES ] ( <replaceable class="parameter">column_name</replaceable> [, ...] ) }
|
||||
ON [ TABLE ] <replaceable class="parameter">table_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
@ -42,30 +44,35 @@ REVOKE [ GRANT OPTION FOR ]
|
||||
ON { SEQUENCE <replaceable class="parameter">sequence_name</replaceable> [, ...]
|
||||
| ALL SEQUENCES IN SCHEMA <replaceable>schema_name</replaceable> [, ...] }
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
|
||||
ON DATABASE <replaceable>database_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ USAGE | ALL [ PRIVILEGES ] }
|
||||
ON DOMAIN <replaceable>domain_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ USAGE | ALL [ PRIVILEGES ] }
|
||||
ON FOREIGN DATA WRAPPER <replaceable>fdw_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ USAGE | ALL [ PRIVILEGES ] }
|
||||
ON FOREIGN SERVER <replaceable>server_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
@ -73,36 +80,42 @@ REVOKE [ GRANT OPTION FOR ]
|
||||
ON { { FUNCTION | PROCEDURE | ROUTINE } <replaceable>function_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) ] [, ...]
|
||||
| ALL { FUNCTIONS | PROCEDURES | ROUTINES } IN SCHEMA <replaceable>schema_name</replaceable> [, ...] }
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ USAGE | ALL [ PRIVILEGES ] }
|
||||
ON LANGUAGE <replaceable>lang_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
|
||||
ON LARGE OBJECT <replaceable class="parameter">loid</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] }
|
||||
ON SCHEMA <replaceable>schema_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ CREATE | ALL [ PRIVILEGES ] }
|
||||
ON TABLESPACE <replaceable>tablespace_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ GRANT OPTION FOR ]
|
||||
{ USAGE | ALL [ PRIVILEGES ] }
|
||||
ON TYPE <replaceable>type_name</replaceable> [, ...]
|
||||
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
|
||||
[ GRANTED BY <replaceable class="parameter">role_specification</replaceable> ]
|
||||
[ CASCADE | RESTRICT ]
|
||||
|
||||
REVOKE [ ADMIN OPTION FOR ]
|
||||
|
Reference in New Issue
Block a user