Check table ownership in upgrade_to_reference_table

pull/2483/head
Marco Slot 2018-11-16 23:27:34 +01:00
parent fc9f981525
commit aab9f623eb
3 changed files with 22 additions and 1 deletions

View File

@ -60,8 +60,9 @@ upgrade_to_reference_table(PG_FUNCTION_ARGS)
uint64 shardId = INVALID_SHARD_ID;
DistTableCacheEntry *tableEntry = NULL;
EnsureCoordinator();
CheckCitusVersion(ERROR);
EnsureCoordinator();
EnsureTableOwner(relationId);
if (!IsDistributedTable(relationId))
{

View File

@ -21,6 +21,14 @@ SELECT create_distributed_table('test', 'id');
(1 row)
SET citus.shard_count TO 1;
CREATE TABLE singleshard (id integer, val integer);
SELECT create_distributed_table('singleshard', 'id');
create_distributed_table
--------------------------
(1 row)
-- turn off propagation to avoid Enterprise processing the following section
SET citus.enable_ddl_propagation TO off;
CREATE USER full_access;
@ -212,6 +220,9 @@ ERROR: permission denied for table test
ABORT;
SELECT * FROM citus_stat_statements_reset();
ERROR: permission denied for function citus_stat_statements_reset
-- should not be allowed to upgrade to reference table
SELECT upgrade_to_reference_table('singleshard');
ERROR: must be owner of table singleshard
-- table owner should be the same on the shards, even when distributing the table as superuser
SET ROLE full_access;
CREATE TABLE my_table (id integer, val integer);
@ -231,6 +242,7 @@ SELECT result FROM run_command_on_workers($$SELECT tableowner FROM pg_tables WHE
DROP TABLE my_table;
DROP TABLE test;
DROP TABLE singleshard;
DROP USER full_access;
DROP USER read_access;
DROP USER no_access;

View File

@ -16,6 +16,10 @@ SET citus.shard_replication_factor TO 1;
CREATE TABLE test (id integer, val integer);
SELECT create_distributed_table('test', 'id');
SET citus.shard_count TO 1;
CREATE TABLE singleshard (id integer, val integer);
SELECT create_distributed_table('singleshard', 'id');
-- turn off propagation to avoid Enterprise processing the following section
SET citus.enable_ddl_propagation TO off;
@ -138,6 +142,9 @@ ABORT;
SELECT * FROM citus_stat_statements_reset();
-- should not be allowed to upgrade to reference table
SELECT upgrade_to_reference_table('singleshard');
-- table owner should be the same on the shards, even when distributing the table as superuser
SET ROLE full_access;
CREATE TABLE my_table (id integer, val integer);
@ -147,6 +154,7 @@ SELECT result FROM run_command_on_workers($$SELECT tableowner FROM pg_tables WHE
DROP TABLE my_table;
DROP TABLE test;
DROP TABLE singleshard;
DROP USER full_access;
DROP USER read_access;
DROP USER no_access;