Skip to content

Commit a70f2a5

Browse files
committed
Don't try to dump RLS policies or security labels for extension objects.
checkExtensionMembership() set the DUMP_COMPONENT_SECLABEL and DUMP_COMPONENT_POLICY flags for extension member objects, even though we lack any infrastructure for tracking extensions' initial settings of these properties. This is not OK. The result was that a dump would always include commands to set these properties for extension objects that have them, with at least three negative consequences: 1. The restoring user might not have privilege to set these properties on these objects. 2. The properties might be incorrect/irrelevant for the version of the extension that's installed in the destination database. 3. The dump itself might fail, in the case of RLS properties attached to extension tables that the dumping user lacks privilege to LOCK. (That's because we must get at least AccessShareLock to ensure that we don't fail while trying to decompile the RLS expressions.) When and if somebody cares to invent initial-state infrastructure for extensions' RLS policies and security labels, we could think about finding another way around problem #3. But in the absence of such infrastructure, this whole thing is just wrong and we shouldn't do it. (Note: this applies only to ordinary dumps; binary-upgrade dumps still dump and restore extension member objects separately, with all properties.) Tom Lane and Jacob Champion. Back-patch to all supported branches. Discussion: https://postgr.es/m/[email protected]
1 parent 24943fb commit a70f2a5

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

src/bin/pg_dump/pg_dump.c

+12-10
Original file line numberDiff line numberDiff line change
@@ -1680,20 +1680,24 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout)
16801680
addObjectDependency(dobj, ext->dobj.dumpId);
16811681

16821682
/*
1683-
* In 9.6 and above, mark the member object to have any non-initial ACL,
1684-
* policies, and security labels dumped.
1685-
*
1686-
* Note that any initial ACLs (see pg_init_privs) will be removed when we
1687-
* extract the information about the object. We don't provide support for
1688-
* initial policies and security labels and it seems unlikely for those to
1689-
* ever exist, but we may have to revisit this later.
1683+
* In 9.6 and above, mark the member object to have any non-initial ACLs
1684+
* dumped. (Any initial ACLs will be removed later, using data from
1685+
* pg_init_privs, so that we'll dump only the delta from the extension's
1686+
* initial setup.)
16901687
*
16911688
* Prior to 9.6, we do not include any extension member components.
16921689
*
16931690
* In binary upgrades, we still dump all components of the members
16941691
* individually, since the idea is to exactly reproduce the database
16951692
* contents rather than replace the extension contents with something
16961693
* different.
1694+
*
1695+
* Note: it might be interesting someday to implement storage and delta
1696+
* dumping of extension members' RLS policies and/or security labels.
1697+
* However there is a pitfall for RLS policies: trying to dump them
1698+
* requires getting a lock on their tables, and the calling user might not
1699+
* have privileges for that. We need no lock to examine a table's ACLs,
1700+
* so the current feature doesn't have a problem of that sort.
16971701
*/
16981702
if (fout->dopt->binary_upgrade)
16991703
dobj->dump = ext->dobj.dump;
@@ -1702,9 +1706,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout)
17021706
if (fout->remoteVersion < 90600)
17031707
dobj->dump = DUMP_COMPONENT_NONE;
17041708
else
1705-
dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1706-
DUMP_COMPONENT_SECLABEL |
1707-
DUMP_COMPONENT_POLICY);
1709+
dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL);
17081710
}
17091711

17101712
return true;

src/test/modules/test_pg_dump/t/001_base.pl

+27
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@
175175
'postgres',
176176
],
177177
},
178+
179+
# regress_dump_login_role shouldn't need SELECT rights on internal
180+
# (undumped) extension tables
181+
privileged_internals => {
182+
dump_cmd => [
183+
'pg_dump', '--no-sync', "--file=$tempdir/privileged_internals.sql",
184+
# these two tables are irrelevant to the test case
185+
'--exclude-table=regress_pg_dump_schema.external_tab',
186+
'--exclude-table=regress_pg_dump_schema.extdependtab',
187+
'--username=regress_dump_login_role', 'postgres',
188+
],
189+
},
190+
178191
schema_only => {
179192
dump_cmd => [
180193
'pg_dump', '--no-sync', "--file=$tempdir/schema_only.sql",
@@ -284,6 +297,7 @@
284297
exclude_table => 1,
285298
no_privs => 1,
286299
no_owner => 1,
300+
privileged_internals => 1,
287301
with_extension => 1,
288302
without_extension => 1);
289303

@@ -321,6 +335,16 @@
321335
like => { pg_dumpall_globals => 1, },
322336
},
323337
338+
'CREATE ROLE regress_dump_login_role' => {
339+
create_order => 1,
340+
create_sql => 'CREATE ROLE regress_dump_login_role LOGIN;',
341+
regexp => qr/^
342+
\QCREATE ROLE regress_dump_login_role;\E
343+
\n\QALTER ROLE regress_dump_login_role WITH \E.*\Q LOGIN \E.*;
344+
\n/xm,
345+
like => { pg_dumpall_globals => 1, },
346+
},
347+
324348
'GRANT ALTER SYSTEM ON PARAMETER full_page_writes TO regress_dump_test_role'
325349
=> {
326350
create_order => 2,
@@ -704,6 +728,7 @@
704728
data_only => 1,
705729
extension_schema => 1,
706730
pg_dumpall_globals => 1,
731+
privileged_internals => 1,
707732
section_data => 1,
708733
section_pre_data => 1,
709734
# Excludes this schema as extension is not listed.
@@ -720,6 +745,7 @@
720745
data_only => 1,
721746
extension_schema => 1,
722747
pg_dumpall_globals => 1,
748+
privileged_internals => 1,
723749
section_data => 1,
724750
section_pre_data => 1,
725751
# Excludes this schema as extension is not listed.
@@ -743,6 +769,7 @@
743769
# Excludes the extension and keeps the schema's data.
744770
without_extension_internal_schema => 1,
745771
},
772+
unlike => { privileged_internals => 1 },
746773
},);
747774
748775
#########################################

src/test/modules/test_pg_dump/test_pg_dump--1.0.sql

+2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ CREATE SEQUENCE regress_pg_dump_seq;
1212

1313
CREATE SEQUENCE regress_seq_dumpable;
1414
SELECT pg_catalog.pg_extension_config_dump('regress_seq_dumpable', '');
15+
GRANT SELECT ON SEQUENCE regress_seq_dumpable TO public;
1516

1617
CREATE TABLE regress_table_dumpable (
1718
col1 int check (col1 > 0)
1819
);
1920
SELECT pg_catalog.pg_extension_config_dump('regress_table_dumpable', '');
21+
GRANT SELECT ON regress_table_dumpable TO public;
2022

2123
CREATE SCHEMA regress_pg_dump_schema;
2224

0 commit comments

Comments
 (0)