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

Commit1b55acb

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 parent84b4a0c commit1b55acb

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
@@ -5445,7 +5445,10 @@ get_default_acl_internal(Oid roleId, Oid nsp_oid, char objtype)
54455445
/*
54465446
* Get default permissions for newly created object within given schema
54475447
*
5448-
* Returns NULL if built-in system defaults should be used
5448+
* Returns NULL if built-in system defaults should be used.
5449+
*
5450+
* If the result is not NULL, caller must call recordDependencyOnNewAcl
5451+
* once the OID of the new object is known.
54495452
*/
54505453
Acl*
54515454
get_user_default_acl(ObjectTypeobjtype,OidownerId,Oidnsp_oid)
@@ -5520,6 +5523,30 @@ get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
55205523
returnresult;
55215524
}
55225525

5526+
/*
5527+
* Record dependencies on roles mentioned in a new object's ACL.
5528+
*/
5529+
void
5530+
recordDependencyOnNewAcl(OidclassId,OidobjectId,int32objsubId,
5531+
OidownerId,Acl*acl)
5532+
{
5533+
intnmembers;
5534+
Oid*members;
5535+
5536+
/* Nothing to do if ACL is defaulted */
5537+
if (acl==NULL)
5538+
return;
5539+
5540+
/* Extract roles mentioned in ACL */
5541+
nmembers=aclmembers(acl,&members);
5542+
5543+
/* Update the shared dependency ACL info */
5544+
updateAclDependencies(classId,objectId,objsubId,
5545+
ownerId,
5546+
0,NULL,
5547+
nmembers,members);
5548+
}
5549+
55235550
/*
55245551
* Record initial privileges for the top-level object passed in.
55255552
*

‎src/backend/catalog/heap.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,13 +1320,16 @@ heap_create_with_catalog(const char *relname,
13201320
myself.classId=RelationRelationId;
13211321
myself.objectId=relid;
13221322
myself.objectSubId=0;
1323+
13231324
referenced.classId=NamespaceRelationId;
13241325
referenced.objectId=relnamespace;
13251326
referenced.objectSubId=0;
13261327
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
13271328

13281329
recordDependencyOnOwner(RelationRelationId,relid,ownerid);
13291330

1331+
recordDependencyOnNewAcl(RelationRelationId,relid,0,ownerid,relacl);
1332+
13301333
recordDependencyOnCurrentExtension(&myself, false);
13311334

13321335
if (reloftypeid)
@@ -1336,18 +1339,6 @@ heap_create_with_catalog(const char *relname,
13361339
referenced.objectSubId=0;
13371340
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
13381341
}
1339-
1340-
if (relacl!=NULL)
1341-
{
1342-
intnnewmembers;
1343-
Oid*newmembers;
1344-
1345-
nnewmembers=aclmembers(relacl,&newmembers);
1346-
updateAclDependencies(RelationRelationId,relid,0,
1347-
ownerid,
1348-
0,NULL,
1349-
nnewmembers,newmembers);
1350-
}
13511342
}
13521343

13531344
/* 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
@@ -654,17 +654,9 @@ ProcedureCreate(const char *procedureName,
654654
recordDependencyOnOwner(ProcedureRelationId,retval,proowner);
655655

656656
/* dependency on any roles mentioned in ACL */
657-
if (!is_update&&proacl!=NULL)
658-
{
659-
intnnewmembers;
660-
Oid*newmembers;
661-
662-
nnewmembers=aclmembers(proacl,&newmembers);
663-
updateAclDependencies(ProcedureRelationId,retval,0,
664-
proowner,
665-
0,NULL,
666-
nnewmembers,newmembers);
667-
}
657+
if (!is_update)
658+
recordDependencyOnNewAcl(ProcedureRelationId,retval,0,
659+
proowner,proacl);
668660

669661
/* dependency on extension */
670662
recordDependencyOnCurrentExtension(&myself,is_update);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp