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

Commitf15147d

Browse files
committed
Don't try to dump RLS policies or security labels for extension objects.
checkExtensionMembership() set the DUMP_COMPONENT_SECLABEL andDUMP_COMPONENT_POLICY flags for extension member objects, even thoughwe lack any infrastructure for tracking extensions' initial settingsof these properties. This is not OK. The result was that a dumpwould always include commands to set these properties for extensionobjects that have them, with at least three negative consequences:1. The restoring user might not have privilege to set these propertieson these objects.2. The properties might be incorrect/irrelevant for the version of theextension that's installed in the destination database.3. The dump itself might fail, in the case of RLS properties attachedto extension tables that the dumping user lacks privilege to LOCK.(That's because we must get at least AccessShareLock to ensure thatwe don't fail while trying to decompile the RLS expressions.)When and if somebody cares to invent initial-state infrastructure forextensions' RLS policies and security labels, we could think aboutfinding another way around problem#3. But in the absence of suchinfrastructure, this whole thing is just wrong and we shouldn't do it.(Note: this applies only to ordinary dumps; binary-upgrade dumpsstill dump and restore extension member objects separately, withall 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 parent403f4f4 commitf15147d

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

‎src/bin/pg_dump/pg_dump.c

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

15781578
/*
1579-
* In 9.6 and above, mark the member object to have any non-initial ACL,
1580-
* policies, and security labels dumped.
1581-
*
1582-
* Note that any initial ACLs (see pg_init_privs) will be removed when we
1583-
* extract the information about the object. We don't provide support for
1584-
* initial policies and security labels and it seems unlikely for those to
1585-
* ever exist, but we may have to revisit this later.
1579+
* In 9.6 and above, mark the member object to have any non-initial ACLs
1580+
* dumped. (Any initial ACLs will be removed later, using data from
1581+
* pg_init_privs, so that we'll dump only the delta from the extension's
1582+
* initial setup.)
15861583
*
15871584
* Prior to 9.6, we do not include any extension member components.
15881585
*
15891586
* In binary upgrades, we still dump all components of the members
15901587
* individually, since the idea is to exactly reproduce the database
15911588
* contents rather than replace the extension contents with something
15921589
* different.
1590+
*
1591+
* Note: it might be interesting someday to implement storage and delta
1592+
* dumping of extension members' RLS policies and/or security labels.
1593+
* However there is a pitfall for RLS policies: trying to dump them
1594+
* requires getting a lock on their tables, and the calling user might not
1595+
* have privileges for that. We need no lock to examine a table's ACLs,
1596+
* so the current feature doesn't have a problem of that sort.
15931597
*/
15941598
if (fout->dopt->binary_upgrade)
15951599
dobj->dump = ext->dobj.dump;
@@ -1598,9 +1602,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout)
15981602
if (fout->remoteVersion < 90600)
15991603
dobj->dump = DUMP_COMPONENT_NONE;
16001604
else
1601-
dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1602-
DUMP_COMPONENT_SECLABEL |
1603-
DUMP_COMPONENT_POLICY);
1605+
dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL);
16041606
}
16051607

16061608
return true;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@
170170
'postgres',
171171
],
172172
},
173+
174+
# regress_dump_login_role shouldn't need SELECT rights on internal
175+
# (undumped) extension tables
176+
privileged_internals=> {
177+
dump_cmd=> [
178+
'pg_dump','--no-sync',"--file=$tempdir/privileged_internals.sql",
179+
# these two tables are irrelevant to the test case
180+
'--exclude-table=regress_pg_dump_schema.external_tab',
181+
'--exclude-table=regress_pg_dump_schema.extdependtab',
182+
'--username=regress_dump_login_role','postgres',
183+
],
184+
},
185+
173186
schema_only=> {
174187
dump_cmd=> [
175188
'pg_dump','--no-sync',"--file=$tempdir/schema_only.sql",
@@ -279,6 +292,7 @@
279292
exclude_table=> 1,
280293
no_privs=> 1,
281294
no_owner=> 1,
295+
privileged_internals=> 1,
282296
with_extension=> 1,
283297
without_extension=> 1);
284298

@@ -316,6 +330,16 @@
316330
like => { pg_dumpall_globals => 1, },
317331
},
318332
333+
'CREATE ROLE regress_dump_login_role' => {
334+
create_order => 1,
335+
create_sql => 'CREATE ROLE regress_dump_login_role LOGIN;',
336+
regexp => qr/^
337+
\QCREATE ROLE regress_dump_login_role;\E
338+
\n\QALTER ROLE regress_dump_login_role WITH\E.*\Q LOGIN\E.*;
339+
\n/xm,
340+
like => { pg_dumpall_globals => 1, },
341+
},
342+
319343
'GRANT ALTER SYSTEM ON PARAMETER full_page_writes TO regress_dump_test_role'
320344
=> {
321345
create_order => 2,
@@ -699,6 +723,7 @@
699723
data_only => 1,
700724
extension_schema => 1,
701725
pg_dumpall_globals => 1,
726+
privileged_internals => 1,
702727
section_data => 1,
703728
section_pre_data => 1,
704729
# Excludes this schema as extension is not listed.
@@ -715,6 +740,7 @@
715740
data_only => 1,
716741
extension_schema => 1,
717742
pg_dumpall_globals => 1,
743+
privileged_internals => 1,
718744
section_data => 1,
719745
section_pre_data => 1,
720746
# Excludes this schema as extension is not listed.
@@ -738,6 +764,7 @@
738764
# Excludes the extension and keeps the schema's data.
739765
without_extension_internal_schema => 1,
740766
},
767+
unlike => { privileged_internals => 1 },
741768
},);
742769
743770
#########################################

‎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
CREATESEQUENCEregress_seq_dumpable;
1414
SELECTpg_catalog.pg_extension_config_dump('regress_seq_dumpable','');
15+
GRANTSELECTON SEQUENCE regress_seq_dumpable TO public;
1516

1617
CREATETABLEregress_table_dumpable (
1718
col1intcheck (col1>0)
1819
);
1920
SELECTpg_catalog.pg_extension_config_dump('regress_table_dumpable','');
21+
GRANTSELECTON regress_table_dumpable TO public;
2022

2123
CREATESCHEMAregress_pg_dump_schema;
2224

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp