Skip to content
Snippets Groups Projects
Commit 5f4a3116 authored by Tom Lane's avatar Tom Lane
Browse files

Remove ALTER DEFAULT PRIVILEGES' requirement of schema CREATE permissions.

Per discussion, this restriction isn't needed for any real security reason,
and it seems to confuse people more often than it helps them.  It could
also result in some database states being unrestorable.  So just drop it.

Back-patch to 9.0, where ALTER DEFAULT PRIVILEGES was introduced.
parent a9ec978e
No related branches found
No related tags found
No related merge requests found
...@@ -121,8 +121,8 @@ REVOKE [ GRANT OPTION FOR ] ...@@ -121,8 +121,8 @@ REVOKE [ GRANT OPTION FOR ]
<term><replaceable>schema_name</replaceable></term> <term><replaceable>schema_name</replaceable></term>
<listitem> <listitem>
<para> <para>
The name of an existing schema. Each <replaceable>target_role</> The name of an existing schema. If specified, the default privileges
must have <literal>CREATE</> privileges for each specified schema. are altered for objects later created in that schema.
If <literal>IN SCHEMA</> is omitted, the global default privileges If <literal>IN SCHEMA</> is omitted, the global default privileges
are altered. are altered.
</para> </para>
......
...@@ -1030,27 +1030,26 @@ SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames) ...@@ -1030,27 +1030,26 @@ SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames)
} }
else else
{ {
/* Look up the schema OIDs and do permissions checks */ /* Look up the schema OIDs and set permissions for each one */
ListCell *nspcell; ListCell *nspcell;
foreach(nspcell, nspnames) foreach(nspcell, nspnames)
{ {
char *nspname = strVal(lfirst(nspcell)); char *nspname = strVal(lfirst(nspcell));
AclResult aclresult;
/*
* Note that we must do the permissions check against the target
* role not the calling user. We require CREATE privileges, since
* without CREATE you won't be able to do anything using the
* default privs anyway.
*/
iacls->nspid = get_namespace_oid(nspname, false); iacls->nspid = get_namespace_oid(nspname, false);
aclresult = pg_namespace_aclcheck(iacls->nspid, iacls->roleid, /*
ACL_CREATE); * We used to insist that the target role have CREATE privileges
if (aclresult != ACLCHECK_OK) * on the schema, since without that it wouldn't be able to create
aclcheck_error(aclresult, ACL_KIND_NAMESPACE, * an object for which these default privileges would apply.
nspname); * However, this check proved to be more confusing than helpful,
* and it also caused certain database states to not be
* dumpable/restorable, since revoking CREATE doesn't cause
* default privileges for the schema to go away. So now, we just
* allow the ALTER; if the user lacks CREATE he'll find out when
* he tries to create an object.
*/
SetDefaultACL(iacls); SetDefaultACL(iacls);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment