Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d83863

Browse files
committed
Fix missing role dependencies for some schema and type ACLs.
This patch fixes several related cases in which pg_shdepend entries werenever made, or were lost, for references to roles appearing in the ACLs ofschemas and/or types. While that did no immediate harm, if a referencedrole were later dropped, the drop would be allowed and would leave adangling reference in the object's ACL. That still wasn't a big problemfor normal database usage, but it would cause obscure failures insubsequent dump/reload or pg_upgrade attempts, taking the form ofattempts to grant privileges to all-numeric role names. (I think I'veseen field reports matching that symptom, but can't find any right now.)Several cases are fixed here:1. ALTER DOMAIN SET/DROP DEFAULT would lose the dependencies for anyexisting ACL entries for the domain. This case is ancient, datingback as far as we've had pg_shdepend tracking at all.2. If a default type privilege applies, CREATE TYPE recorded theACL properly but forgot to install dependency entries for it.This dates to the addition of default privileges for types in 9.2.3. If a default schema privilege applies, CREATE SCHEMA recorded theACL properly but forgot to install dependency entries for it.This dates to the addition of default privileges for schemas in v10(commitab89e46).Another somewhat-related problem is that when creating a relationrowtype or implicit array type, TypeCreate would apply any availabledefault type privileges to that type, which we don't really wantsince such an object isn't supposed to have privileges of its own.(You can't, for example, drop such privileges once they've been addedto an array type.)ab89e46 is also to blame for a race condition in the regression tests:privileges.sql transiently installed globally-applicable defaultprivileges on schemas, which sometimes got absorbed into the ACLs ofschemas created by concurrent test scripts. This should have resultedin failures when privileges.sql tried to drop the role holding suchprivileges; but thanks to the bug fixed here, it instead led to danglingACLs in the final state of the regression database. We'd managed not tonotice that, but it became obvious in the wake of commitda90676, whichallowed the race condition to occur in pg_upgrade tests.To fix, add a function recordDependencyOnNewAcl to encapsulate whatcallers of get_user_default_acl need to do; while the original callsites got that right via ad-hoc code, none of the later-added oneshave. Also change GenerateTypeDependencies to generate thesedependencies, which requires adding the typacl to its parameter list.(That might be annoying if there are any extensions calling thatfunction directly; but if there are, they're most likely buggy in thesame way as the core callers were, so they need work anyway.) WhileI was at it, I changed GenerateTypeDependencies to accept most of itsparameters in the form of a Form_pg_type pointer, making its parameterlist a bit less unwieldy and mistake-prone.The test race condition is fixed just by wrapping the addition andremoval of default privileges into a single transaction, so that thatstate is never visible externally. We might eventually prefer toseparate out tests of default privileges into a script that runs byitself, but that would be a bigger change and would make the testsrun slower overall.Back-patch relevant parts to all supported branches.Discussion:https://postgr.es/m/15719.1541725287@sss.pgh.pa.us
1 parent52ea6a8 commit2d83863

File tree

10 files changed

+160
-137
lines changed

10 files changed

+160
-137
lines changed

‎src/backend/catalog/aclchk.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5240,7 +5240,10 @@ get_default_acl_internal(Oid roleId, Oid nsp_oid, char objtype)
52405240
/*
52415241
* Get default permissions for newly created object within given schema
52425242
*
5243-
* Returns NULL if built-in system defaults should be used
5243+
* Returns NULL if built-in system defaults should be used.
5244+
*
5245+
* If the result is not NULL, caller must call recordDependencyOnNewAcl
5246+
* once the OID of the new object is known.
52445247
*/
52455248
Acl*
52465249
get_user_default_acl(GrantObjectTypeobjtype,OidownerId,Oidnsp_oid)
@@ -5315,6 +5318,30 @@ get_user_default_acl(GrantObjectType objtype, Oid ownerId, Oid nsp_oid)
53155318
returnresult;
53165319
}
53175320

5321+
/*
5322+
* Record dependencies on roles mentioned in a new object's ACL.
5323+
*/
5324+
void
5325+
recordDependencyOnNewAcl(OidclassId,OidobjectId,int32objsubId,
5326+
OidownerId,Acl*acl)
5327+
{
5328+
intnmembers;
5329+
Oid*members;
5330+
5331+
/* Nothing to do if ACL is defaulted */
5332+
if (acl==NULL)
5333+
return;
5334+
5335+
/* Extract roles mentioned in ACL */
5336+
nmembers=aclmembers(acl,&members);
5337+
5338+
/* Update the shared dependency ACL info */
5339+
updateAclDependencies(classId,objectId,objsubId,
5340+
ownerId,
5341+
0,NULL,
5342+
nmembers,members);
5343+
}
5344+
53185345
/*
53195346
* Record initial privileges for the top-level object passed in.
53205347
*

‎src/backend/catalog/heap.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,13 +1301,16 @@ heap_create_with_catalog(const char *relname,
13011301
myself.classId=RelationRelationId;
13021302
myself.objectId=relid;
13031303
myself.objectSubId=0;
1304+
13041305
referenced.classId=NamespaceRelationId;
13051306
referenced.objectId=relnamespace;
13061307
referenced.objectSubId=0;
13071308
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
13081309

13091310
recordDependencyOnOwner(RelationRelationId,relid,ownerid);
13101311

1312+
recordDependencyOnNewAcl(RelationRelationId,relid,0,ownerid,relacl);
1313+
13111314
recordDependencyOnCurrentExtension(&myself, false);
13121315

13131316
if (reloftypeid)
@@ -1317,18 +1320,6 @@ heap_create_with_catalog(const char *relname,
13171320
referenced.objectSubId=0;
13181321
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
13191322
}
1320-
1321-
if (relacl!=NULL)
1322-
{
1323-
intnnewmembers;
1324-
Oid*newmembers;
1325-
1326-
nnewmembers=aclmembers(relacl,&newmembers);
1327-
updateAclDependencies(RelationRelationId,relid,0,
1328-
ownerid,
1329-
0,NULL,
1330-
nnewmembers,newmembers);
1331-
}
13321323
}
13331324

13341325
/* Post creation hook for new relation */

‎src/backend/catalog/pg_namespace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
100100
/* dependency on owner */
101101
recordDependencyOnOwner(NamespaceRelationId,nspoid,ownerId);
102102

103+
/* dependences on roles mentioned in default ACL */
104+
recordDependencyOnNewAcl(NamespaceRelationId,nspoid,0,ownerId,nspacl);
105+
103106
/* dependency on extension ... but not for magic temp schemas */
104107
if (!isTemp)
105108
recordDependencyOnCurrentExtension(&myself, false);

‎src/backend/catalog/pg_proc.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,9 @@ ProcedureCreate(const char *procedureName,
665665
recordDependencyOnOwner(ProcedureRelationId,retval,proowner);
666666

667667
/* dependency on any roles mentioned in ACL */
668-
if (!is_update&&proacl!=NULL)
669-
{
670-
intnnewmembers;
671-
Oid*newmembers;
672-
673-
nnewmembers=aclmembers(proacl,&newmembers);
674-
updateAclDependencies(ProcedureRelationId,retval,0,
675-
proowner,
676-
0,NULL,
677-
nnewmembers,newmembers);
678-
}
668+
if (!is_update)
669+
recordDependencyOnNewAcl(ProcedureRelationId,retval,0,
670+
proowner,proacl);
679671

680672
/* dependency on extension */
681673
recordDependencyOnCurrentExtension(&myself,is_update);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp