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

Commita70f2a5

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 parent24943fb commita70f2a5

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
@@ -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

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

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