postgresql/src/backend
Tom Lane d431dff1af Fix missing role dependencies for some schema and type ACLs.
This patch fixes several related cases in which pg_shdepend entries were
never made, or were lost, for references to roles appearing in the ACLs of
schemas and/or types.  While that did no immediate harm, if a referenced
role were later dropped, the drop would be allowed and would leave a
dangling reference in the object's ACL.  That still wasn't a big problem
for normal database usage, but it would cause obscure failures in
subsequent dump/reload or pg_upgrade attempts, taking the form of
attempts to grant privileges to all-numeric role names.  (I think I've
seen 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 any
existing ACL entries for the domain.  This case is ancient, dating
back as far as we've had pg_shdepend tracking at all.

2. If a default type privilege applies, CREATE TYPE recorded the
ACL 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 the
ACL properly but forgot to install dependency entries for it.
This dates to the addition of default privileges for schemas in v10
(commit ab89e465c).

Another somewhat-related problem is that when creating a relation
rowtype or implicit array type, TypeCreate would apply any available
default type privileges to that type, which we don't really want
since such an object isn't supposed to have privileges of its own.
(You can't, for example, drop such privileges once they've been added
to an array type.)

ab89e465c is also to blame for a race condition in the regression tests:
privileges.sql transiently installed globally-applicable default
privileges on schemas, which sometimes got absorbed into the ACLs of
schemas created by concurrent test scripts.  This should have resulted
in failures when privileges.sql tried to drop the role holding such
privileges; but thanks to the bug fixed here, it instead led to dangling
ACLs in the final state of the regression database.  We'd managed not to
notice that, but it became obvious in the wake of commit da906766c, which
allowed the race condition to occur in pg_upgrade tests.

To fix, add a function recordDependencyOnNewAcl to encapsulate what
callers of get_user_default_acl need to do; while the original call
sites got that right via ad-hoc code, none of the later-added ones
have.  Also change GenerateTypeDependencies to generate these
dependencies, which requires adding the typacl to its parameter list.
(That might be annoying if there are any extensions calling that
function directly; but if there are, they're most likely buggy in the
same way as the core callers were, so they need work anyway.)  While
I was at it, I changed GenerateTypeDependencies to accept most of its
parameters in the form of a Form_pg_type pointer, making its parameter
list a bit less unwieldy and mistake-prone.

The test race condition is fixed just by wrapping the addition and
removal of default privileges into a single transaction, so that that
state is never visible externally.  We might eventually prefer to
separate out tests of default privileges into a script that runs by
itself, but that would be a bigger change and would make the tests
run slower overall.

Back-patch relevant parts to all supported branches.

Discussion: https://postgr.es/m/15719.1541725287@sss.pgh.pa.us
2018-11-09 20:42:03 -05:00
..
access Fix memory leak in repeated SPGIST index scans. 2018-10-31 17:04:43 -04:00
bootstrap Add macros to make AllocSetContextCreate() calls simpler and safer. 2016-08-27 17:50:38 -04:00
catalog Fix missing role dependencies for some schema and type ACLs. 2018-11-09 20:42:03 -05:00
commands Fix missing role dependencies for some schema and type ACLs. 2018-11-09 20:42:03 -05:00
executor Allow btree comparison functions to return INT_MIN. 2018-10-05 16:01:30 -04:00
foreign Remove GetUserMappingId() and GetUserMappingById(). 2016-07-22 11:32:23 -04:00
lib Revert "Permit dump/reload of not-too-large >1GB tuples" 2016-12-06 12:46:03 -03:00
libpq Server-side fix for delayed NOTIFY and SIGTERM processing. 2018-10-19 21:39:22 -04:00
main Install Windows crash dump handler before all else. 2017-11-12 14:31:04 -08:00
nodes Fix parallel query so it doesn't spoil row estimates above Gather. 2017-03-31 21:10:30 -04:00
optimizer Don't allow LIMIT/OFFSET clause within sub-selects to be pushed to workers. 2018-09-14 10:17:31 +05:30
parser Fix lexing of standard multi-character operators in edge cases. 2018-08-23 21:35:49 +01:00
po Translation updates 2018-11-05 14:52:07 +01:00
port Fix and improve pg_atomic_flag fallback implementation. 2018-04-06 20:02:02 -07:00
postmaster Stop bgworkers during fast shutdown with postmaster in startup phase 2018-08-29 17:11:27 -07:00
regex Fix regexport.c to behave sanely with lookaround constraints. 2017-04-13 17:18:35 -04:00
replication Fix copy-paste error in errhint() introduced in 691d79a079. 2018-11-05 12:05:39 -08:00
rewrite Fix set of NLS translation issues 2018-08-21 15:18:00 +09:00
snowball Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage Avoid duplicate XIDs at recovery when building initial snapshot 2018-10-14 22:23:43 +09:00
tcop Server-side fix for delayed NOTIFY and SIGTERM processing. 2018-10-19 21:39:22 -04:00
tsearch Make ts_locale.c's character-type functions cope with UTF-16. 2018-11-03 13:56:10 -04:00
utils Disallow setting client_min_messages higher than ERROR. 2018-11-08 17:33:26 -05:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:45:38 -04:00
nls.mk Translation updates 2018-08-06 19:44:29 +02:00