]> granicus.if.org Git - postgresql/commitdiff
Remove ALTER DEFAULT PRIVILEGES' requirement of schema CREATE permissions.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 9 Jun 2013 19:27:00 +0000 (15:27 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 9 Jun 2013 19:27:00 +0000 (15:27 -0400)
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.

doc/src/sgml/ref/alter_default_privileges.sgml
src/backend/catalog/aclchk.c

index 2099c3471ece73b707b38fbdc03021d4d7549041..f12a1eb781ebb4bd5b1e120c80159ee79d564dee 100644 (file)
@@ -111,8 +111,8 @@ REVOKE [ GRANT OPTION FOR ]
     <term><replaceable>schema_name</replaceable></term>
     <listitem>
      <para>
-      The name of an existing schema.  Each <replaceable>target_role</>
-      must have <literal>CREATE</> privileges for each specified schema.
+      The name of an existing schema.  If specified, the default privileges
+      are altered for objects later created in that schema.
       If <literal>IN SCHEMA</> is omitted, the global default privileges
       are altered.
      </para>
index ea49b7467832feea1d2979adfa64203a2cad08fd..2eea06515d298127dd195b7949224bdf77e5a48b 100644 (file)
@@ -1028,21 +1028,13 @@ SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames)
        }
        else
        {
-               /* Look up the schema OIDs and do permissions checks */
+               /* Look up the schema OIDs and set permissions for each one */
                ListCell   *nspcell;
 
                foreach(nspcell, nspnames)
                {
                        char       *nspname = strVal(lfirst(nspcell));
-                       AclResult       aclresult;
 
-                       /*
-                        * Normally we'd use LookupCreationNamespace here, but it's
-                        * important to do the permissions check against the target role
-                        * not the calling user, so write it out in full.  We require
-                        * CREATE privileges, since without CREATE you won't be able to do
-                        * anything using the default privs anyway.
-                        */
                        iacls->nspid = GetSysCacheOid1(NAMESPACENAME,
                                                                                   CStringGetDatum(nspname));
                        if (!OidIsValid(iacls->nspid))
@@ -1050,11 +1042,17 @@ SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames)
                                                (errcode(ERRCODE_UNDEFINED_SCHEMA),
                                                 errmsg("schema \"%s\" does not exist", nspname)));
 
-                       aclresult = pg_namespace_aclcheck(iacls->nspid, iacls->roleid,
-                                                                                         ACL_CREATE);
-                       if (aclresult != ACLCHECK_OK)
-                               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-                                                          nspname);
+                       /*
+                        * We used to insist that the target role have CREATE privileges
+                        * on the schema, since without that it wouldn't be able to create
+                        * an object for which these default privileges would apply.
+                        * 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);
                }