Skip to content

Commit 891afa8

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/00d46a48-3324-d9a0-49bf-e7f0f11d1038@timescale.com
1 parent b64926f commit 891afa8

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,20 +1432,24 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout)
14321432
addObjectDependency(dobj, ext->dobj.dumpId);
14331433

14341434
/*
1435-
* In 9.6 and above, mark the member object to have any non-initial ACL,
1436-
* policies, and security labels dumped.
1437-
*
1438-
* Note that any initial ACLs (see pg_init_privs) will be removed when we
1439-
* extract the information about the object. We don't provide support for
1440-
* initial policies and security labels and it seems unlikely for those to
1441-
* ever exist, but we may have to revisit this later.
1435+
* In 9.6 and above, mark the member object to have any non-initial ACLs
1436+
* dumped. (Any initial ACLs will be removed later, using data from
1437+
* pg_init_privs, so that we'll dump only the delta from the extension's
1438+
* initial setup.)
14421439
*
14431440
* Prior to 9.6, we do not include any extension member components.
14441441
*
14451442
* In binary upgrades, we still dump all components of the members
14461443
* individually, since the idea is to exactly reproduce the database
14471444
* contents rather than replace the extension contents with something
14481445
* different.
1446+
*
1447+
* Note: it might be interesting someday to implement storage and delta
1448+
* dumping of extension members' RLS policies and/or security labels.
1449+
* However there is a pitfall for RLS policies: trying to dump them
1450+
* requires getting a lock on their tables, and the calling user might not
1451+
* have privileges for that. We need no lock to examine a table's ACLs,
1452+
* so the current feature doesn't have a problem of that sort.
14491453
*/
14501454
if (fout->dopt->binary_upgrade)
14511455
dobj->dump = ext->dobj.dump;
@@ -1454,9 +1458,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout)
14541458
if (fout->remoteVersion < 90600)
14551459
dobj->dump = DUMP_COMPONENT_NONE;
14561460
else
1457-
dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1458-
DUMP_COMPONENT_SECLABEL |
1459-
DUMP_COMPONENT_POLICY);
1461+
dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL);
14601462
}
14611463

14621464
return true;

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@
169169
'postgres',
170170
],
171171
},
172+
173+
# regress_dump_login_role shouldn't need SELECT rights on internal
174+
# (undumped) extension tables
175+
privileged_internals => {
176+
dump_cmd => [
177+
'pg_dump', '--no-sync', "--file=$tempdir/privileged_internals.sql",
178+
# these two tables are irrelevant to the test case
179+
'--exclude-table=regress_pg_dump_schema.external_tab',
180+
'--exclude-table=regress_pg_dump_schema.extdependtab',
181+
'--username=regress_dump_login_role', 'postgres',
182+
],
183+
},
184+
172185
schema_only => {
173186
dump_cmd => [
174187
'pg_dump', '--no-sync', "--file=$tempdir/schema_only.sql",
@@ -235,7 +248,8 @@
235248
defaults => 1,
236249
exclude_table => 1,
237250
no_privs => 1,
238-
no_owner => 1,);
251+
no_owner => 1,
252+
privileged_internals => 1,);
239253

240254
my %tests = (
241255
'ALTER EXTENSION test_pg_dump' => {
@@ -271,6 +285,16 @@
271285
like => { pg_dumpall_globals => 1, },
272286
},
273287
288+
'CREATE ROLE regress_dump_login_role' => {
289+
create_order => 1,
290+
create_sql => 'CREATE ROLE regress_dump_login_role LOGIN;',
291+
regexp => qr/^
292+
\QCREATE ROLE regress_dump_login_role;\E
293+
\n\QALTER ROLE regress_dump_login_role WITH \E.*\Q LOGIN \E.*;
294+
\n/xm,
295+
like => { pg_dumpall_globals => 1, },
296+
},
297+
274298
'CREATE SEQUENCE regress_pg_dump_table_col1_seq' => {
275299
regexp => qr/^
276300
\QCREATE SEQUENCE public.regress_pg_dump_table_col1_seq\E
@@ -611,6 +635,7 @@
611635
data_only => 1,
612636
extension_schema => 1,
613637
pg_dumpall_globals => 1,
638+
privileged_internals => 1,
614639
section_data => 1,
615640
section_pre_data => 1,
616641
},
@@ -625,6 +650,7 @@
625650
data_only => 1,
626651
extension_schema => 1,
627652
pg_dumpall_globals => 1,
653+
privileged_internals => 1,
628654
section_data => 1,
629655
section_pre_data => 1,
630656
},
@@ -644,6 +670,7 @@
644670
schema_only => 1,
645671
section_pre_data => 1,
646672
},
673+
unlike => { privileged_internals => 1 },
647674
},);
648675
649676
#########################################

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

Lines changed: 2 additions & 0 deletions
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)