Skip to content

Commit 28a3f4d

Browse files
reshkerkhapov
authored andcommitted
Never trust trusted and superuser fields from extension controlfile (#86)
For all in-core (contrib) extension, we already switch trusted options to false. For third-party extensions, simply never trust nothing. This makes API management of extensions consistent.
1 parent c82bd71 commit 28a3f4d

6 files changed

Lines changed: 74 additions & 4 deletions

File tree

src/backend/commands/extension.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,11 +1032,17 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
10321032
* here so that the control flags are correctly associated with the right
10331033
* script(s) if they happen to be set in secondary control files.
10341034
*/
1035-
if (control->superuser && !superuser())
1035+
/* MDB does not trust control->superuser */
1036+
if (!superuser())
10361037
{
1038+
1039+
/* MDB addon */
1040+
#if 0
10371041
if (extension_is_trusted(control))
10381042
switch_to_superuser = true;
1039-
else if (from_version == NULL)
1043+
else
1044+
#endif
1045+
if (from_version == NULL)
10401046
ereport(ERROR,
10411047
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
10421048
errmsg("permission denied to create extension \"%s\"",
@@ -1056,6 +1062,11 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
10561062

10571063
filename = get_extension_script_filename(control, from_version, version);
10581064

1065+
/* MDB addons. Never trust extension's controlfile trusted and/or superuser field.
1066+
* XXX: rethink this if we start support SQL-level ext API */
1067+
1068+
switch_to_superuser = false;
1069+
10591070
/*
10601071
* If installing a trusted extension on behalf of a non-superuser, become
10611072
* the bootstrap superuser. (This switch will be cleaned up automatically

src/test/modules/test_extensions/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ MODULE = test_extensions
44
PGFILEDESC = "test_extensions - regression testing for EXTENSION support"
55

66
EXTENSION = test_ext1 test_ext2 test_ext3 test_ext4 test_ext5 test_ext6 \
7-
test_ext7 test_ext8 test_ext_cine test_ext_cor \
7+
test_ext7 test_ext8 test_ext_mdb test_ext_cine test_ext_cor \
88
test_ext_cyclic1 test_ext_cyclic2 \
99
test_ext_extschema \
1010
test_ext_evttrig
1111
DATA = test_ext1--1.0.sql test_ext2--1.0.sql test_ext3--1.0.sql \
1212
test_ext4--1.0.sql test_ext5--1.0.sql test_ext6--1.0.sql \
1313
test_ext7--1.0.sql test_ext7--1.0--2.0.sql test_ext8--1.0.sql \
14+
test_ext_mdb--1.0.sql \
1415
test_ext_cine--1.0.sql test_ext_cine--1.0--1.1.sql \
1516
test_ext_cor--1.0.sql \
1617
test_ext_cyclic1--1.0.sql test_ext_cyclic2--1.0.sql \
1718
test_ext_extschema--1.0.sql \
1819
test_ext_evttrig--1.0.sql test_ext_evttrig--1.0--2.0.sql
1920

20-
REGRESS = test_extensions test_extdepend
21+
REGRESS = test_extensions test_extdepend test_mdb
2122

2223
# force C locale for output stability
2324
NO_LOCALE = 1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE ROLE regress_mdb_admin_user1;
2+
CREATE ROLE mdb_superuser;
3+
CREATE ROLE mdb_admin;
4+
GRANT mdb_admin TO regress_mdb_admin_user1;
5+
GRANT mdb_superuser TO regress_mdb_admin_user1;
6+
GRANT CREATE ON DATABASE contrib_regression TO regress_mdb_admin_user1;
7+
SET ROLE regress_mdb_admin_user1;
8+
CREATE EXTENSION test_ext_mdb;
9+
ERROR: permission denied to create extension "test_ext_mdb"
10+
HINT: Must have CREATE privilege on current database to create this extension.
11+
RESET ROLE;
12+
DROP ROLE mdb_superuser;
13+
DROP ROLE mdb_admin;
14+
DROP OWNED BY regress_mdb_admin_user1;
15+
DROP ROLE regress_mdb_admin_user1;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE ROLE regress_mdb_admin_user1;
2+
3+
CREATE ROLE mdb_superuser;
4+
CREATE ROLE mdb_admin;
5+
6+
GRANT mdb_admin TO regress_mdb_admin_user1;
7+
GRANT mdb_superuser TO regress_mdb_admin_user1;
8+
9+
GRANT CREATE ON DATABASE contrib_regression TO regress_mdb_admin_user1;
10+
11+
SET ROLE regress_mdb_admin_user1;
12+
13+
CREATE EXTENSION test_ext_mdb;
14+
15+
RESET ROLE;
16+
17+
DROP ROLE mdb_superuser;
18+
DROP ROLE mdb_admin;
19+
20+
DROP OWNED BY regress_mdb_admin_user1;
21+
22+
DROP ROLE regress_mdb_admin_user1;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* src/test/modules/test_extensions/test_ext9--1.0.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "CREATE EXTENSION test_ext9" to load this file. \quit
5+
6+
-- create some random data type
7+
create domain posint as int check (value > 0);
8+
9+
-- use it in regular and temporary tables and functions
10+
11+
create table ext9_table1 (f1 posint);
12+
13+
create function ext9_even (posint) returns bool as
14+
'select ($1 % 2) = 0' language sql;
15+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
comment = 'Test extension mdb'
2+
default_version = '1.0'
3+
schema = 'public'
4+
relocatable = false
5+
trusted = true
6+
superuser = false

0 commit comments

Comments
 (0)