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

Commitd431dff

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 parent041ad9a commitd431dff

File tree

7 files changed

+142
-138
lines changed

7 files changed

+142
-138
lines changed

‎src/backend/catalog/aclchk.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5158,7 +5158,10 @@ get_default_acl_internal(Oid roleId, Oid nsp_oid, char objtype)
51585158
/*
51595159
* Get default permissions for newly created object within given schema
51605160
*
5161-
* Returns NULL if built-in system defaults should be used
5161+
* Returns NULL if built-in system defaults should be used.
5162+
*
5163+
* If the result is not NULL, caller must call recordDependencyOnNewAcl
5164+
* once the OID of the new object is known.
51625165
*/
51635166
Acl*
51645167
get_user_default_acl(GrantObjectTypeobjtype,OidownerId,Oidnsp_oid)
@@ -5229,6 +5232,30 @@ get_user_default_acl(GrantObjectType objtype, Oid ownerId, Oid nsp_oid)
52295232
returnresult;
52305233
}
52315234

5235+
/*
5236+
* Record dependencies on roles mentioned in a new object's ACL.
5237+
*/
5238+
void
5239+
recordDependencyOnNewAcl(OidclassId,OidobjectId,int32objsubId,
5240+
OidownerId,Acl*acl)
5241+
{
5242+
intnmembers;
5243+
Oid*members;
5244+
5245+
/* Nothing to do if ACL is defaulted */
5246+
if (acl==NULL)
5247+
return;
5248+
5249+
/* Extract roles mentioned in ACL */
5250+
nmembers=aclmembers(acl,&members);
5251+
5252+
/* Update the shared dependency ACL info */
5253+
updateAclDependencies(classId,objectId,objsubId,
5254+
ownerId,
5255+
0,NULL,
5256+
nmembers,members);
5257+
}
5258+
52325259
/*
52335260
* Record initial privileges for the top-level object passed in.
52345261
*

‎src/backend/catalog/heap.c

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

13101311
recordDependencyOnOwner(RelationRelationId,relid,ownerid);
13111312

1313+
recordDependencyOnNewAcl(RelationRelationId,relid,0,ownerid,relacl);
1314+
13121315
if (relpersistence!=RELPERSISTENCE_TEMP)
13131316
recordDependencyOnCurrentExtension(&myself, false);
13141317

@@ -1319,18 +1322,6 @@ heap_create_with_catalog(const char *relname,
13191322
referenced.objectSubId=0;
13201323
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
13211324
}
1322-
1323-
if (relacl!=NULL)
1324-
{
1325-
intnnewmembers;
1326-
Oid*newmembers;
1327-
1328-
nnewmembers=aclmembers(relacl,&newmembers);
1329-
updateAclDependencies(RelationRelationId,relid,0,
1330-
ownerid,
1331-
0,NULL,
1332-
nnewmembers,newmembers);
1333-
}
13341325
}
13351326

13361327
/* Post creation hook for new relation */

‎src/backend/catalog/pg_proc.c

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

673673
/* dependency on any roles mentioned in ACL */
674-
if (!is_update&&proacl!=NULL)
675-
{
676-
intnnewmembers;
677-
Oid*newmembers;
678-
679-
nnewmembers=aclmembers(proacl,&newmembers);
680-
updateAclDependencies(ProcedureRelationId,retval,0,
681-
proowner,
682-
0,NULL,
683-
nnewmembers,newmembers);
684-
}
674+
if (!is_update)
675+
recordDependencyOnNewAcl(ProcedureRelationId,retval,0,
676+
proowner,proacl);
685677

686678
/* dependency on extension */
687679
recordDependencyOnCurrentExtension(&myself,is_update);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp