From e320679c4cc5cd9fc0f35f59fd22284fc2ecfb89 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Fri, 7 Jan 2022 14:07:09 +0100 Subject: [PATCH] Remove grants on data node bootstrap Starting with PG15, default permissions on the public schema is restricted for any non-superuser non-owner. This causes test failures since tables can no longer be created without explicitly adding permissions, so we remove grant when bootstrapping the data nodes and instead grant permissions to the users in the regression tests. This keeps the default permissions on data nodes, but allow regression tests to run. Fixes #3957 Reference: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=b073c3cc --- test/expected/trusted_extension.out | 11 ++++++-- test/runner.sh | 23 +++++++++++++-- test/sql/trusted_extension.sql | 12 +++++--- test/test-defs.cmake | 7 +++-- tsl/src/data_node.c | 12 -------- tsl/test/expected/remote_connection_cache.out | 28 ++++++++++++------- tsl/test/sql/remote_connection_cache.sql | 18 ++++++------ 7 files changed, 67 insertions(+), 44 deletions(-) diff --git a/test/expected/trusted_extension.out b/test/expected/trusted_extension.out index eefb810b8..7f0583f02 100644 --- a/test/expected/trusted_extension.out +++ b/test/expected/trusted_extension.out @@ -3,9 +3,14 @@ -- LICENSE-APACHE for a copy of the license. \c :TEST_DBNAME :ROLE_SUPERUSER CREATE DATABASE trusted_test; -GRANT CREATE ON DATABASE trusted_test TO test_role_1; -\c trusted_test test_role_1 --- user shouldnt have superuser privilege +GRANT CREATE ON DATABASE trusted_test TO :ROLE_1; +\c trusted_test :ROLE_READ_ONLY +\set ON_ERROR_STOP 0 +CREATE EXTENSION timescaledb; +ERROR: permission denied to create extension "timescaledb" +\set ON_ERROR_STOP 1 +\c trusted_test :ROLE_1 +-- user shouldn't have superuser privilege SELECT rolsuper FROM pg_roles WHERE rolname=user; rolsuper ---------- diff --git a/test/runner.sh b/test/runner.sh index 735998658..e1a8a5b72 100755 --- a/test/runner.sh +++ b/test/runner.sh @@ -41,12 +41,23 @@ TEST_ROLE_2=${TEST_ROLE_2:-test_role_2} TEST_ROLE_2_PASS=${TEST_ROLE_2_PASS:-pass} TEST_ROLE_3=${TEST_ROLE_3:-test_role_3} TEST_ROLE_3_PASS=${TEST_ROLE_3_PASS:-pass} +TEST_ROLE_READ_ONLY=${TEST_ROLE_READ_ONLY:-test_role_read_only} shift # Drop test database and make it less verbose in case of dropping a -# distributed database +# distributed database. Also revoke privileges granted when setting up +# the template1 database. This has to be revoked since the user is +# dropped from a different database. function cleanup { + ${PSQL} "$@" -U ${USER} -d template1 -v ECHO=none >/dev/null 2>&1 </dev/null 2>&1 SET client_min_messages=ERROR; DROP DATABASE "${TEST_DBNAME}"; @@ -59,9 +70,14 @@ trap cleanup EXIT # we use mkdir here because it is an atomic operation unlike existance of a lockfile # where creating and checking are 2 separate operations if mkdir ${TEST_OUTPUT_DIR}/.pg_init 2>/dev/null; then - cat </dev/null 2>&1 + ${PSQL} "$@" -U ${USER} -d template1 -v ECHO=none >/dev/null 2>&1 < 'localhost', - database => 'db_remote_connection_cache_1', - port => current_setting('port')::int)$$; - EXECUTE $$SELECT add_data_node('loopback_2', host => 'localhost', - database => 'db_remote_connection_cache_2', - port => current_setting('port')::int)$$; - END; -$d$; +SET client_min_messages TO WARNING; +SELECT node_name, database, node_created, extension_created +FROM add_data_node('loopback_1', host => 'localhost', database => :'DN_DBNAME_1', + port => current_setting('port')::int); + node_name | database | node_created | extension_created +------------+------------------------------+--------------+------------------- + loopback_1 | db_remote_connection_cache_1 | t | t +(1 row) + +SELECT node_name, database, node_created, extension_created +FROM add_data_node('loopback_2', host => 'localhost', database => :'DN_DBNAME_2', + port => current_setting('port')::int); + node_name | database | node_created | extension_created +------------+------------------------------+--------------+------------------- + loopback_2 | db_remote_connection_cache_2 | t | t +(1 row) + +SET client_min_messages TO INFO; SELECT _timescaledb_internal.test_remote_connection_cache(); test_remote_connection_cache ------------------------------ diff --git a/tsl/test/sql/remote_connection_cache.sql b/tsl/test/sql/remote_connection_cache.sql index 91fac054b..4e1daab16 100644 --- a/tsl/test/sql/remote_connection_cache.sql +++ b/tsl/test/sql/remote_connection_cache.sql @@ -17,16 +17,14 @@ RETURNS BOOL AS :TSL_MODULE_PATHNAME, 'ts_test_alter_data_node' LANGUAGE C STRICT; -DO $d$ - BEGIN - EXECUTE $$SELECT add_data_node('loopback_1', host => 'localhost', - database => 'db_remote_connection_cache_1', - port => current_setting('port')::int)$$; - EXECUTE $$SELECT add_data_node('loopback_2', host => 'localhost', - database => 'db_remote_connection_cache_2', - port => current_setting('port')::int)$$; - END; -$d$; +SET client_min_messages TO WARNING; +SELECT node_name, database, node_created, extension_created +FROM add_data_node('loopback_1', host => 'localhost', database => :'DN_DBNAME_1', + port => current_setting('port')::int); +SELECT node_name, database, node_created, extension_created +FROM add_data_node('loopback_2', host => 'localhost', database => :'DN_DBNAME_2', + port => current_setting('port')::int); +SET client_min_messages TO INFO; SELECT _timescaledb_internal.test_remote_connection_cache();